summaryrefslogtreecommitdiff
path: root/src/mixer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mixer.cpp')
-rw-r--r--src/mixer.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/mixer.cpp b/src/mixer.cpp
index 6aaa8204d..6014f6082 100644
--- a/src/mixer.cpp
+++ b/src/mixer.cpp
@@ -15,6 +15,7 @@
#include "framerate_type.h"
#include "safeguards.h"
+#include "mixer.h"
struct MixerChannel {
bool active;
@@ -38,6 +39,7 @@ struct MixerChannel {
static MixerChannel _channels[8];
static uint32 _play_rate = 11025;
static uint32 _max_size = UINT_MAX;
+static MxStreamCallback _music_stream = NULL;
/**
* The theoretical maximum volume for a single sound sample. Multiple sound
@@ -151,6 +153,9 @@ void MxMixSamples(void *buffer, uint samples)
/* Clear the buffer */
memset(buffer, 0, sizeof(int16) * 2 * samples);
+ /* Fetch music if a sampled stream is available */
+ if (_music_stream) _music_stream((int16*)buffer, samples);
+
/* Mix each channel */
for (mc = _channels; mc != endof(_channels); mc++) {
if (mc->active) {
@@ -215,6 +220,17 @@ void MxSetChannelVolume(MixerChannel *mc, uint volume, float pan)
void MxActivateChannel(MixerChannel *mc)
{
mc->active = true;
+}
+
+/**
+ * Set source of PCM music
+ * @param music_callback Function that will be called to fill sample buffers with music data.
+ * @return Sample rate of mixer, which the buffers supplied to the callback must be rendered at.
+ */
+uint32 MxSetMusicSource(MxStreamCallback music_callback)
+{
+ _music_stream = music_callback;
+ return _play_rate;
}
@@ -222,5 +238,6 @@ bool MxInitialize(uint rate)
{
_play_rate = rate;
_max_size = UINT_MAX / _play_rate;
+ _music_stream = NULL; /* rate may have changed, any music source is now invalid */
return true;
}