diff --git a/src/conf.c b/src/conf.c index 7323a50..0ac00b5 100644 --- a/src/conf.c +++ b/src/conf.c @@ -208,7 +208,7 @@ void conf_parseCLI(int argc, char** argv) { int option_index = 0; int c = 0; - while((c = getopt_long(argc, argv, "fF:d:J:j:sm:V:hv", long_options, &option_index)) != -1) { + while((c = getopt_long(argc, argv, "fF:d:J:j:s:m:V:hv", long_options, &option_index)) != -1) { switch(c) { case 'f': gl_screen.flags |= OPENGL_FULLSCREEN; diff --git a/src/land.c b/src/land.c index 94a66f3..57bc21f 100644 --- a/src/land.c +++ b/src/land.c @@ -148,7 +148,7 @@ void takeoff(void) { if(!landed) return; music_load(MUSIC_TAKEOFF); - music_play(); + //music_play(); int sw, sh; sw = planet->gfx_space->w; diff --git a/src/main.c b/src/main.c index 0a419b9..7d0d6a0 100644 --- a/src/main.c +++ b/src/main.c @@ -111,7 +111,7 @@ int main(int argc, char** argv) { // OpenAL sound. if(sound_init()) WARN("Problem setting up sound!"); music_load("Machina"); - //music_play(); + music_play(); // Input. if((indjoystick >= 0) || (namjoystick != NULL)) { diff --git a/src/music.c b/src/music.c index 572eb92..3b0b2f5 100644 --- a/src/music.c +++ b/src/music.c @@ -75,25 +75,30 @@ int music_thread(void* unused) { // Main loop. while(!music_is(MUSIC_KILL)) { if(music_is(MUSIC_PLAYING)) { - music_rm(MUSIC_STOPPED); - SDL_mutexP(music_vorbis_lock); // Lock the mutex. - SDL_mutexP(sound_lock); + if(music_vorbis.file.end == 0) + music_rm(MUSIC_PLAYING); + else { + music_rm(MUSIC_STOPPED); - // Start playing current song. - active = 0; // Load first buffer. - if(stream_loadBuffer(music_buffer[active])) music_rm(MUSIC_PLAYING); - alSourceQueueBuffers(music_source, 1, &music_buffer[active]); + SDL_mutexP(music_vorbis_lock); // Lock the mutex. + SDL_mutexP(sound_lock); - // Start playing with the buffer loaded. - alSourcePlay(music_source); + // Start playing current song. + active = 0; // Load first buffer. + if(stream_loadBuffer(music_buffer[active])) music_rm(MUSIC_PLAYING); + alSourceQueueBuffers(music_source, 1, &music_buffer[active]); - active = 1; // Load second buffer. - if(stream_loadBuffer(music_buffer[active])) music_rm(MUSIC_PLAYING); - alSourceQueueBuffers(music_source, 1, &music_buffer[active]); + // Start playing with buffer laoaded. + alSourcePlay(music_source); - SDL_mutexV(sound_lock); + active = 1; // Load the second buffer. + if(stream_loadBuffer(music_buffer[active])) music_rm(MUSIC_PLAYING); + alSourceQueueBuffers(music_source, 1, &music_buffer[active]); - active = 0; // dive into the loop. + SDL_mutexV(sound_lock); + + active = 0; + } while(music_is(MUSIC_PLAYING)) { SDL_mutexP(sound_lock); @@ -141,15 +146,19 @@ static int stream_loadBuffer(ALuint buffer) { §ion); // Current bitstream. if(result == 0) return 1; - else if(result == OV_HOLE) + else if(result == OV_HOLE) { WARN("OGG: Vorbis hole detected in music!"); - else if(result == OV_EBADLINK) + return 0; + } + else if(result == OV_EBADLINK) { WARN("OGG: Invalid stream section or corrupt link in music!"); + return -1; + } size += result; if(size == BUFFER_SIZE) break; // Buffer is full. } - alBufferData(buffer, AL_FORMAT_STEREO16, data, size, music_vorbis.info->rate); + alBufferData(buffer, AL_FORMAT_STEREO16, data, BUFFER_SIZE, music_vorbis.info->rate); return 0; }