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

small envelope cleanup

git-svn-id: https://pimpmobile.svn.sourceforge.net/svnroot/pimpmobile/trunk@115 3d5ecaf0-f903-0410-b953-c2c1a4d75763
parent e1df9df6
......@@ -58,12 +58,10 @@ unsigned eval_vol_env(pimp_channel_state &chan)
}
#endif
int __pimp_envelope_sample(pimp_envelope_state *state, bool sustain)
int __pimp_envelope_sample(pimp_envelope_state *state)
{
ASSERT(NULL != chan.vol_env);
ASSERT(NULL != state);
// TODO: sustain
// the magnitude of the envelope at tick N:
// first, find the last node at or before tick N - its position is M
// then, the magnitude of the envelope at tick N is given by
......@@ -75,11 +73,19 @@ int __pimp_envelope_sample(pimp_envelope_state *state, bool sustain)
int val = state->env->node_magnitude[state->current_node];
val += ((long long)delta * internal_tick) >> 9;
return val << 2;
}
void __pimp_envelope_advance_tick(pimp_envelope_state *state, bool sustain)
{
ASSERT(NULL != state);
// advance a tick (TODO: move to separate function)
state->current_tick++;
iprintf("%d\n", state->current_tick);
if (state->current_node < (state->env->node_count - 1))
{
// TODO: sustain
#if 0
if (chan.vol_env->flags & (1 << 1))
{
......@@ -93,6 +99,4 @@ int __pimp_envelope_sample(pimp_envelope_state *state, bool sustain)
state->current_node++;
}
}
return val << 2;
}
......@@ -28,6 +28,7 @@ STATIC INLINE void __pimp_envelope_reset(pimp_envelope_state *state)
state->current_tick = 0;
}
int __pimp_envelope_sample(pimp_envelope_state *state, bool sustain);
int __pimp_envelope_sample(pimp_envelope_state *state);
void __pimp_envelope_advance_tick(pimp_envelope_state *state, bool sustain);
#endif /* PIMP_ENVELOPE_H */
......@@ -10,15 +10,15 @@
pimp_mod_context __pimp_ctx;
pimp_mixer __pimp_mixer;
static s8 sound_buffers[2][SOUND_BUFFER_SIZE] IWRAM_DATA;
static u32 sound_buffer_index = 0;
STATIC s8 __pimp_sound_buffers[2][SOUND_BUFFER_SIZE] IWRAM_DATA;
STATIC u32 __pimp_sound_buffer_index = 0;
extern "C" void pimp_init(const void *module, const void *sample_bank)
{
__pimp_mod_context_init(&__pimp_ctx, (const pimp_module*)module, (const u8*)sample_bank, &__pimp_mixer);
u32 zero = 0;
CpuFastSet(&zero, &sound_buffers[0][0], DMA_SRC_FIXED | ((SOUND_BUFFER_SIZE / 4) * 2));
CpuFastSet(&zero, &__pimp_sound_buffers[0][0], DMA_SRC_FIXED | ((SOUND_BUFFER_SIZE / 4) * 2));
REG_SOUNDCNT_H = SNDA_VOL_100 | SNDA_L_ENABLE | SNDA_R_ENABLE | SNDA_RESET_FIFO;
REG_SOUNDCNT_X = (1 << 7);
......@@ -34,14 +34,14 @@ extern "C" void pimp_close()
extern "C" void pimp_vblank()
{
if (sound_buffer_index == 0)
if (__pimp_sound_buffer_index == 0)
{
REG_DMA1CNT = 0;
REG_DMA1SAD = (u32) &(sound_buffers[0][0]);
REG_DMA1SAD = (u32) &(__pimp_sound_buffers[0][0]);
REG_DMA1DAD = (u32) &REG_FIFO_A;
REG_DMA1CNT = DMA_DST_FIXED | DMA_REPEAT | DMA32 | DMA_SPECIAL | DMA_ENABLE;
}
sound_buffer_index ^= 1;
__pimp_sound_buffer_index ^= 1;
}
extern "C" void pimp_set_callback(pimp_callback in_callback)
......@@ -70,7 +70,7 @@ extern "C" void pimp_frame()
if (TRUE == locked) return; /* whops, we're in the middle of filling. sorry. you did something wrong! */
locked = TRUE;
__pimp_render(&__pimp_ctx, sound_buffers[sound_buffer_index], SOUND_BUFFER_SIZE);
__pimp_render(&__pimp_ctx, __pimp_sound_buffers[__pimp_sound_buffer_index], SOUND_BUFFER_SIZE);
locked = FALSE;
}
......@@ -10,19 +10,19 @@
// #define PRINT_PATTERNS
/* need to move these to a separate channel state header (?) */
void porta_up(pimp_channel_state &chan, s32 period_low_clamp)
STATIC void porta_up(pimp_channel_state &chan, s32 period_low_clamp)
{
chan.final_period -= chan.porta_speed;
if (chan.final_period < period_low_clamp) chan.final_period = period_low_clamp;
}
void porta_down(pimp_channel_state &chan, s32 period_high_clamp)
STATIC void porta_down(pimp_channel_state &chan, s32 period_high_clamp)
{
chan.final_period += chan.porta_speed;
if (chan.final_period > period_high_clamp) chan.final_period = period_high_clamp;
}
void porta_note(pimp_channel_state &chan)
STATIC void porta_note(pimp_channel_state &chan)
{
if (chan.final_period > chan.porta_target)
{
......@@ -36,6 +36,18 @@ void porta_note(pimp_channel_state &chan)
}
}
STATIC int __pimp_channel_get_volume(pimp_channel_state *chan)
{
int volume = chan->volume;
if (chan->vol_env.env != 0)
{
volume = (volume * __pimp_envelope_sample(&chan->vol_env)) >> 8;
__pimp_envelope_advance_tick(&chan->vol_env, true);
}
return volume;
}
void update_row(pimp_mod_context *ctx)
{
ASSERT(mod != 0);
......@@ -341,8 +353,7 @@ $f0-$ff Tone porta
if (volume_dirty || chan.vol_env.env != 0)
{
mc.volume = (chan.volume * ctx->global_volume) >> 8;
if (chan.vol_env.env != 0) mc.volume = (mc.volume * __pimp_envelope_sample(&chan.vol_env, true)) >> 8;
mc.volume = (__pimp_channel_get_volume(&chan) * ctx->global_volume) >> 8;
}
}
......@@ -537,11 +548,10 @@ $f0-$ff Tone porta
if (volume_dirty || chan.vol_env.env != 0)
{
DEBUG_PRINT(("setting volume to: %02X\n", chan.volume));
mc.volume = (chan.volume * ctx->global_volume) >> 8;
if (chan.vol_env.env != 0) mc.volume = (mc.volume * __pimp_envelope_sample(&chan.vol_env, true)) >> 8;
mc.volume = (__pimp_channel_get_volume(&chan) * ctx->global_volume) >> 8;
}
}
ctx->curr_tick++;
}
......
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