Rename GBAAudioWave to GBAAudioEnvelope, add fields for internal state
Jeffrey Pfau jeffrey@endrift.com
Fri, 18 Oct 2013 08:10:10 -0700
2 files changed,
20 insertions(+),
14 deletions(-)
M
src/gba/gba-audio.c
→
src/gba/gba-audio.c
@@ -25,6 +25,8 @@ audio->ch4.sample = 0;
audio->eventDiff = 0; audio->nextSample = 0; audio->sampleRate = 0x8000; + audio->soundcntLo = 0; + audio->soundcntHi = 0; audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate; CircleBufferInit(&audio->left, GBA_AUDIO_SAMPLES * sizeof(int32_t));@@ -107,7 +109,7 @@ audio->ch1.sweep.packed = 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) {@@ -115,7 +117,7 @@ audio->ch1.control.packed = 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) {@@ -135,7 +137,7 @@ audio->ch3.control.packed = 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) {
M
src/gba/gba-audio.h
→
src/gba/gba-audio.h
@@ -10,15 +10,19 @@ struct GBADMA;
const unsigned GBA_AUDIO_SAMPLES; -union GBAAudioWave { - struct { - unsigned length : 6; - unsigned duty : 2; - unsigned stepTime : 3; - unsigned direction : 1; - unsigned initialVolume : 4; +struct GBAAudioEnvelope { + union { + struct { + unsigned length : 6; + unsigned duty : 2; + unsigned stepTime : 3; + unsigned direction : 1; + unsigned initialVolume : 4; + }; + uint16_t packed; }; - uint16_t packed; + int currentVolume; + int32_t nextStep; }; union GBAAudioSquareControl {@@ -42,12 +46,12 @@ };
uint16_t packed; } sweep; - union GBAAudioWave wave; + struct GBAAudioEnvelope envelope; union GBAAudioSquareControl control; }; struct GBAAudioChannel2 { - union GBAAudioWave wave; + struct GBAAudioEnvelope envelope; union GBAAudioSquareControl control; };@@ -86,7 +90,7 @@ } control;
}; struct GBAAudioChannel4 { - union GBAAudioWave wave; + struct GBAAudioEnvelope envelope; union { struct { unsigned ratio : 3;