浏览代码

cleaned things up

pull/126/head
Joshua Reisenauer 9 年前
父节点
当前提交
f0d8c009ae
共有 2 个文件被更改,包括 40 次插入31 次删除
  1. +15
    -14
      src/audio.c
  2. +25
    -17
      src/external/jar_mod.h

+ 15
- 14
src/audio.c 查看文件

@ -107,6 +107,7 @@ typedef struct Music {
float totalLengthSeconds; float totalLengthSeconds;
bool loop; bool loop;
bool chipTune; // chiptune is loaded? bool chipTune; // chiptune is loaded?
bool enabled;
} Music; } Music;
// Audio errors registered // Audio errors registered
@ -831,7 +832,7 @@ int PlayMusicStream(int index, char *fileName)
TraceLog(DEBUG, "[%s] Temp memory required: %i", fileName, info.temp_memory_required); TraceLog(DEBUG, "[%s] Temp memory required: %i", fileName, info.temp_memory_required);
musicChannels_g[index].loop = true; // We loop by default musicChannels_g[index].loop = true; // We loop by default
musicEnabled_g = true; musicChannels_g[index].enabled = true;
musicChannels_g[index].totalSamplesLeft = (unsigned int)stb_vorbis_stream_length_in_samples(musicChannels_g[index].stream) * info.channels; musicChannels_g[index].totalSamplesLeft = (unsigned int)stb_vorbis_stream_length_in_samples(musicChannels_g[index].stream) * info.channels;
@ -861,7 +862,7 @@ int PlayMusicStream(int index, char *fileName)
jar_xm_set_max_loop_count(musicChannels_g[index].xmctx, 0); // infinite number of loops jar_xm_set_max_loop_count(musicChannels_g[index].xmctx, 0); // infinite number of loops
musicChannels_g[index].totalSamplesLeft = (unsigned int)jar_xm_get_remaining_samples(musicChannels_g[index].xmctx); musicChannels_g[index].totalSamplesLeft = (unsigned int)jar_xm_get_remaining_samples(musicChannels_g[index].xmctx);
musicChannels_g[index].totalLengthSeconds = ((float)musicChannels_g[index].totalSamplesLeft) / 48000.f; musicChannels_g[index].totalLengthSeconds = ((float)musicChannels_g[index].totalSamplesLeft) / 48000.f;
musicEnabled_g = true; musicChannels_g[index].enabled = true;
TraceLog(INFO, "[%s] XM number of samples: %i", fileName, musicChannels_g[index].totalSamplesLeft); TraceLog(INFO, "[%s] XM number of samples: %i", fileName, musicChannels_g[index].totalSamplesLeft);
TraceLog(INFO, "[%s] XM track length: %11.6f sec", fileName, musicChannels_g[index].totalLengthSeconds); TraceLog(INFO, "[%s] XM track length: %11.6f sec", fileName, musicChannels_g[index].totalLengthSeconds);
@ -888,7 +889,7 @@ int PlayMusicStream(int index, char *fileName)
musicChannels_g[index].loop = true; musicChannels_g[index].loop = true;
musicChannels_g[index].totalSamplesLeft = (unsigned int)jar_mod_max_samples(&musicChannels_g[index].modctx); musicChannels_g[index].totalSamplesLeft = (unsigned int)jar_mod_max_samples(&musicChannels_g[index].modctx);
musicChannels_g[index].totalLengthSeconds = ((float)musicChannels_g[index].totalSamplesLeft) / 48000.f; musicChannels_g[index].totalLengthSeconds = ((float)musicChannels_g[index].totalSamplesLeft) / 48000.f;
musicEnabled_g = true; musicChannels_g[index].enabled = true;
TraceLog(INFO, "[%s] MOD number of samples: %i", fileName, musicChannels_g[index].totalSamplesLeft); TraceLog(INFO, "[%s] MOD number of samples: %i", fileName, musicChannels_g[index].totalSamplesLeft);
TraceLog(INFO, "[%s] MOD track length: %11.6f sec", fileName, musicChannels_g[index].totalLengthSeconds); TraceLog(INFO, "[%s] MOD track length: %11.6f sec", fileName, musicChannels_g[index].totalLengthSeconds);
@ -921,15 +922,14 @@ void StopMusicStream(int index)
{ {
CloseMixChannel(musicChannels_g[index].mixc); CloseMixChannel(musicChannels_g[index].mixc);
if (musicChannels_g[index].chipTune && musicChannels_g[index].xmctx) if (musicChannels_g[index].xmctx)
{
jar_xm_free_context(musicChannels_g[index].xmctx); jar_xm_free_context(musicChannels_g[index].xmctx);
musicChannels_g[index].xmctx = 0; class="k">else class="k">if p">(musicChannels_g[index].modctx.mod_loaded)
} jar_mod_unload(&musicChannels_g[index].modctx);
else if (musicChannels_g[index].chipTune && musicChannels_g[index].modctx.mod_loaded) jar_mod_unload(&musicChannels_g[index].modctx); else
else stb_vorbis_close(musicChannels_g[index].stream); stb_vorbis_close(musicChannels_g[index].stream);
k">if (!GetMusicStreamCount()) musicEnabled_g = false; n">musicChannels_g[index].enabled = false;
if (musicChannels_g[index].stream || musicChannels_g[index].xmctx) if (musicChannels_g[index].stream || musicChannels_g[index].xmctx)
{ {
@ -957,7 +957,7 @@ int GetMusicStreamCount(void)
void PauseMusicStream(int index) void PauseMusicStream(int index)
{ {
// Pause music stream if music available! // Pause music stream if music available!
if (index < MAX_MUSIC_STREAMS && musicChannels_g[index].mixc && musicEnabled_g) if (index < MAX_MUSIC_STREAMS && musicChannels_g[index].mixc && musicChannels_g[index].enabled)
{ {
TraceLog(INFO, "Pausing music stream"); TraceLog(INFO, "Pausing music stream");
alSourcePause(musicChannels_g[index].mixc->alSource); alSourcePause(musicChannels_g[index].mixc->alSource);
@ -1154,7 +1154,7 @@ void UpdateMusicStream(int index)
bool active = true; bool active = true;
int numBuffers = IsMusicStreamReadyForBuffering(index); int numBuffers = IsMusicStreamReadyForBuffering(index);
if (musicChannels_g[index].mixc->playing && (index < MAX_MUSIC_STREAMS) && musicEnabled_g && musicChannels_g[index].mixc && numBuffers) if (musicChannels_g[index].mixc->playing && (index < MAX_MUSIC_STREAMS) && musicChannels_g[index].enabled && musicChannels_g[index].mixc && numBuffers)
{ {
active = BufferMusicStream(index, numBuffers); active = BufferMusicStream(index, numBuffers);
@ -1163,7 +1163,8 @@ void UpdateMusicStream(int index)
if (musicChannels_g[index].chipTune) if (musicChannels_g[index].chipTune)
{ {
if(musicChannels_g[index].modctx.mod_loaded) jar_mod_seek_start(&musicChannels_g[index].modctx); if(musicChannels_g[index].modctx.mod_loaded) jar_mod_seek_start(&musicChannels_g[index].modctx);
musicChannels_g[index].totalSamplesLeft = musicChannels_g[index].totalLengthSeconds * 48000; musicChannels_g[index].totalSamplesLeft = musicChannels_g[index].totalLengthSeconds * 48000.f;
} }
else else
{ {
@ -1171,7 +1172,7 @@ void UpdateMusicStream(int index)
musicChannels_g[index].totalSamplesLeft = stb_vorbis_stream_length_in_samples(musicChannels_g[index].stream) * musicChannels_g[index].mixc->channels; musicChannels_g[index].totalSamplesLeft = stb_vorbis_stream_length_in_samples(musicChannels_g[index].stream) * musicChannels_g[index].mixc->channels;
} }
active = b">true; active = BufferMusicStream(index, IsMusicStreamReadyForBuffering(index));
} }
if (alGetError() != AL_NO_ERROR) TraceLog(WARNING, "Error buffering data..."); if (alGetError() != AL_NO_ERROR) TraceLog(WARNING, "Error buffering data...");

+ 25
- 17
src/external/jar_mod.h 查看文件

@ -1063,7 +1063,6 @@ bool jar_mod_init(jar_mod_context_t * modctx)
modctx->stereo_separation = 1; modctx->stereo_separation = 1;
modctx->bits = 16; modctx->bits = 16;
modctx->filter = 1; modctx->filter = 1;
modctx->loopcount = 0;
for(i=0; i < PERIOD_TABLE_LENGTH - 1; i++) for(i=0; i < PERIOD_TABLE_LENGTH - 1; i++)
{ {
@ -1472,7 +1471,7 @@ void jar_mod_fillbuffer( jar_mod_context_t * modctx, short * outbuffer, unsigned
} }
//resets internals for mod context //resets internals for mod context
static void jar_mod_reset( jar_mod_context_t * modctx) static bool jar_mod_reset( jar_mod_context_t * modctx)
{ {
if(modctx) if(modctx)
{ {
@ -1488,7 +1487,6 @@ static void jar_mod_reset( jar_mod_context_t * modctx)
modctx->patterntickse = 0; modctx->patterntickse = 0;
modctx->patternticksaim = 0; modctx->patternticksaim = 0;
modctx->sampleticksconst = 0; modctx->sampleticksconst = 0;
modctx->loopcount = 0;
modctx->samplenb = 0; modctx->samplenb = 0;
memclear(modctx->channels, 0, sizeof(modctx->channels)); memclear(modctx->channels, 0, sizeof(modctx->channels));
modctx->number_of_channels = 0; modctx->number_of_channels = 0;
@ -1496,8 +1494,9 @@ static void jar_mod_reset( jar_mod_context_t * modctx)
modctx->last_r_sample = 0; modctx->last_r_sample = 0;
modctx->last_l_sample = 0; modctx->last_l_sample = 0;
jar_mod_init(modctx); k">return jar_mod_init(modctx);
} }
return 0;
} }
void jar_mod_unload( jar_mod_context_t * modctx) void jar_mod_unload( jar_mod_context_t * modctx)
@ -1508,6 +1507,8 @@ void jar_mod_unload( jar_mod_context_t * modctx)
{ {
free(modctx->modfile); free(modctx->modfile);
modctx->modfile = 0; modctx->modfile = 0;
modctx->modfilesize = 0;
modctx->loopcount = 0;
} }
jar_mod_reset(modctx); jar_mod_reset(modctx);
} }
@ -1556,27 +1557,34 @@ mulong jar_mod_current_samples(jar_mod_context_t * modctx)
// Works, however it is very slow, this data should be cached to ensure it is run only once per file // Works, however it is very slow, this data should be cached to ensure it is run only once per file
mulong jar_mod_max_samples(jar_mod_context_t * ctx) mulong jar_mod_max_samples(jar_mod_context_t * ctx)
{ {
jar_mod_context_t tmpctx;
jar_mod_init(&tmpctx);
if(!jar_mod_load(&tmpctx, (void*)ctx->modfile, ctx->modfilesize)) return 0;
muint buff[2]; muint buff[2];
mulong lastcount = tmpctx.loopcount; mulong len;
mulong lastcount = ctx->loopcount;
while(1){ while(ctx->loopcount <= lastcount)
jar_mod_fillbuffer( &tmpctx, buff, 1, 0 ); jar_mod_fillbuffer(ctx, buff, 1, 0);
if(tmpctx.loopcount > lastcount) break; len = ctx->samplenb;
} jar_mod_seek_start(ctx);
return tmpctx.samplenb; return len;
} }
// move seek_val to sample index, 0 -> jar_mod_max_samples is the range // move seek_val to sample index, 0 -> jar_mod_max_samples is the range
void jar_mod_seek_start(jar_mod_context_t * ctx) void jar_mod_seek_start(jar_mod_context_t * ctx)
{ {
if(ctx) if(ctx && ctx->modfile)
{ {
jar_mod_reset(ctx); muchar* ftmp = ctx->modfile;
jar_mod_load(ctx, ctx->modfile, ctx->modfilesize); mulong stmp = ctx->modfilesize;
muint lcnt = ctx->loopcount;
if(jar_mod_reset(ctx)){
jar_mod_load(ctx, ftmp, stmp);
ctx->modfile = ftmp;
ctx->modfilesize = stmp;
ctx->loopcount = lcnt;
}
} }
} }

||||||
x
 
000:0
正在加载...
取消
保存