mirror of https://github.com/mgba-emu/mgba.git
Start filling in audio framework
This commit is contained in:
parent
ea41ef7ae6
commit
eac9dfb325
|
@ -4,13 +4,23 @@
|
|||
#include "gba-io.h"
|
||||
#include "gba-thread.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
const unsigned GBA_AUDIO_SAMPLES = 512;
|
||||
const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);
|
||||
|
||||
static int32_t _updateChannel1(struct GBAAudioChannel1* ch);
|
||||
static int32_t _updateChannel2(struct GBAAudioChannel2* ch);
|
||||
static int32_t _updateChannel3(struct GBAAudioChannel3* ch);
|
||||
static int32_t _updateChannel4(struct GBAAudioChannel4* ch);
|
||||
static void _sample(struct GBAAudio* audio);
|
||||
|
||||
void GBAAudioInit(struct GBAAudio* audio) {
|
||||
audio->nextEvent = 0;
|
||||
audio->nextCh1 = 0;
|
||||
audio->nextCh2 = 0;
|
||||
audio->nextCh3 = 0;
|
||||
audio->nextCh4 = 0;
|
||||
audio->eventDiff = 0;
|
||||
audio->nextSample = 0;
|
||||
audio->sampleRate = 0x8000;
|
||||
|
@ -36,6 +46,27 @@ void GBAAudioDeinit(struct GBAAudio* audio) {
|
|||
int32_t GBAAudioProcessEvents(struct GBAAudio* audio, int32_t cycles) {
|
||||
audio->nextEvent -= cycles;
|
||||
if (audio->nextEvent <= 0) {
|
||||
audio->nextCh1 -= audio->eventDiff;
|
||||
audio->nextCh2 -= audio->eventDiff;
|
||||
audio->nextCh3 -= audio->eventDiff;
|
||||
audio->nextCh4 -= audio->eventDiff;
|
||||
|
||||
if ((audio->ch1Right || audio->ch1Left) && audio->nextCh1 <= 0) {
|
||||
audio->nextCh1 += _updateChannel1(&audio->ch1);
|
||||
}
|
||||
|
||||
if ((audio->ch2Right || audio->ch2Left) && audio->nextCh2 <= 0) {
|
||||
audio->nextCh2 += _updateChannel2(&audio->ch2);
|
||||
}
|
||||
|
||||
if ((audio->ch3Right || audio->ch3Left) && audio->nextCh3 <= 0) {
|
||||
audio->nextCh3 += _updateChannel3(&audio->ch3);
|
||||
}
|
||||
|
||||
if ((audio->ch4Right || audio->ch4Left) && audio->nextCh4 <= 0) {
|
||||
audio->nextCh4 += _updateChannel4(&audio->ch4);
|
||||
}
|
||||
|
||||
audio->nextSample -= audio->eventDiff;
|
||||
if (audio->nextSample <= 0) {
|
||||
_sample(audio);
|
||||
|
@ -156,6 +187,22 @@ void GBAAudioSampleFIFO(struct GBAAudio* audio, int fifoId) {
|
|||
CircleBufferRead8(&channel->fifo, &channel->sample);
|
||||
}
|
||||
|
||||
static int32_t _updateChannel1(struct GBAAudioChannel1* ch) {
|
||||
return INT_MAX / 4;
|
||||
}
|
||||
|
||||
static int32_t _updateChannel2(struct GBAAudioChannel2* ch) {
|
||||
return INT_MAX / 4;
|
||||
}
|
||||
|
||||
static int32_t _updateChannel3(struct GBAAudioChannel3* ch) {
|
||||
return INT_MAX / 4;
|
||||
}
|
||||
|
||||
static int32_t _updateChannel4(struct GBAAudioChannel4* ch) {
|
||||
return INT_MAX / 4;
|
||||
}
|
||||
|
||||
static void _sample(struct GBAAudio* audio) {
|
||||
int32_t sampleLeft = 0;
|
||||
int32_t sampleRight = 0;
|
||||
|
|
|
@ -173,6 +173,10 @@ struct GBAAudio {
|
|||
|
||||
int32_t nextEvent;
|
||||
int32_t eventDiff;
|
||||
int32_t nextCh1;
|
||||
int32_t nextCh2;
|
||||
int32_t nextCh3;
|
||||
int32_t nextCh4;
|
||||
int32_t nextSample;
|
||||
|
||||
int32_t sampleInterval;
|
||||
|
|
|
@ -22,33 +22,43 @@ void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) {
|
|||
// Audio
|
||||
case REG_SOUND1CNT_LO:
|
||||
GBAAudioWriteSOUND1CNT_LO(&gba->audio, value);
|
||||
value &= 0x00FF;
|
||||
break;
|
||||
case REG_SOUND1CNT_HI:
|
||||
GBAAudioWriteSOUND1CNT_HI(&gba->audio, value);
|
||||
value &= 0xFFC0;
|
||||
break;
|
||||
case REG_SOUND1CNT_X:
|
||||
GBAAudioWriteSOUND1CNT_X(&gba->audio, value);
|
||||
value &= 0x4000;
|
||||
break;
|
||||
case REG_SOUND2CNT_LO:
|
||||
GBAAudioWriteSOUND2CNT_LO(&gba->audio, value);
|
||||
value &= 0xFFC0;
|
||||
break;
|
||||
case REG_SOUND2CNT_HI:
|
||||
GBAAudioWriteSOUND2CNT_HI(&gba->audio, value);
|
||||
value &= 0x4000;
|
||||
break;
|
||||
case REG_SOUND3CNT_LO:
|
||||
GBAAudioWriteSOUND3CNT_LO(&gba->audio, value);
|
||||
value &= 0x00E0;
|
||||
break;
|
||||
case REG_SOUND3CNT_HI:
|
||||
GBAAudioWriteSOUND3CNT_HI(&gba->audio, value);
|
||||
value &= 0xE000;
|
||||
break;
|
||||
case REG_SOUND3CNT_X:
|
||||
GBAAudioWriteSOUND3CNT_X(&gba->audio, value);
|
||||
value &= 0x4000;
|
||||
break;
|
||||
case REG_SOUND4CNT_LO:
|
||||
GBAAudioWriteSOUND4CNT_LO(&gba->audio, value);
|
||||
value &= 0xFF00;
|
||||
break;
|
||||
case REG_SOUND4CNT_HI:
|
||||
GBAAudioWriteSOUND4CNT_HI(&gba->audio, value);
|
||||
value &= 0x40FF;
|
||||
break;
|
||||
case REG_SOUNDCNT_LO:
|
||||
GBAAudioWriteSOUNDCNT_LO(&gba->audio, value);
|
||||
|
@ -284,6 +294,16 @@ uint16_t GBAIORead(struct GBA* gba, uint32_t address) {
|
|||
case REG_BG1CNT:
|
||||
case REG_BG2CNT:
|
||||
case REG_BG3CNT:
|
||||
case REG_SOUND1CNT_LO:
|
||||
case REG_SOUND1CNT_HI:
|
||||
case REG_SOUND1CNT_X:
|
||||
case REG_SOUND2CNT_LO:
|
||||
case REG_SOUND2CNT_HI:
|
||||
case REG_SOUND3CNT_LO:
|
||||
case REG_SOUND3CNT_HI:
|
||||
case REG_SOUND3CNT_X:
|
||||
case REG_SOUND4CNT_LO:
|
||||
case REG_SOUND4CNT_HI:
|
||||
case REG_DMA0CNT_HI:
|
||||
case REG_DMA1CNT_HI:
|
||||
case REG_DMA2CNT_HI:
|
||||
|
|
Loading…
Reference in New Issue