mirror of
https://gitlab.com/drummyfish/anarch.git
synced 2024-11-21 16:35:08 -05:00
Continue music
This commit is contained in:
parent
2a58188ee0
commit
22b18f1d90
@ -179,13 +179,9 @@ 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)
|
||||
static inline uint8_t mixSamples(uint8_t sample1, uint8_t sample2)
|
||||
{
|
||||
int16_t mixed = sample1;
|
||||
mixed -= 127;
|
||||
mixed += sample2;
|
||||
mixed = (mixed > 0) ? ((mixed < 255) ? mixed : 255) : 0;
|
||||
return mixed;
|
||||
return (((uint16_t) sample1) + ((uint16_t) sample2)) / 2;
|
||||
}
|
||||
|
||||
uint8_t musicOn = 1;
|
||||
@ -195,7 +191,7 @@ void audioFillCallback(void *userdata, uint8_t *s, int l)
|
||||
for (int i = 0; i < l; ++i)
|
||||
{
|
||||
s[i] = musicOn ?
|
||||
addSamples(audioBuff[audioPos],SFG_getNextMusicSample()) :
|
||||
mixSamples(audioBuff[audioPos],SFG_getNextMusicSample() / 2) :
|
||||
audioBuff[audioPos];
|
||||
|
||||
audioBuff[audioPos] = 127;
|
||||
@ -217,7 +213,7 @@ void SFG_playSound(uint8_t soundIndex, uint8_t volume)
|
||||
for (int i = 0; i < SFG_SFX_SAMPLE_COUNT; ++i)
|
||||
{
|
||||
audioBuff[pos] =
|
||||
addSamples(audioBuff[pos],SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep);
|
||||
mixSamples(audioBuff[pos],SFG_GET_SFX_SAMPLE(soundIndex,i) * volumeStep);
|
||||
|
||||
pos = (pos < SFG_SFX_SAMPLE_COUNT - 1) ? (pos + 1) : 0;
|
||||
}
|
||||
|
34
sounds.h
34
sounds.h
@ -37,13 +37,10 @@
|
||||
|
||||
struct
|
||||
{ // all should be initialized to 0
|
||||
// TODO: leave only those needed here
|
||||
uint8_t track;
|
||||
uint32_t t;
|
||||
uint32_t t2;
|
||||
uint32_t n3t;
|
||||
uint32_t n5t;
|
||||
uint32_t n7t;
|
||||
uint32_t n11t;
|
||||
} SFG_MusicState;
|
||||
|
||||
/**
|
||||
@ -56,28 +53,28 @@ uint8_t SFG_getNextMusicSample()
|
||||
{
|
||||
SFG_MusicState.track++;
|
||||
|
||||
if (SFG_MusicState.track >= 4)
|
||||
if (SFG_MusicState.track >= 5)
|
||||
SFG_MusicState.track = 0;
|
||||
|
||||
SFG_MusicState.t = 0;
|
||||
SFG_MusicState.t2 = 0;
|
||||
SFG_MusicState.n3t = 0;
|
||||
SFG_MusicState.n5t = 0;
|
||||
SFG_MusicState.n7t = 0;
|
||||
SFG_MusicState.n11t = 0;
|
||||
}
|
||||
|
||||
uint8_t result;
|
||||
|
||||
#define t SFG_MusicState.t
|
||||
#define t2 SFG_MusicState.t2
|
||||
#define n3t SFG_MusicState.n3t
|
||||
#define n11t SFG_MusicState.n11t
|
||||
|
||||
switch (SFG_MusicState.track) // individual music tracks
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
uint32_t a = ((t >> 7) | (t >> 9) | (~t << 1) | t);
|
||||
result = ((t) & 65536 ? (a & (((t * t) >> 16) & 0x09)) : ~a);
|
||||
result = ((t) & 65536 ? (a & (((t2) >> 16) & 0x09)) : ~a);
|
||||
|
||||
t2 += t;
|
||||
|
||||
break;
|
||||
}
|
||||
@ -105,6 +102,17 @@ uint8_t SFG_getNextMusicSample()
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
result =
|
||||
((0x47 >> (t >> 9)) & (t >> t)) | (0x57 >> (t >> 7)) |
|
||||
(0x06 >> (t >> (((n11t) >> 14) & 0x0e)));
|
||||
|
||||
n11t += 11;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
result = 127;
|
||||
break;
|
||||
@ -112,13 +120,9 @@ uint8_t SFG_getNextMusicSample()
|
||||
|
||||
#undef t
|
||||
#undef t2
|
||||
#undef n3t
|
||||
#undef n11t
|
||||
|
||||
SFG_MusicState.t += 1;
|
||||
SFG_MusicState.t2 += SFG_MusicState.t;
|
||||
SFG_MusicState.n3t += 3;
|
||||
SFG_MusicState.n5t += 5;
|
||||
SFG_MusicState.n7t += 7;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user