Start audio channel 3

This commit is contained in:
Jeffrey Pfau 2013-10-19 03:04:45 -07:00
parent cfb0115c0e
commit cc8eeb4353
2 changed files with 56 additions and 5 deletions

View File

@ -33,6 +33,8 @@ void GBAAudioInit(struct GBAAudio* audio) {
audio->ch2.envelope.nextStep = INT_MAX;
audio->ch2.control.nextStep = 0;
audio->ch2.sample = 0;
audio->ch3.bank.packed = 0;
audio->ch3.sample = 0;
audio->ch4.sample = 0;
audio->ch4.envelope.nextStep = INT_MAX;
audio->eventDiff = 0;
@ -281,7 +283,7 @@ void GBAAudioWriteSOUNDCNT_X(struct GBAAudio* audio, uint16_t value) {
}
void GBAAudioWriteWaveRAM(struct GBAAudio* audio, int address, uint32_t value) {
GBALog(audio->p, GBA_LOG_STUB, "Audio unimplemented");
audio->ch3.wavedata[address | (!audio->ch3.bank.bank * 4)] = value;
}
void GBAAudioWriteFIFO(struct GBAAudio* audio, int address, uint32_t value) {
@ -390,7 +392,47 @@ static int32_t _updateChannel2(struct GBAAudioChannel2* ch) {
}
static int32_t _updateChannel3(struct GBAAudioChannel3* ch) {
return INT_MAX / 4;
int i;
int start;
int end;
int volume;
switch (ch->wave.volume) {
case 0:
volume = 0;
break;
case 1:
volume = 4;
break;
case 2:
volume = 2;
break;
case 3:
volume = 1;
break;
default:
volume = 3;
break;
}
if (ch->bank.size) {
start = 7;
end = 0;
} else if (ch->bank.bank) {
start = 7;
end = 4;
} else {
start = 3;
end = 0;
}
uint32_t bitsCarry = ch->wavedata[end] & 0xF0000000;
uint32_t bits;
for (i = start; i >= end; --i) {
bits = ch->wavedata[i] & 0xF0000000;
ch->wavedata[i] <<= 4;
ch->wavedata[i] |= bitsCarry >> 28;
bitsCarry = bits;
}
ch->sample = ((bitsCarry >> 26) - 0x20) * volume;
return 16 * (2048 - ch->control.rate);
}
static int32_t _updateChannel4(struct GBAAudioChannel4* ch) {
@ -426,6 +468,14 @@ static void _sample(struct GBAAudio* audio) {
sampleRight += audio->ch2.sample >> psgShift;
}
if (audio->ch3Left) {
sampleLeft += audio->ch3.sample >> psgShift;
}
if (audio->ch3Right) {
sampleRight += audio->ch3.sample >> psgShift;
}
if (audio->ch4Left) {
sampleLeft += audio->ch4.sample >> psgShift;
}

View File

@ -69,7 +69,7 @@ struct GBAAudioChannel3 {
unsigned : 5;
unsigned size : 1;
unsigned bank : 1;
unsigned disable : 1;
unsigned enable : 1;
unsigned : 7;
};
uint16_t packed;
@ -80,8 +80,6 @@ struct GBAAudioChannel3 {
unsigned length : 8;
unsigned : 5;
unsigned volume : 3;
unsigned disable : 1;
unsigned : 7;
};
uint16_t packed;
} wave;
@ -95,6 +93,9 @@ struct GBAAudioChannel3 {
};
uint16_t packed;
} control;
uint32_t wavedata[8];
int8_t sample;
};
struct GBAAudioChannel4 {