summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2008-01-30 17:18:29 +0000
committer Aaron Giles <aaron@aarongiles.com>2008-01-30 17:18:29 +0000
commitd90d36b49ffdc34f32da75c3f3433dd740c423b2 (patch)
tree0989c0f639d91f63cbfe41571697b53d9da922d6
parent18241e1a36733d4b1494742ecc503963f372cab2 (diff)
Added stream_get_sample_rate(), stream_get_time(), and stream_get_sample_period().
These functions are not really tested yet -- make sure they give reasonable results when first used! Updated streams.h header to latest core style.
-rw-r--r--src/emu/streams.c144
-rw-r--r--src/emu/streams.h52
2 files changed, 148 insertions, 48 deletions
diff --git a/src/emu/streams.c b/src/emu/streams.c
index 715edd4c76f..44dfa36cf40 100644
--- a/src/emu/streams.c
+++ b/src/emu/streams.c
@@ -112,6 +112,7 @@ struct _stream_output
struct _sound_stream
{
/* linking information */
+ running_machine * machine; /* owning machine object */
sound_stream * next; /* next stream in the chain */
void * tag; /* tag (used for identification) */
int index; /* index for save states */
@@ -207,7 +208,7 @@ INLINE INT32 time_to_sampindex(const streams_private *strdata, const sound_strea
/***************************************************************************
- CORE IMPLEMENTATION
+ SYSTEM-LEVEL MANAGEMENT
***************************************************************************/
/*-------------------------------------------------
@@ -236,6 +237,18 @@ void streams_init(running_machine *machine, attoseconds_t update_attoseconds)
/*-------------------------------------------------
+ streams_set_tag - set the tag to be associated
+ with all streams allocated from now on
+-------------------------------------------------*/
+
+void streams_set_tag(running_machine *machine, void *streamtag)
+{
+ streams_private *strdata = machine->streams_data;
+ strdata->current_tag = streamtag;
+}
+
+
+/*-------------------------------------------------
streams_update - update all the streams
periodically
-------------------------------------------------*/
@@ -326,17 +339,10 @@ void streams_update(running_machine *machine)
}
-/*-------------------------------------------------
- streams_set_tag - set the tag to be associated
- with all streams allocated from now on
--------------------------------------------------*/
-
-void streams_set_tag(running_machine *machine, void *streamtag)
-{
- streams_private *strdata = machine->streams_data;
- strdata->current_tag = streamtag;
-}
+/***************************************************************************
+ STREAM CONFIGURATION AND SETUP
+***************************************************************************/
/*-------------------------------------------------
stream_create - create a new stream
@@ -356,6 +362,7 @@ sound_stream *stream_create(int inputs, int outputs, int sample_rate, void *para
VPRINTF(("stream_create(%d, %d, %d) => %p\n", inputs, outputs, sample_rate, stream));
/* fill in the data */
+ stream->machine = Machine;
stream->tag = strdata->current_tag;
stream->index = strdata->stream_index++;
stream->sample_rate = sample_rate;
@@ -450,7 +457,7 @@ void stream_set_input(sound_stream *stream, int index, sound_stream *input_strea
input->source->dependents++;
/* update sample rates now that we know the input */
- recompute_sample_rate_data(Machine->streams_data, stream);
+ recompute_sample_rate_data(stream->machine->streams_data, stream);
}
@@ -461,7 +468,7 @@ void stream_set_input(sound_stream *stream, int index, sound_stream *input_strea
void stream_update(sound_stream *stream)
{
- streams_private *strdata = Machine->streams_data;
+ streams_private *strdata = stream->machine->streams_data;
INT32 update_sampindex = time_to_sampindex(strdata, stream, timer_get_time());
/* generate samples to get us up to the appropriate time */
@@ -475,6 +482,85 @@ void stream_update(sound_stream *stream)
/*-------------------------------------------------
+ stream_get_output_since_last_update - 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_output *output = &stream->output[outputnum];
+
+ /* force an update on the stream */
+ stream_update(stream);
+
+ /* compute the number of samples and a pointer to the output buffer */
+ *numsamples = stream->output_sampindex - stream->output_update_sampindex;
+ return output->buffer + (stream->output_update_sampindex - stream->output_base_sampindex);
+}
+
+
+
+/***************************************************************************
+ STREAM TIMING
+***************************************************************************/
+
+/*-------------------------------------------------
+ stream_get_sample_rate - return the currently
+ set sample rate on a given stream
+-------------------------------------------------*/
+
+int stream_get_sample_rate(sound_stream *stream)
+{
+ /* take into account any pending sample rate changes */
+ return (stream->new_sample_rate != 0) ? stream->new_sample_rate : stream->sample_rate;
+}
+
+
+/*-------------------------------------------------
+ stream_set_sample_rate - set the sample rate
+ on a given stream
+-------------------------------------------------*/
+
+void stream_set_sample_rate(sound_stream *stream, int sample_rate)
+{
+ /* we will update this on the next global update */
+ if (sample_rate != stream_get_sample_rate(stream))
+ stream->new_sample_rate = sample_rate;
+}
+
+
+/*-------------------------------------------------
+ stream_get_time - return the emulation time
+ of the next sample to be generated on the
+ stream
+-------------------------------------------------*/
+
+attotime stream_get_time(sound_stream *stream)
+{
+ streams_private *strdata = stream->machine->streams_data;
+ attotime base = attotime_make(strdata->last_update.seconds, 0);
+ return attotime_add_attoseconds(base, stream->output_sampindex * stream->attoseconds_per_sample);
+}
+
+
+/*-------------------------------------------------
+ stream_get_sample_period - return the duration
+ of a single sample for a stream
+-------------------------------------------------*/
+
+attotime stream_get_sample_period(sound_stream *stream)
+{
+ return attotime_make(0, stream->attoseconds_per_sample);
+}
+
+
+
+/***************************************************************************
+ STREAM INFORMATION AND CONTROL
+***************************************************************************/
+
+/*-------------------------------------------------
stream_find_by_tag - find a stream using a
tag and index
-------------------------------------------------*/
@@ -538,38 +624,6 @@ void stream_set_output_gain(sound_stream *stream, int output, float gain)
}
-/*-------------------------------------------------
- stream_set_sample_rate - set the sample rate
- on a given stream
--------------------------------------------------*/
-
-void stream_set_sample_rate(sound_stream *stream, int sample_rate)
-{
- /* we will update this on the next global update */
- if ((stream->new_sample_rate == 0 && sample_rate != stream->sample_rate) || (stream->new_sample_rate != 0 && sample_rate != stream->new_sample_rate))
- stream->new_sample_rate = sample_rate;
-}
-
-
-/*-------------------------------------------------
- stream_get_output_since_last_update - 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_output *output = &stream->output[outputnum];
-
- /* force an update on the stream */
- stream_update(stream);
-
- /* compute the number of samples and a pointer to the output buffer */
- *numsamples = stream->output_sampindex - stream->output_update_sampindex;
- return output->buffer + (stream->output_update_sampindex - stream->output_base_sampindex);
-}
-
-
/***************************************************************************
STREAM BUFFER MAINTENANCE
diff --git a/src/emu/streams.h b/src/emu/streams.h
index b49fd0e66cd..2bdb80ad20c 100644
--- a/src/emu/streams.h
+++ b/src/emu/streams.h
@@ -29,22 +29,68 @@ typedef void (*stream_callback)(void *param, stream_sample_t **inputs, stream_sa
FUNCTION PROTOTYPES
***************************************************************************/
+
+/* ----- system-level management ----- */
+
+/* initialize the streams engine */
void streams_init(running_machine *machine, attoseconds_t update_subseconds);
+
+/* set the tag to be associated with all streams allocated from now on */
void streams_set_tag(running_machine *machine, void *streamtag);
+
+/* update all the streams periodically */
void streams_update(running_machine *machine);
-/* core stream configuration and operation */
+
+
+/* ----- stream configuration and setup ----- */
+
+/* create a new stream */
sound_stream *stream_create(int inputs, int outputs, int sample_rate, void *param, stream_callback callback);
+
+/* 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);
-/* utilities for accessing a particular stream */
+
+
+/* ----- 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 ----- */
+
+/* find a stream using a tag and index */
sound_stream *stream_find_by_tag(void *streamtag, 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);
-void stream_set_sample_rate(sound_stream *stream, int sample_rate);
+
#endif