Rename GBAAudioWave to GBAAudioEnvelope, add fields for internal state

This commit is contained in:
Jeffrey Pfau 2013-10-18 08:10:10 -07:00
parent 7393351e27
commit d99bf7fdff
2 changed files with 20 additions and 14 deletions

View File

@ -25,6 +25,8 @@ void GBAAudioInit(struct GBAAudio* audio) {
audio->eventDiff = 0; audio->eventDiff = 0;
audio->nextSample = 0; audio->nextSample = 0;
audio->sampleRate = 0x8000; audio->sampleRate = 0x8000;
audio->soundcntLo = 0;
audio->soundcntHi = 0;
audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate; audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate;
CircleBufferInit(&audio->left, GBA_AUDIO_SAMPLES * sizeof(int32_t)); CircleBufferInit(&audio->left, GBA_AUDIO_SAMPLES * sizeof(int32_t));
@ -107,7 +109,7 @@ void GBAAudioWriteSOUND1CNT_LO(struct GBAAudio* audio, uint16_t value) {
} }
void GBAAudioWriteSOUND1CNT_HI(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUND1CNT_HI(struct GBAAudio* audio, uint16_t value) {
audio->ch1.wave.packed = value; audio->ch1.envelope.packed = value;
} }
void GBAAudioWriteSOUND1CNT_X(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUND1CNT_X(struct GBAAudio* audio, uint16_t value) {
@ -115,7 +117,7 @@ void GBAAudioWriteSOUND1CNT_X(struct GBAAudio* audio, uint16_t value) {
} }
void GBAAudioWriteSOUND2CNT_LO(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUND2CNT_LO(struct GBAAudio* audio, uint16_t value) {
audio->ch2.wave.packed = value; audio->ch2.envelope.packed = value;
} }
void GBAAudioWriteSOUND2CNT_HI(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUND2CNT_HI(struct GBAAudio* audio, uint16_t value) {
@ -135,7 +137,7 @@ void GBAAudioWriteSOUND3CNT_X(struct GBAAudio* audio, uint16_t value) {
} }
void GBAAudioWriteSOUND4CNT_LO(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUND4CNT_LO(struct GBAAudio* audio, uint16_t value) {
audio->ch4.wave.packed = value; audio->ch4.envelope.packed = value;
} }
void GBAAudioWriteSOUND4CNT_HI(struct GBAAudio* audio, uint16_t value) { void GBAAudioWriteSOUND4CNT_HI(struct GBAAudio* audio, uint16_t value) {

View File

@ -10,7 +10,8 @@ struct GBADMA;
const unsigned GBA_AUDIO_SAMPLES; const unsigned GBA_AUDIO_SAMPLES;
union GBAAudioWave { struct GBAAudioEnvelope {
union {
struct { struct {
unsigned length : 6; unsigned length : 6;
unsigned duty : 2; unsigned duty : 2;
@ -20,6 +21,9 @@ union GBAAudioWave {
}; };
uint16_t packed; uint16_t packed;
}; };
int currentVolume;
int32_t nextStep;
};
union GBAAudioSquareControl { union GBAAudioSquareControl {
struct { struct {
@ -42,12 +46,12 @@ struct GBAAudioChannel1 {
uint16_t packed; uint16_t packed;
} sweep; } sweep;
union GBAAudioWave wave; struct GBAAudioEnvelope envelope;
union GBAAudioSquareControl control; union GBAAudioSquareControl control;
}; };
struct GBAAudioChannel2 { struct GBAAudioChannel2 {
union GBAAudioWave wave; struct GBAAudioEnvelope envelope;
union GBAAudioSquareControl control; union GBAAudioSquareControl control;
}; };
@ -86,7 +90,7 @@ struct GBAAudioChannel3 {
}; };
struct GBAAudioChannel4 { struct GBAAudioChannel4 {
union GBAAudioWave wave; struct GBAAudioEnvelope envelope;
union { union {
struct { struct {
unsigned ratio : 3; unsigned ratio : 3;