Browse Source

Start music

merge-requests/1/head
Miloslav Číž 3 years ago
parent
commit
443adbe950
  1. 1
      assets/sfx_noise.raw
  2. 21
      platform_sdl.h
  3. 78
      sounds.h

1
assets/sfx_noise.raw

@ -0,0 +1 @@ @@ -0,0 +1 @@
yB㊨k頻fw嬌dkq葺。n刹掾p峻ッ<EFBFBD>拝zf|m蛙<cッ枠慾]b嘛gメー義賠》{酢^u`粗n~′赫i暫Zd郭嚼カ€學bゥ宜GWN孛g義]d、qZ弛ユcQH笥<EFBFBD>€馬イ秩foj」fkィ}mLfニゥッf<EFBFBD>血J慧|x、ti`e毆エKн<EFBFBD>|桷fス溶袈w脹:Nbエ`CゥhSk|争ィ箱<EFBFBD>n3杠|I燕Lsク貌ムmェv生izx@<EFBFBD>^芸セ晋ネxDサXvァkイz§n師㌃旨x凭」圄\[←u<EFBFBD>]]r勃R屏=pニyi{「Q梼}wvヲsK葡y决sZ~o峽嫺K<EFBFBD>ェ`]izチXlscシ<EFBFBD>}o{ッ凰ヤ’<EFBFBD>}<EFBFBD>フ\『co寃渚tOjv<EFBFBD><EFBFBD>reゥ劉K<EFBFBD>ィヲ琶「絞」fオ盃W<EFBFBD>鏑鑑伺ar〕{R{宵o<EFBFBD>``銃壮Q藁誠汾徑~ォマ訊<EFBFBD>>笈{コA{q套刹d腕ヲ}<EFBFBD>吏idncsRhD@ッp喊昧kuqgyィe_7v<EFBFBD>lpnkl<EFBFBD>椛ョ」V梛vゥ浦q<EFBFBD>yo?X<EFBFBD>Us€sbP{oaGィi`掵ヲ噤葬Nuz搆ォhO梱f;p{yーxb<EFBFBD>6t梨zxsz淑qz<EFBFBD><EFBFBD>「ァyコX矧ョ=knyЩmu<EFBFBD>チs+jvcShタeyュs埋奪}酢sjT剿nQ麿除Si怛idx揆ノ<EFBFBD>]bェU槽殷・釦撫<EFBFBD>tqkャ`s達yxf|Ttmzu∥k<EFBFBD>ы浙g}ャ}n_享<EFBFBD>&L<EFBFBD>ァrtェ<EFBFBD>r、aRエrノy祝2oyQZ」€クゥs<EFBFBD>┃p€頻x[V右\抖Bddj_}ooョgTカ身@}YNェqwゥ俳сf━5Ymm|u<EFBFBD>Y}㌻浪Lァ~叙q<EFBFBD>tkノawoj渓㍉jxo斬x寫エ<EFBFBD>}z。ニ恵m「・`嚆{p孫s€hp斌<EFBFBD>X刧~・帳撒Kゥ<EFBFBD>嗅劃`YRdN}芸l?W|ャ綰WΜnjRW背л「Zチx€万ァ圍h親噫~yl西ljqmク蛎ゥ着コlV<EFBFBD>團yg^~^`徃Eff穀c殕L鞄Syァw倉拵笠j}<EFBFBD>Yイyh甥、x柤^Z<EFBFBD>戎b_V岨n插促qシ学a^ハァ坊RィfC筈㎎<EFBFBD>~h錐crArzニlqg_徘団K瀕6V糎[Yq|ww図]e<瓶鋳ヲHIO軒峻ゥ歎ス活Zy-b{<EFBFBD><EFBFBD><EFBFBD>疹寔oトFqSgnm「}i尋zケサWR[_俵楔フ祷_ec8USM~s]bd撻I密Ff歔浙k楼Oュ織<EFBFBD>ォ鱒zE浚xTモe‘oGkーUeオ哭kR<EFBFBD>v⑦宙「[祷Id<EFBFBD>h妖<EFBFBD>ャy<EFBFBD>@鋒鯨。t€カ匝<EFBFBD>潟j`cjトn<EFBFBD>n存jyヶニynu]X讃xmp^昭ヲ准<EFBFBD>ネ島孛ャヤ散<EFBFBD>M<EFBFBD>Qn沛n<EFBFBD>Eu<EFBFBD>弾om、タッ<EFBFBD>ィウ矧捉Z<EFBFBD>ヲ8庶タマё|<EFBFBD><EFBFBD>bstァ|\rY~キ牌<EFBFBD>y<EFBFBD>0}㈲ィm<EFBFBD>抹メ捏用産Wbz<EFBFBD>Y:ue|ウ棡ィt[Tx<EFBFBD>殄P|v㎎~<EFBFBD><EFBFBD>]Xク。rk「、燦_エww吹~c屁貫盈ネ枠wZァ「<EFBFBD>ipiゞne詩}S<EFBFBD>Rw寒Ur復宕ie、葺┣hZe~yld=从a^槙キアt<EFBFBD>Xj抽ы酪ウv[n悒<EFBFBD>j洶。粋<EFBFBD>.yシ<EFBFBD>€]q孺qj味j<EFBFBD>T2剞棍姥jzv<EFBFBD><EFBFBD>yj逐婉|エC}ウ梼r]イ尢ェxィ視bvp<EFBFBD>等\<EFBFBD>{G<EFBFBD>v岑トレbwpイNuqォ労z<EFBFBD>轄㌦<EFBFBD>ィ尸オィY泪S<EFBFBD>チァe転[{剋~蓉聡IuEo}・ニ|€拍ウ<EFBFBD>ツ操」/kYnuち<EFBFBD><EFBFBD>ッ朧fz冪、-u吐」脹g。Ζ」嫖♂_<EFBFBD>=u:`W客~ア<EFBFBD>bs€ラィ、PG<EFBFBD>ォXキOX€V嗔杉jI・xuO容昆~sR^[a組S糊]bpy・vyカヤ怐ァ~ャィ孕i答<EFBFBD>ウ蒲j<EFBFBD>n罵oKb寥R|G掟lッO迅qヌ重~cU鰐憧|ォW€N`U<EFBFBD>?€<EFBFBD>Y執、オtヲォ^豫<EFBFBD>do嫉クフ検コWo~資衰「ォgキェpw℡続ぃ惣zw儷b「l。チ丶cmlcミ~~q~ァv~ツr吏<EFBFBD>W<EFBFBD>r洳T汞ayDe勦ッz・嗇~R」nuYc€=緒vf潟q・」<EFBFBD>{イエ輿€杜狽iwwスュ評<EFBFBD><EFBFBD>ぞv〟・ッonx途Yヲy媛ェ「]垣〕{D尢Ut㊤他qэ`l<EFBFBD>p<EFBFBD><EFBFBD>f拷Wmja<EFBFBD>}€ェ憶ュV越|悍敷トox|ャ<EFBFBD>€oub<EFBFBD>}S綱孱w蝕推jl営nsオ縛瑛タzyW€ClI錨m_ョ|p剥d鋭iーr恬「jo北荘](qツ<EFBFBD>Wアャ<EFBFBD>剪iho~Hx。_諜j負it<EFBFBD>Ia<EFBFBD>x者rwO∟oursn

21
platform_sdl.h

@ -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;
}

78
sounds.h

@ -30,6 +30,84 @@ @@ -30,6 +30,84 @@
(SFG_sounds[soundIndex][sampleIndex / 2] >> 4) : \
(SFG_sounds[soundIndex][sampleIndex / 2] & 0x0f))
#define SFG_TRACK_SAMPLES (512 * 1024)
struct
{ // all should be initialized to 0
uint8_t track;
uint32_t t;
uint32_t t2;
uint32_t n3t;
uint32_t n5t;
uint32_t n7t;
} SFG_MusicState;
uint8_t SFG_getNextMusicSample()
{
if (SFG_MusicState.t >= SFG_TRACK_SAMPLES)
{
SFG_MusicState.track++;
if (SFG_MusicState.track >= 3)
SFG_MusicState.track = 0;
SFG_MusicState.t = 0;
SFG_MusicState.t2 = 0;
SFG_MusicState.n3t = 0;
SFG_MusicState.n5t = 0;
SFG_MusicState.n7t = 0;
}
uint8_t result;
#define t SFG_MusicState.t
#define t2 SFG_MusicState.t2
#define n3t SFG_MusicState.n3t
switch (SFG_MusicState.track)
{
case 0:
{
uint32_t a = ((t >> 7) | (t >> 9) | (~t << 1) | t);
result = ((t) & 65536 ? (a & (((t * t) >> 16) & 0x09)) : ~a);
break;
}
case 1:
{
result = (t & (3 << (((t >> 10) ^ ((t >> 10) << (t >> 6))))));
break;
}
case 2:
{
result =
((((t >> (t >> 2)) + (t >> (t >> 7)))) & 0x3f | (t >> 5) | (t >> 11))
& (t & (32768 | 8192) ? 0xf0 : 0x30);
break;
}
default:
result = 127;
break;
}
#undef t
#undef t2
#undef n3t
SFG_MusicState.t += 1;
SFG_MusicState.t2 += SFG_MusicState.t;
SFG_MusicState.n3t += 3;
SFG_MusicState.n5t += 5;
SFG_MusicState.n7t += 7;
return result;
}
SFG_PROGRAM_MEMORY uint8_t SFG_sounds[][SFG_SFX_SIZE] =
{
{ // 0, bullet shot

Loading…
Cancel
Save