summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/streams.h
blob: 06f78faec0d794f8174f3f6b885fb2a9e017e370 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************

    streams.h

    Handle general purpose audio streams

    Copyright Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

***************************************************************************/

#ifndef STREAMS_H
#define STREAMS_H

#include "mamecore.h"


/***************************************************************************
    CONSTANTS
***************************************************************************/

#define STREAMS_UPDATE_FREQUENCY	(50)
#define STREAMS_UPDATE_ATTOTIME		ATTOTIME_IN_HZ(STREAMS_UPDATE_FREQUENCY)



/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

typedef struct _sound_stream sound_stream;

typedef void (*stream_update_func)(const device_config *device, void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples);

#define STREAM_UPDATE(name) void name(const device_config *device, void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples)



/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/


/* ----- system-level management ----- */

/* initialize the streams engine */
void streams_init(running_machine *machine);

/* update all the streams periodically */
void streams_update(running_machine *machine);



/* ----- stream configuration and setup ----- */

/* create a new stream */
sound_stream *stream_create(const device_config *device, int inputs, int outputs, int sample_rate, void *param, stream_update_func callback);

/* convert a device/output pair to a stream/output pair */
int stream_device_output_to_stream_output(const device_config *device, int outputnum, sound_stream **streamptr, int *streamoutputptr);

/* convert a device/input pair to a stream/input pair */
int stream_device_input_to_stream_input(const device_config *device, int inputnum, sound_stream **streamptr, int *streaminputptr);

/* configure a stream's input */
void stream_set_input(sound_stream *stream, int index, sound_stream *input_stream, int output_index, float gain);

/* force a stream to update to the current emulated time */
void stream_update(sound_stream *stream);

/* return a pointer to the output buffer and the number of samples since the last global update */
const stream_sample_t *stream_get_output_since_last_update(sound_stream *stream, int outputnum, int *numsamples);



/* ----- stream timing ----- */

/* return the currently set sample rate on a given stream */
int stream_get_sample_rate(sound_stream *stream);

/* set the sample rate on a given stream */
void stream_set_sample_rate(sound_stream *stream, int sample_rate);

/* return the emulation time of the next sample to be generated on the stream */
attotime stream_get_time(sound_stream *stream);

/* return the duration of a single sample for a stream */
attotime stream_get_sample_period(sound_stream *stream);



/* ----- stream information and control ----- */

/* return the total number of outputs for the given device */
int stream_get_device_outputs(const device_config *device);

/* find a stream using a device and index */
sound_stream *stream_find_by_device(const device_config *device, int streamindex);

/* return the number of inputs for a given stream */
int stream_get_inputs(sound_stream *stream);

/* return the number of outputs for a given stream */
int stream_get_outputs(sound_stream *stream);

/* set the input gain on a given stream */
void stream_set_input_gain(sound_stream *stream, int input, float gain);

/* set the output gain on a given stream */
void stream_set_output_gain(sound_stream *stream, int output, float gain);


#endif