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

cleanup, and some more player logic

git-svn-id: https://pimpmobile.svn.sourceforge.net/svnroot/pimpmobile/trunk@50 3d5ecaf0-f903-0410-b953-c2c1a4d75763
parent a74bfbc1
......@@ -42,29 +42,28 @@ OBJS = \
src/mixer.iwram.o \
src/mixer_arm.iwram.o
.PHONY: all clean
.PHONY: all clean converter
all: example.gba
all: bin/example.gba
clean:
$(RM) example.elf example.gba example.o example.map sample.o converter converter.exe $(OBJS) lib/libpimpmobile.a *~ src/*~ include/*~
$(RM) bin/example.elf bin/example.gba example.o example.map sample.o $(OBJS) lib/libpimpmobile.a *~ src/*~ include/*~
run: example.gba
$(GBAEMU) example.gba
run: bin/example.gba
$(GBAEMU) bin/example.gba
debug: example.elf
$(DEVKITPRO)/insight/bin/arm-elf-insight.exe &
$(DEVKITPRO)/vba/VisualBoyAdvance-SDL.exe -Gtcp:55555 example.elf
converter: converter.cpp converter_xm.cpp converter_s3m.cpp converter_mod.cpp converter.h
g++ converter.cpp converter_xm.cpp converter_s3m.cpp converter_mod.cpp -o converter
bin/converter: converter/converter.cpp converter/converter_xm.cpp converter/converter_s3m.cpp converter/converter_mod.cpp converter/converter.h
g++ converter/converter.cpp converter/converter_xm.cpp converter/converter_s3m.cpp converter/converter_mod.cpp -o bin/converter
lut_gen: lut_gen.cpp
g++ lut_gen.cpp -o lut_gen
bin/lut_gen: lut_gen.cpp
g++ lut_gen.cpp -o bin/lut_gen
example.gba: converter
example.elf: example.o sample.o lib/libpimpmobile.a
bin/example.gba: converter
bin/example.elf: example.o sample.o lib/libpimpmobile.a
lib/libpimpmobile.a: $(OBJS)
%.a:
......
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <assert.h>
......@@ -124,11 +125,8 @@ int main(int argc, char *argv[])
fclose(fp);
printf("done loading\n");
if (mod != 0)
{
printf("converting samples\n");
convert_samples(mod); // convert all samples to unsigned 8bit format
}
printf("converting samples\n");
convert_samples(mod); // convert all samples to unsigned 8bit format
}
return 0;
}
......@@ -43,7 +43,7 @@ int main()
BG_COLORS[241]=RGB5(31, 31, 31);
REG_DISPCNT = MODE_0 | BG0_ON;
pimp_init();
pimp_init(0, 0);
mixer::sample_t mixer_sample;
mixer_sample.data = sample;
......
......@@ -2,35 +2,11 @@
#define _PIMPMOBILE_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
extern "C"
{
unsigned int length;
unsigned int loop_start;
unsigned int loop_length;
unsigned char volume;
signed char finetune;
unsigned char type;
unsigned char pan;
signed char rel_note;
} pimp_sample_t;
typedef struct
{
unsigned int length;
unsigned int loop_start;
unsigned int loop_length;
unsigned char volume;
signed char finetune;
unsigned char type;
unsigned char pan;
signed char rel_note;
} pimp_channel_t;
#endif
void pimp_init();
void pimp_init(void *module, void *sample_bank);
void pimp_close();
void pimp_vblank(); /* call this on the beginning of each vsync */
......
......@@ -3,6 +3,8 @@
#include <string.h>
#include <math.h>
#include "src/config.h" // get the current config
const unsigned char clz_lut[256] =
{
0x8, 0x7, 0x6, 0x6, 0x5, 0x5, 0x5, 0x5, 0x4, 0x4, 0x4, 0x4, 0x4, 0x4, 0x4, 0x4, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
......@@ -34,8 +36,6 @@ static inline unsigned clz16(unsigned input)
return clz_lut[input] + c;
}
#define PLAYBACK_FREQ 18157
unsigned short linear_freq_lut[12 * 64];
unsigned get_linear_delta(unsigned period)
......@@ -44,9 +44,9 @@ unsigned get_linear_delta(unsigned period)
unsigned octave = p / (12 * 64);
unsigned octave_period = p % (12 * 64);
unsigned frequency = linear_freq_lut[octave_period] << octave;
// return float(frequency) * (1.0 / (1 << 9));
frequency = ((long long)frequency * unsigned((1.0 / PLAYBACK_FREQ) * (1 << 3) * (1ULL << 32)) + (1ULL << 31)) >> 32;
// BEHOLD: the expression of the devil 2.0
frequency = ((long long)frequency * unsigned((1.0 / SAMPLERATE) * (1 << 3) * (1ULL << 32)) + (1ULL << 31)) >> 32;
return frequency;
}
......@@ -55,10 +55,6 @@ unsigned get_linear_delta(unsigned period)
#define AMIGA_FREQ_TABLE_FRAC_BITS (15 - AMIGA_FREQ_TABLE_LOG_SIZE)
unsigned short amiga_freq_lut[(AMIGA_FREQ_TABLE_SIZE / 2) + 1];
/* TODO:
- make the routine output in 20.12 fixedpoint-format
*/
unsigned get_amiga_delta(unsigned period)
{
unsigned shamt = clz16(period) - 1;
......@@ -76,7 +72,7 @@ unsigned get_amiga_delta(unsigned period)
// BEHOLD: the expression of the devil
// quasi-explaination: the table-lookup the playback freq - the LUT presc - make it overflow - round it - pick the top
frequency = ((long long)frequency * unsigned(((1.0 / PLAYBACK_FREQ) * (1 << 6)) * (1LL << 32)) + (1ULL << 31)) >> 32;
frequency = ((long long)frequency * unsigned(((1.0 / SAMPLERATE) * (1 << 6)) * (1LL << 32)) + (1ULL << 31)) >> 32;
return frequency;
}
......@@ -117,7 +113,7 @@ int main(int argc, char *argv[])
for (unsigned period = 1; period < 32767; period += 17)
{
float frequency1 = (8363 * 1712) / float(period);
float delta1 = frequency1 / PLAYBACK_FREQ;
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));
......@@ -138,7 +134,7 @@ int main(int argc, char *argv[])
int period = (10 * 12 * 16 * 4) - i * (16 * 4) - finetune / 2;
float frequency1 = 8363 * pow(2.0, float(6 * 12 * 16 * 4 - period) / (12 * 16 * 4));
float delta1 = frequency1 / PLAYBACK_FREQ;
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));
......
......@@ -23,12 +23,16 @@
#include <stdio.h>
#include <assert.h>
#include "internal.h"
#include "mixer.h"
s8 sound_buffers[2][SOUND_BUFFER_SIZE] IWRAM_DATA ALIGN(4);
static u32 sound_buffer_index = 0;
extern "C" void pimp_init()
unsigned char *sample_bank;
pimp_module_t *mod;
extern "C" void pimp_init(void *module, void *sample_bank)
{
u32 zero = 0;
CpuFastSet(&zero, &sound_buffers[0][0], DMA_SRC_FIXED | ((SOUND_BUFFER_SIZE / 4) * 2));
......@@ -36,7 +40,7 @@ extern "C" void pimp_init()
REG_SOUNDCNT_X = SOUND_ENABLE;
/* setup timer-shit */
REG_TM0CNT_L = (1 << 16) - ((1 << 24) / 18157);
REG_TM0CNT_L = (1 << 16) - ((1 << 24) / SAMPLERATE);
REG_TM0CNT_H = TIMER_START;
}
......@@ -107,15 +111,27 @@ end for
*/
pimp_pattern_entry_t *get_next_pattern_entry(unsigned chan)
{
static int row = -1;
if (chan == 0) row++;
return 0;
}
static pimp_channel_t channels[CHANNELS];
void update_row()
{
#if 0
assert(mod != 0);
for (u32 c = 0; c < CHANNELS; ++c)
{
pimp_channel_t &chan = mod->channels[c];
unsigned instr = mod->curr_pattern[mod->row][c].sample;
pimp_channel_t &chan = channels[c];
pimp_pattern_entry_t *note = get_next_pattern_entry(c);
// unsigned instr = mod->curr_pattern[mod->row][c].sample;
if (instr > 0)
if (0) // note->instr > 0)
{
// NOTE ON !
// unsigned note = mod->pattern_data[offs].note;
......@@ -125,20 +141,60 @@ void update_row()
switch (chan.effect)
{
case
case 0x00:
// effect 0 with parameter 0 is no effect at all
if (chan.effect_param == 0) continue;
default: assert(0);
}
}
#endif
}
u32 samples_per_tick = 304;
u32 samples_per_tick = 200;
static void update_tick()
{
if (mod == 0) return; // no module active (sound-effects can still be playing, though)
for (u32 c = 0; c < CHANNELS; ++c)
{
{
pimp_channel_t &chan = channels[c];
chan.period = 1000;
chan.effect = EFF_PORTA_UP;
chan.porta_speed = 1;
bool period_dirty = false;
switch (chan.effect)
{
case EFF_NONE: break;
case EFF_PORTA_UP:
chan.period += chan.porta_speed;
period_dirty = true;
break;
case EFF_PORTA_DOWN:
chan.period -= chan.porta_speed;
period_dirty = true;
break;
case EFF_PORTA_NOTE:
period_dirty = true;
break;
case EFF_VIBRATO:
break;
default: assert(0);
}
if (period_dirty)
{
// period to delta-conversion
}
}
}
......
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