new trace logs and optimizations

This commit is contained in:
Joshua Reisenauer 2016-04-26 16:50:07 -07:00
parent 3104d3d6cd
commit 299ae7a4bd
2 changed files with 23 additions and 21 deletions

View File

@ -584,12 +584,15 @@ void PlayMusicStream(char *fileName)
// only stereo is supported for xm
if(!jar_xm_create_context_from_file(&currentMusic.chipctx, currentMusic.sampleRate, fileName))
{
currentMusic.format = AL_FORMAT_STEREO16; // AL_FORMAT_STEREO_FLOAT32;
currentMusic.format = AL_FORMAT_STEREO16;
jar_xm_set_max_loop_count(currentMusic.chipctx, 0); // infinite number of loops
currentMusic.totalSamplesLeft = jar_xm_get_remaining_samples(currentMusic.chipctx);
currentMusic.totalLengthSeconds = currentMusic.totalSamplesLeft / (currentMusic.sampleRate * currentMusic.channels);
currentMusic.totalLengthSeconds = ((float)currentMusic.totalSamplesLeft) / ((float)currentMusic.sampleRate);
musicEnabled = true;
TraceLog(INFO, "[%s] XM number of samples: %i", fileName, currentMusic.totalSamplesLeft);
TraceLog(INFO, "[%s] XM track length: %11.6f sec", fileName, currentMusic.totalLengthSeconds);
// Set up OpenAL
alGenSources(1, &currentMusic.source);
alSourcef(currentMusic.source, AL_PITCH, 1);
@ -601,7 +604,10 @@ void PlayMusicStream(char *fileName)
BufferMusicStream(currentMusic.buffers[1]);
alSourceQueueBuffers(currentMusic.source, 2, currentMusic.buffers);
alSourcePlay(currentMusic.source);
// NOTE: Regularly, we must check if a buffer has been processed and refill it: UpdateMusicStream()
}
else TraceLog(WARNING, "[%s] XM file could not be opened", fileName);
}
else TraceLog(WARNING, "[%s] Music extension not recognized, it can't be loaded", fileName);
}
@ -680,7 +686,7 @@ float GetMusicTimeLength(void)
float totalSeconds;
if (currentMusic.chipTune)
{
totalSeconds = currentMusic.totalLengthSeconds; // Not sure if this is the correct value
totalSeconds = currentMusic.totalLengthSeconds;
}
else
{
@ -801,7 +807,7 @@ void UpdateMusicStream(void)
{
if(currentMusic.chipTune)
{
currentMusic.totalSamplesLeft = jar_xm_get_remaining_samples(currentMusic.chipctx);
currentMusic.totalSamplesLeft = currentMusic.totalLengthSeconds * currentMusic.sampleRate;
}
else
{

View File

@ -121,51 +121,47 @@ void jar_xm_free_context(jar_xm_context_t*);
/** Play the module and put the sound samples in an output buffer.
*
* @param output buffer of 2*numsamples elements
* @param output buffer of 2*numsamples elements (A left and right value for each sample)
* @param numsamples number of samples to generate
*/
void jar_xm_generate_samples(jar_xm_context_t*, float* output, size_t numsamples);
/** Play the module, resample from 32 bit to 16 bit, and put the sound samples in an output buffer.
*
* @param output buffer of 2*numsamples elements
* @param output buffer of 2*numsamples elements (A left and right value for each sample)
* @param numsamples number of samples to generate
*/
void jar_xm_generate_samples_16bit(jar_xm_context_t* ctx, short* output, size_t numsamples)
{
float* musicBuffer = malloc((2*numsamples)*sizeof(float));
short* musicBuffer2 = malloc((2*numsamples)*sizeof(short));
jar_xm_generate_samples(ctx, musicBuffer, numsamples);
int x;
for(x=0;x<2*numsamples;x++)
musicBuffer2[x] = musicBuffer[x] * SHRT_MAX;
if(output){
int x;
for(x=0;x<2*numsamples;x++)
output[x] = musicBuffer[x] * SHRT_MAX;
}
memcpy(output, musicBuffer2, (2*numsamples)*sizeof(short));
free(musicBuffer);
free(musicBuffer2);
}
/** Play the module, resample from 32 bit to 8 bit, and put the sound samples in an output buffer.
*
* @param output buffer of 2*numsamples elements
* @param output buffer of 2*numsamples elements (A left and right value for each sample)
* @param numsamples number of samples to generate
*/
void jar_xm_generate_samples_8bit(jar_xm_context_t* ctx, char* output, size_t numsamples)
{
float* musicBuffer = malloc((2*numsamples)*sizeof(float));
char* musicBuffer2 = malloc((2*numsamples)*sizeof(char));
jar_xm_generate_samples(ctx, musicBuffer, numsamples);
int x;
for(x=0;x<2*numsamples;x++)
musicBuffer2[x] = musicBuffer[x] * CHAR_MAX;
if(output){
int x;
for(x=0;x<2*numsamples;x++)
output[x] = musicBuffer[x] * CHAR_MAX;
}
memcpy(output, musicBuffer2, (2*numsamples)*sizeof(char));
free(musicBuffer);
free(musicBuffer2);
}