|
|
|
@ -179,14 +179,21 @@ void emscripten_set_main_loop(em_callback_func func, int fps, int simulate_infin
@@ -179,14 +179,21 @@ void emscripten_set_main_loop(em_callback_func func, int fps, int simulate_infin
|
|
|
|
|
uint8_t audioBuff[SFG_SFX_SAMPLE_COUNT]; |
|
|
|
|
uint16_t audioPos = 0; |
|
|
|
|
|
|
|
|
|
static inline uint8_t addSamples(uint8_t sample1, uint8_t sample2) |
|
|
|
|
{ |
|
|
|
|
int16_t mixed = sample1; |
|
|
|
|
mixed -= 127; |
|
|
|
|
mixed += sample2; |
|
|
|
|
mixed = (mixed > 0) ? ((mixed < 255) ? mixed : 255) : 0; |
|
|
|
|
return mixed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void audioFillCallback(void *userdata, uint8_t *s, int l) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < l; ++i) |
|
|
|
|
{ |
|
|
|
|
s[i] = audioBuff[audioPos]; |
|
|
|
|
|
|
|
|
|
s[i] = addSamples(audioBuff[audioPos],SFG_getNextMusicSample()); |
|
|
|
|
audioBuff[audioPos] = 127; |
|
|
|
|
|
|
|
|
|
audioPos = (audioPos < SFG_SFX_SAMPLE_COUNT - 1) ? (audioPos + 1) : 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -199,12 +206,8 @@ void SFG_playSound(uint8_t soundIndex, uint8_t volume)
@@ -199,12 +206,8 @@ void SFG_playSound(uint8_t soundIndex, uint8_t volume)
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i) |
|
|
|
|
{ |
|
|
|
|
int16_t mixedValue = |
|
|
|
|
audioBuff[pos] - 127 + SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep; |
|
|
|
|
|
|
|
|
|
mixedValue = (mixedValue > 0) ? ((mixedValue < 255) ? mixedValue : 255) : 0; |
|
|
|
|
|
|
|
|
|
audioBuff[pos] = mixedValue;
|
|
|
|
|
audioBuff[pos] = |
|
|
|
|
addSamples(audioBuff[pos],SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep); |
|
|
|
|
|
|
|
|
|
pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0; |
|
|
|
|
} |
|
|
|
|