Commit b3645db4 authored by Erik Faye-Lund's avatar Erik Faye-Lund
Browse files

tidied up the mixer a bit

moved the mix-buffer into the mixer-struct. better for thread-safety.

git-svn-id: https://pimpmobile.svn.sourceforge.net/svnroot/pimpmobile/trunk@174 3d5ecaf0-f903-0410-b953-c2c1a4d75763
parent 6a2726e8
......@@ -30,6 +30,7 @@ s32 __pimp_mix_buffer[SOUND_BUFFER_SIZE] IWRAM_DATA;
void pimp_init(const void *module, const void *sample_bank)
{
__pimp_mixer.mix_buffer = __pimp_mix_buffer;
__pimp_mod_context_init(&__pimp_ctx, (const pimp_module*)module, (const u8*)sample_bank, &__pimp_mixer);
u32 zero = 0;
......
......@@ -6,6 +6,19 @@
#include "pimp_mixer.h"
#include "pimp_debug.h"
void __pimp_mixer_reset(pimp_mixer *mixer)
{
u32 c;
ASSERT(mixer != NULL);
for (c = 0; c < CHANNELS; ++c)
{
mixer->channels[c].sample_data = 0;
mixer->channels[c].sample_cursor = 0;
mixer->channels[c].sample_cursor_delta = 0;
}
}
/*
TODO: this all needs a rewrite.
next implementation should always keep track of the next loop-event for all active channels,
......@@ -142,34 +155,24 @@ void __pimp_mixer_mix_channel(pimp_mixer_channel_state *chan, s32 *target, u32 s
}
ASSERT(chan->sample_data != 0);
#if 1
chan->sample_cursor = __pimp_mixer_mix_samples(target, samples, chan->sample_data, chan->volume, chan->sample_cursor, chan->sample_cursor_delta);
#else
chan->sample_cursor = chan->sample_cursor + chan->sample_cursor_delta * samples;
#endif
}
void __pimp_mixer_reset(pimp_mixer *mixer)
{
u32 c;
ASSERT(mixer != NULL);
for (c = 0; c < CHANNELS; ++c)
{
mixer->channels[c].sample_data = 0;
mixer->channels[c].sample_cursor = 0;
mixer->channels[c].sample_cursor_delta = 0;
}
}
extern s32 __pimp_mix_buffer[];
void __pimp_mixer_mix(pimp_mixer *mixer, s8 *target, int samples)
{
u32 c;
int dc_offs;
ASSERT(NULL != mixer);
ASSERT(NULL != mixer->mix_buffer);
ASSERT(NULL != target);
ASSERT(samples > 0);
__pimp_mixer_clear(__pimp_mix_buffer, samples);
__pimp_mixer_clear(mixer->mix_buffer, samples);
dc_offs = 0;
for (c = 0; c < CHANNELS; ++c)
......@@ -177,12 +180,12 @@ void __pimp_mixer_mix(pimp_mixer *mixer, s8 *target, int samples)
pimp_mixer_channel_state *chan = &mixer->channels[c];
if ((NULL != chan->sample_data) && (chan->volume > 1))
{
__pimp_mixer_mix_channel(chan, __pimp_mix_buffer, samples);
__pimp_mixer_mix_channel(chan, mixer->mix_buffer, samples);
dc_offs += chan->volume * 128;
}
}
dc_offs >>= 8;
__pimp_mixer_clip_samples(target, __pimp_mix_buffer, samples, dc_offs);
__pimp_mixer_clip_samples(target, mixer->mix_buffer, samples, dc_offs);
}
......@@ -36,7 +36,7 @@ typedef struct
typedef struct
{
pimp_mixer_channel_state channels[CHANNELS];
/* TODO: any other needed states */
s32 *mix_buffer;
} pimp_mixer;
void __pimp_mixer_reset(pimp_mixer *mixer);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment