diff options
author | Segher Boessenkool <segher@kernel.crashing.org> | 2009-03-11 04:32:21 +0100 |
---|---|---|
committer | Segher Boessenkool <segher@kernel.crashing.org> | 2009-03-11 04:32:21 +0100 |
commit | dbf9877034ec70a13c776211ae948f59e91d4cd9 (patch) | |
tree | 9ccce4c0c377bafddab2c090a4650e6628e87cd1 /audio.c | |
parent | 5b76a1130e61066cdeda6e24ddce4e819d71f982 (diff) |
audio: Pretend all audio is looping U8 samples. Make that work, sort of.
Diffstat (limited to 'audio.c')
-rw-r--r-- | audio.c | 50 |
1 files changed, 45 insertions, 5 deletions
@@ -60,16 +60,56 @@ static u32 get_channel_bit(u32 ch, u32 reg) return (mem[reg] >> ch) & 1; } +static u32 n_left[24]; +static u16 bits_left[24]; +static void do_next_sample(u32 ch) +{ +loop: + if (n_left[ch] == 0) { + u32 addr = ((mem[0x3001 + 16*ch] & 0x3f) << 16) | mem[0x3000 + 16*ch]; + bits_left[ch] = mem[addr]; + if (bits_left[ch] == 0xffff) { + mem[0x3000 + 16*ch] = mem[0x3002 + 16*ch]; + mem[0x3001 + 16*ch] &= 0xffc0; + mem[0x3001 + 16*ch] |= (mem[0x3001 + 16*ch] >> 6) & 0x3f; + goto loop; + } + n_left[ch] = 2; + mem[0x3000 + 16*ch]++; + if (mem[0x3000 + 16*ch] == 0) + mem[0x3001 + 16*ch]++; // XXX: mask? +//printf("--> addr = %06x\n", addr); + } + + mem[0x300b + 16*ch] = bits_left[ch] << 8; + bits_left[ch] >>= 8; + n_left[ch]--; +} + #define FREQ 440 static u16 next_channel_sample(u32 ch) { // if (ch) // return 0x8000; - static u32 xxx[24] = {0}; - u16 sample = 0x8000 + (int)(20000*sin(2*M_PI*xxx[ch]*FREQ/281250)); - xxx[ch]++; - if (xxx[ch] == 281250) - xxx[ch] = 0; + +// static u32 xxx[24] = {0}; +// u16 sample = 0x8000 + (int)(20000*sin(2*M_PI*xxx[ch]*FREQ/281250)); +// xxx[ch]++; +// if (xxx[ch] == 281250) +// xxx[ch] = 0; +// return sample; + + u16 sample = mem[0x300b + 16*ch]; + u32 acc = (mem[0x3201 + 16*ch] << 16) | mem[0x3205 + 16*ch]; + u32 inc = (mem[0x3200 + 16*ch] << 16) | mem[0x3204 + 16*ch]; + acc += inc; + if (acc >= 0x80000) { + do_next_sample(ch); + acc -= 0x80000; + } + mem[0x3201 + 16*ch] = acc >> 16; + mem[0x3205 + 16*ch] = acc; + return sample; } |