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

removed MOST c++-comments, fixed 16khz rendering (works, but clicks)

git-svn-id: https://pimpmobile.svn.sourceforge.net/svnroot/pimpmobile/trunk@156 3d5ecaf0-f903-0410-b953-c2c1a4d75763
parent 12773987
......@@ -46,8 +46,9 @@ else
CPPFLAGS += -DRELEASE -DNDEBUG
CXXFLAGS += -O3 -fomit-frame-pointer
CFLAGS += -O3 -fomit-frame-pointer
# OBJS += src/pimp_mixer_portable.o
OBJS += src/pimp_mixer_arm.o
# OBJS += src/pimp_mixer_clip_arm.o
OBJS += src/pimp_mixer_clip_arm.o
endif
......
......@@ -115,7 +115,7 @@ int main(int argc, char *argv[])
for (unsigned period = 1; period < 32767; period += 17)
{
float frequency1 = (8363 * 1712) / float(period);
float delta1 = frequency1 / SAMPLERATE;
float delta1 = frequency1 / (SAMPLERATE);
delta1 = unsigned(delta1 * (1 << 12) + 0.5) * (1.0 / (1 << 12));
float delta2 = get_amiga_delta(period) * (1.0 / (1 << 12));
......@@ -136,7 +136,7 @@ int main(int argc, char *argv[])
int period = (10 * 12 * 16 * 4) - i * (16 * 4) - fine_tune / 2;
float frequency1 = 8363 * pow(2.0, float(6 * 12 * 16 * 4 - period) / (12 * 16 * 4));
float delta1 = frequency1 / SAMPLERATE;
float delta1 = frequency1 / (SAMPLERATE);
delta1 = unsigned(delta1 * (1 << 12) + 0.5) * (1.0 / (1 << 12));
float delta2 = get_linear_delta(period) * (1.0 / (1 << 12));
......
......@@ -6,30 +6,26 @@
#ifndef PIMP_CONFIG_H
#define PIMP_CONFIG_H
#define CYCLES_PR_FRAME 280896
/* 32 is the maximum amount of channels in fasttracker2. a nice default. */
#define CHANNELS 8
#define CHANNELS 32
/* check the sample-rate calculator at http://www.pineight.com/gba/samplerates/ for more glitch-free samplerates */
/* 0x4000100 = 0xFFFF, 0x4000102 = 0x0083 */
#define SAMPLERATE (18157.16)
/* #define SAMPLERATE (18157.16) */
/* #define SAMPLERATE (16384) */
#define SAMPLERATE 15768.06
/* only 130 bytes big, quite damn pleasing results */
#define AMIGA_DELTA_LUT_LOG_SIZE 7
/* derivated settings. don't touch. */
#define SOUND_BUFFER_SIZE (CYCLES_PR_FRAME / ((int)((1 << 24) / SAMPLERATE)))
#define AMIGA_DELTA_LUT_SIZE (1 << AMIGA_DELTA_LUT_LOG_SIZE)
#define AMIGA_DELTA_LUT_FRAC_BITS (15 - AMIGA_DELTA_LUT_LOG_SIZE)
/* enable / disable assert */
/*
#define DEBUG_PRINTF_ENABLED
#define ASSERT_ENABLED
#define DEBUG_PRINT_ENABLE
#define ASSERT_ENABLE
*/
#define DEBUG_PRINTF_ENABLED
// #define ASSERT_ENABLED
#endif /* PIMP_CONFIG_H */
......@@ -6,17 +6,25 @@
#ifndef PIMP_DEBUG_H
#define PIMP_DEBUG_H
#ifdef DEBUG_PRINTF_ENABLED
#define DEBUG_PRINT(X) iprintf X
/* current debug level */
#define DEBUG_LEVEL 100
/* some standard debug levels */
#define DEBUG_LEVEL_INFO 10
#define DEBUG_LEVEL_WARNING 50
#define DEBUG_LEVEL_ERROR 100
#ifdef DEBUG_PRINT_ENABLE
#define DEBUG_PRINT(debug_level, X) do { if (DEBUG_LEVEL <= debug_level) iprintf X } while(0)
#else
#define DEBUG_PRINT(X)
#define DEBUG_PRINT(debug_level, X)
#endif
#ifdef ASSERT_ENABLED
#ifdef ASSERT_ENABLE
#include <stdlib.h>
#include <stdio.h>
#define ASSERT(expr) \
do { \
do { \
if (!(expr)) iprintf("*** ASSERT FAILED %s AT (%s:%i)\n", #expr, __FILE__, __LINE__); \
} while(0)
#else
......
......@@ -19,7 +19,7 @@ typedef struct
s16 node_delta[25];
u8 node_count;
u8 flags; // bit 0: loop enable, bit 1: sustain loop enable
u8 flags; /* bit 0: loop enable, bit 1: sustain loop enable */
u8 loop_start, loop_end;
u8 sustain_loop_start, sustain_loop_end;
} pimp_envelope;
......
......@@ -7,6 +7,7 @@
#define PIMP_TYPES_H /* prevent pimp_types.h from being included */
#include "pimp_render.h"
#include "pimp_debug.h"
#include <gba_dma.h>
#include <gba_sound.h>
......@@ -18,8 +19,14 @@
pimp_mod_context __pimp_ctx;
pimp_mixer __pimp_mixer;
/* setup some constants */
#define CYCLES_PR_FRAME 280896
#define SAMPLES_PER_FRAME ((int)((1 << 24) / ((float)SAMPLERATE)))
#define SOUND_BUFFER_SIZE ((int)((float)CYCLES_PR_FRAME / SAMPLES_PER_FRAME))
STATIC s8 __pimp_sound_buffers[2][SOUND_BUFFER_SIZE] IWRAM_DATA;
STATIC u32 __pimp_sound_buffer_index = 0;
s32 __pimp_mix_buffer[SOUND_BUFFER_SIZE] IWRAM_DATA;
void pimp_init(const void *module, const void *sample_bank)
{
......@@ -30,8 +37,10 @@ void pimp_init(const void *module, const void *sample_bank)
REG_SOUNDCNT_H = SNDA_VOL_100 | SNDA_L_ENABLE | SNDA_R_ENABLE | SNDA_RESET_FIFO;
REG_SOUNDCNT_X = (1 << 7);
/* setup timer-shit */
REG_TM0CNT_L = (1 << 16) - (int)((1 << 24) / SAMPLERATE);
DEBUG_PRINT(DEBUG_LEVEL_INFO, ("samples pr frame: 0x%x\nsound buffer size: %d\n", SAMPLES_PER_FRAME, SOUND_BUFFER_SIZE));
/* setup timer */
REG_TM0CNT_L = (1 << 16) - SAMPLES_PER_FRAME;
REG_TM0CNT_H = TIMER_START;
}
......@@ -77,7 +86,7 @@ void pimp_frame()
static volatile BOOL locked = FALSE;
if (TRUE == locked) return; /* whops, we're in the middle of filling. sorry. you did something wrong! */
locked = TRUE;
__pimp_render(&__pimp_ctx, __pimp_sound_buffers[__pimp_sound_buffer_index], SOUND_BUFFER_SIZE);
locked = FALSE;
......@@ -85,6 +94,14 @@ void pimp_frame()
void __pimp_mixer_clear(void *target, int samples)
{
u32 zero = 0;
CpuFastSet(&zero, target, DMA_SRC_FIXED | (samples));
int i;
const u32 zero = 0;
u32 *dst = (u32*)target;
for (i = samples &7; i; --i)
{
*dst++ = 0;
}
CpuFastSet(&zero, dst, DMA_SRC_FIXED | (samples & ~7));
}
......@@ -36,10 +36,10 @@ unsigned __pimp_get_linear_period(int note, int fine_tune)
ASSERT(fine_tune >= -8);
ASSERT(fine_tune < 8);
int xm_note = note - (12 * 1) - 1; // we extended our note-range with one octave.
int xm_note = note - (12 * 1) - 1; /* we extended our note-range with one octave. */
return (10 * 12 * 16 * 4 - xm_note * 16 * 4 - fine_tune / 2);
// return 10 * 12 * 16 * 4 - note * 16 * 4 - fine_tune / 2;
/* return 10 * 12 * 16 * 4 - note * 16 * 4 - fine_tune / 2; */
}
#include "linear_delta_lut.h"
......@@ -51,7 +51,7 @@ unsigned __pimp_get_linear_delta(unsigned period)
unsigned delta = linear_delta_lut[octave_period] << octave;
/* BEHOLD: the expression of the devil (this compiles to one arm-instruction) */
const unsigned int scale = (unsigned int)((1.0 / SAMPLERATE) * (1 << 3) * (1ULL << 32));
const unsigned int scale = (unsigned int)((1.0 / (SAMPLERATE)) * (1 << 3) * (1ULL << 32));
delta = ((long long)delta * scale + (1ULL << 31)) >> 32;
return delta;
}
......@@ -61,7 +61,7 @@ unsigned __pimp_get_linear_delta(unsigned period)
#include "amiga_period_lut.h"
unsigned __pimp_get_amiga_period(int note, int fine_tune)
{
fine_tune /= 8; // todo: interpolate instead?
fine_tune /= 8; /* todo: interpolate instead? */
ASSERT(fine_tune >= -8);
ASSERT(fine_tune <= 8);
......@@ -94,16 +94,16 @@ unsigned __pimp_get_amiga_delta(unsigned period)
unsigned p_frac = p & ((1 << AMIGA_DELTA_LUT_FRAC_BITS) - 1);
p >>= AMIGA_DELTA_LUT_FRAC_BITS;
// interpolate table-entries for better result
int d1 = amiga_delta_lut[p - (AMIGA_DELTA_LUT_SIZE / 2)]; // (8363 * 1712) / float(p);
int d2 = amiga_delta_lut[p + 1 - (AMIGA_DELTA_LUT_SIZE / 2)]; // (8363 * 1712) / float(p + 1);
/* interpolate table-entries for better result */
int d1 = amiga_delta_lut[p - (AMIGA_DELTA_LUT_SIZE / 2)]; /* (8363 * 1712) / float(p) */
int d2 = amiga_delta_lut[p + 1 - (AMIGA_DELTA_LUT_SIZE / 2)]; /* (8363 * 1712) / float(p + 1) */
unsigned delta = (d1 << AMIGA_DELTA_LUT_FRAC_BITS) + (d2 - d1) * p_frac;
if (shamt > AMIGA_DELTA_LUT_FRAC_BITS) delta <<= shamt - AMIGA_DELTA_LUT_FRAC_BITS;
else delta >>= AMIGA_DELTA_LUT_FRAC_BITS - shamt;
/* BEHOLD: the expression of the devil 2.0 (this compiles to one arm-instruction) */
const unsigned int scale = (unsigned int)(((1.0 / SAMPLERATE) * (1 << 6)) * (1LL << 32));
const unsigned int scale = (unsigned int)(((1.0 / (SAMPLERATE)) * (1 << 6)) * (1LL << 32));
delta = ((long long)delta * scale + (1ULL << 31)) >> 32;
return delta;
......
......@@ -35,12 +35,12 @@ STATIC BOOL detect_loop_event(pimp_mixer_channel_state *chan, int samples)
case LOOP_TYPE_PINGPONG:
if (chan->sample_cursor_delta >= 0)
{
// moving forwards through the sample
/* moving forwards through the sample */
check_point = chan->loop_end;
}
else
{
// moving backwards through the sample
/* moving backwards through the sample */
check_point = chan->loop_start;
if (end_sample < (check_point << 12))
{
......@@ -63,7 +63,7 @@ STATIC BOOL detect_loop_event(pimp_mixer_channel_state *chan, int samples)
return FALSE;
}
// returns false if we hit sample-end
/* returns false if we hit sample-end */
BOOL process_loop_event(pimp_mixer_channel_state *chan)
{
switch (chan->loop_type)
......@@ -115,7 +115,7 @@ void __pimp_mixer_mix_channel(pimp_mixer_channel_state *chan, s32 *target, u32 s
while (samples > 0 && detect_loop_event(chan, samples) == TRUE)
{
// TODO: iterative binary search here instead
/* TODO: iterative binary search here instead */
do
{
ASSERT((chan->sample_cursor >> 12) < chan->sample_length);
......@@ -134,12 +134,12 @@ void __pimp_mixer_mix_channel(pimp_mixer_channel_state *chan, s32 *target, u32 s
if (process_loop_event(chan) == FALSE)
{
// the sample has stopped, we need to fill the rest of the buffer with the dc-offset, so it doesn't ruin our unsigned mixing-thing
/* the sample has stopped, we need to fill the rest of the buffer with the dc-offset, so it doesn't ruin our unsigned mixing-thing */
while (samples--)
{
*target++ += chan->volume * 128;
}
// terminate sample
/* terminate sample */
chan->sample_data = 0;
return;
}
......@@ -162,23 +162,23 @@ void __pimp_mixer_reset(pimp_mixer *mixer)
}
}
STATIC s32 sound_mix_buffer[SOUND_BUFFER_SIZE] __attribute__((section(".iwram")));
extern s32 __pimp_mix_buffer[];
void __pimp_mixer_mix(pimp_mixer *mixer, s8 *target, int samples)
{
u32 c;
ASSERT(samples > 0);
__pimp_mixer_clear(sound_mix_buffer, samples);
__pimp_mixer_clear(__pimp_mix_buffer, samples);
dc_offs = 0;
for (c = 0; c < CHANNELS; ++c)
{
pimp_mixer_channel_state *chan = &mixer->channels[c];
if (NULL != chan->sample_data) __pimp_mixer_mix_channel(chan, sound_mix_buffer, samples);
if (NULL != chan->sample_data) __pimp_mixer_mix_channel(chan, __pimp_mix_buffer, samples);
}
dc_offs >>= 8;
__pimp_mixer_clip_samples(target, sound_mix_buffer, samples, dc_offs);
__pimp_mixer_clip_samples(target, __pimp_mix_buffer, samples, dc_offs);
}
......@@ -61,6 +61,6 @@ void __pimp_mod_context_set_bpm(pimp_mod_context *ctx, int bpm)
ASSERT(bpm > 0);
/* we're using 8 fractional-bits for the tick-length */
const int temp = (int)((SAMPLERATE * 5) * (1 << 8));
const int temp = (int)(((SAMPLERATE) * 5) * (1 << 8));
ctx->tick_len = temp / (bpm * 2);
}
......@@ -29,8 +29,7 @@ typedef struct
u32 flags;
u32 reserved; /* for future flags */
// these are offsets relative to the begining of the pimp_module_t-structure
/* TODO: make these relative to their storage, and make a generic getter for those kinds of pointers */
/* these are offsets relative to the begining of the pimp_module_t-structure */
u32 order_ptr;
u32 pattern_ptr;
u32 channel_ptr;
......
......@@ -12,7 +12,7 @@
#include "pimp_mixer.h"
#include "pimp_math.h"
// #define PRINT_PATTERNS
/* #define PRINT_PATTERNS */
/* need to move these to a separate channel state header (?) */
STATIC void porta_up(pimp_channel_state *chan, s32 period_low_clamp)
......@@ -64,7 +64,7 @@ STATIC int __pimp_channel_get_volume(pimp_channel_state *chan)
chan->fadeout -= chan->instrument->volume_fadeout;
if (chan->fadeout <= 0)
{
// TODO: kill sample
/* TODO: kill sample */
chan->fadeout = 0;
}
}
......@@ -105,7 +105,7 @@ STATIC void __pimp_mod_context_update_row(pimp_mod_context *ctx)
if (note->note == KEY_OFF)
{
chan->sustain = FALSE;
volume_dirty = TRUE; // we need to update volume if note off killed note
volume_dirty = TRUE; /* we need to update volume if note off killed note */
}
else
{
......@@ -136,7 +136,7 @@ STATIC void __pimp_mod_context_update_row(pimp_mod_context *ctx)
{
/* TODO: this should be handeled in the converter, and as an assert. */
// stupid musician, tried to play an empty instrument...
/* stupid musician, tried to play an empty instrument... */
mc->sample_data = NULL;
mc->sample_cursor = 0;
mc->sample_cursor_delta = 0;
......@@ -172,7 +172,7 @@ STATIC void __pimp_mod_context_update_row(pimp_mod_context *ctx)
if (mc->sample_cursor > (mc->sample_length << 12))
{
if (ctx->mod->flags & FLAG_SAMPLE_OFFSET_CLAMP) mc->sample_cursor = mc->sample_length << 12;
else mc->sample_data = NULL; // kill sample
else mc->sample_data = NULL; /* kill sample */
}
}
......@@ -213,12 +213,12 @@ $f0-$ff Tone porta
if (note->volume_command > 0x50)
{
/* something else */
DEBUG_PRINT(("unsupported volume-command %02X\n", note->volume_command));
DEBUG_PRINT(DEBUG_LEVEL_ERROR, ("unsupported volume-command %02X\n", note->volume_command));
}
else
{
chan->volume = note->volume_command - 0x10;
// DEBUG_PRINT(("setting volume to: %02X\n", chan->volume));
DEBUG_PRINT(DEBUG_LEVEL_INFO, ("setting volume to: %02X\n", chan->volume));
volume_dirty = TRUE;
}
break;
......@@ -239,7 +239,7 @@ $f0-$ff Tone porta
default:
DEBUG_PRINT(("unsupported volume-command %02X\n", note->volume_command));
DEBUG_PRINT(DEBUG_LEVEL_ERROR, ("unsupported volume-command %02X\n", note->volume_command));
}
switch (chan->effect)
......@@ -257,7 +257,7 @@ $f0-$ff Tone porta
case EFF_PORTA_NOTE:
if (note->note > 0)
{
// no fine tune or relative note here, boooy
/* no fine tune or relative note here, boooy */
if (ctx->mod->flags & FLAG_LINEAR_PERIODS) chan->porta_target = __pimp_get_linear_period(note->note + chan->sample->rel_note, 0);
else chan->porta_target = __pimp_get_amiga_period(note->note, 0);
......@@ -274,7 +274,7 @@ $f0-$ff Tone porta
/* TODO: move to a separate function ? */
if (note->note > 0)
{
// no fine tune or relative note here, boooy
/* no fine tune or relative note here, boooy */
if (ctx->mod->flags & FLAG_LINEAR_PERIODS) chan->porta_target = __pimp_get_linear_period(note->note + chan->sample->rel_note, 0);
else chan->porta_target = __pimp_get_amiga_period(note->note, 0);
......@@ -321,8 +321,8 @@ $f0-$ff Tone porta
case EFF_BREAK_ROW:
__pimp_mod_context_set_pos(
ctx,
(chan->effect_param >> 4) * 10 + (chan->effect_param & 0xF) - 1, // row
ctx->curr_order + 1 // order
(chan->effect_param >> 4) * 10 + (chan->effect_param & 0xF) - 1, /* row */
ctx->curr_order + 1 /* order */
);
break;
......@@ -363,7 +363,7 @@ $f0-$ff Tone porta
break;
default:
DEBUG_PRINT(("unsupported effect E%X\n", chan->effect_param >> 4));
DEBUG_PRINT(DEBUG_LEVEL_ERROR, ("unsupported effect E%X\n", chan->effect_param >> 4));
}
break;
......@@ -380,7 +380,7 @@ $f0-$ff Tone porta
case EFF_PAN_SLIDE: break;
*/
case EFF_MULTI_RETRIG:
if ((note->effect_parameter & 0xF0) != 0) DEBUG_PRINT(("multi retrig x-parameter != 0 not supported\n"));
if ((note->effect_parameter & 0xF0) != 0) DEBUG_PRINT(DEBUG_LEVEL_ERROR, ("multi retrig x-parameter != 0 not supported\n"));
if ((note->effect_parameter & 0xF) != 0) chan->note_retrig = note->effect_parameter & 0xF;
break;
......@@ -397,7 +397,7 @@ $f0-$ff Tone porta
*/
default:
DEBUG_PRINT(("unsupported effect %02X\n", chan->effect));
DEBUG_PRINT(DEBUG_LEVEL_ERROR, ("unsupported effect %02X\n", chan->effect));
ASSERT(0);
}
......@@ -437,7 +437,7 @@ $f0-$ff Tone porta
STATIC void __pimp_mod_context_update_tick(pimp_mod_context *ctx)
{
u32 c;
if (ctx->mod == NULL) return; // no module active (sound-effects can still be playing, though)
if (ctx->mod == NULL) return; /* no module active (sound-effects can still be playing, though) */
if (ctx->curr_tick == ctx->curr_tempo)
{
......@@ -494,7 +494,7 @@ $f0-$ff Tone porta
case 0x9: break;
default:
DEBUG_PRINT(("unsupported volume-command %02X\n", chan->volume_command));
DEBUG_PRINT(DEBUG_LEVEL_ERROR, ("unsupported volume-command %02X\n", chan->volume_command));
}
switch (chan->effect)
......@@ -558,10 +558,10 @@ $f0-$ff Tone porta
break; /* fine volume slide is only done on tick0 */
case EFF_NOTE_DELAY:
// note on
/* note on */
if (--chan->note_delay == 0)
{
// TODO: replace with a note_on-function
/* TODO: replace with a note_on-function */
if (chan->instrument != 0)
{
chan->sample = get_sample(chan->instrument, chan->instrument->sample_map[chan->note]);
......@@ -597,10 +597,10 @@ $f0-$ff Tone porta
}
break;
// default: ASSERT(0);
/* default: ASSERT(0); */
}
// period to delta-conversion
/* period to delta-conversion */
if (period_dirty)
{
if (ctx->mod->flags & FLAG_LINEAR_PERIODS)
......@@ -613,7 +613,6 @@ $f0-$ff Tone porta
}
}
// if (c == 7) printf("%i\n", (volume_dirty) ? 1 : 0);
if (volume_dirty || chan->vol_env.env != 0)
{
mc->volume = (__pimp_channel_get_volume(chan) * ctx->global_volume) >> 8;
......@@ -646,7 +645,7 @@ void __pimp_render(pimp_mod_context *ctx, s8 *buf, u32 samples)
__pimp_mod_context_update_tick(ctx);
// fixed point tick length
/* fixed point tick length */
ctx->curr_tick_len += ctx->tick_len;
remainder = ctx->curr_tick_len >> 8;
ctx->curr_tick_len -= (ctx->curr_tick_len >> 8) << 8;
......
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