Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Looping MOD music

Credits go to Elias for helping out!
This thread is locked; no one can reply to it. rss feed Print
Looping MOD music
Max Savenkov
Member #4,613
May 2004
avatar

I noticed that when I play looped MOD streams they always have a gap of silence before repeat. I believe this is related to streaming/buffers? Can I somehow make looping gap-less? Maybe set the right buffer size/count, or something?

Here's what I do now:

m_pVoice = al_create_voice( 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2 );    
m_pMusicMixer = al_create_mixer( 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2 );
m_pSoundMixer = al_create_mixer( 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2 );
m_pMasterMixer = al_create_mixer( 44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2 );
al_attach_mixer_to_mixer( m_pMusicMixer, m_pMasterMixer );
al_attach_mixer_to_mixer( m_pSoundMixer, m_pMasterMixer );
al_attach_mixer_to_voice( m_pMasterMixer, m_pVoice );

m_pInstance = al_load_audio_stream( path.c_str(), 10, 1024 );
al_set_audio_stream_playmode( m_pInstance, ALLEGRO_PLAYMODE_LOOP );
al_set_audio_stream_playing( m_pInstance, true );

Elias
Member #358
May 2000

What if you loop an ogg or flac instead? (Just trying to rule out a MOD related problem so we don't try to find the problem at the wrong place.)

--
"Either help out or stop whining" - Evert

Max Savenkov
Member #4,613
May 2004
avatar

If I loop a WAV everything's OK, it starts looping just as soon as it ends.

I suspect this is related to mod music specifically, because I had the same problem with irrKlang (its author said that it cannot be fixed, but then Visual Studio reports memory leaks in his MOD-playback code...).

Elias
Member #358
May 2000

Ok, so then changing anything about the buffers or streams will do nothing. I don't really know much about MOD files though. Allegro's addon simply uses libDUMB to play them, this seems where it detects when the loop point is reached: https://github.com/elias-pschernig/allegro5/blob/master/addons/acodec/modaudio.c#L122

Maybe you can check the DUMB documentation about the expected way to do looping? Also, what if you loop your mod with DUMB itself (I assume it comes with an example player)? Does it work?

If there is no easy solution but the MOD loops properly in other players, you could just render it into an OGG file then loop that in Allegro.

--
"Either help out or stop whining" - Evert

Max Savenkov
Member #4,613
May 2004
avatar

OK, now I see it's MODPlug Tracker who inserts silence :( I actually know nothing of mod music, you understand, but just write my songs in the only editor I know how to use - Guitar Pro - and then export them. Unfortunately, it can only export them to MIDI or WAV. I don't like the idea of a single song being bigger than the rest of resources combined, so I think WAV (and even OGG) is probably out of question. And Allegro does not play MIDI now :) So I used MPTracker to convert MIDI file into IT file (convoluted way, I know).

Now, I think, I can try to write a MIDI addon for Allegro (which many people asked for anyway) or use big-ass OGG-files (although, with carefully chosen compression options they might be not so big, probably).

gnolam
Member #2,030
March 2002
avatar

Yay, problem solved! Because now I can say what someone has to in the name of sanity: ewwww, Systems Hungarian. :-X

As the guide to writing unmaintainable code puts it: "Hungarian Notation is the tactical nuclear weapon of source code obfuscation techniques". It really has no place in code today - type and scope information is something an IDE can provide for you easier, better and in a more readable form than any combination of cryptic prefixes will.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Elias
Member #358
May 2000

For the sake of argument, some of us don't use an IDE but a simple text editor (and I don't mean vim or emacs when I say simple). And then being able to see the type without having to backtrack to the declaration can be an advantage. Similarly it can help grepping for a variable in all your sources (those prefixes tend to make them more unique).

--
"Either help out or stop whining" - Evert

Audric
Member #907
January 2001

Max, you can check in ModPlug Tracker how the last pattern of your converted music plays when you listen to it. If there are many lines of zeroes at the end that get played (ie. silence), you can fix the song: Find the last line that played a sound, and in the 'Effect' column, write C00 : It's a 'pattern break', it informs the tracker that lines below shouldn't be played.

Max Savenkov
Member #4,613
May 2004
avatar

gnolam said:

Yay, problem solved! Because now I can say what someone has to in the name of sanity: ewwww, Systems Hungarian. :-X

As the guide to writing unmaintainable code puts it: "Hungarian Notation is the tactical nuclear weapon of source code obfuscation techniques". It really has no place in code today - type and scope information is something an IDE can provide for you easier, better and in a more readable form than any combination of cryptic prefixes will.

The "p" prefix for raw pointers is the only one part of Hungarian notation we use in our code standard at work, so I'm keeping it in my pet projects too. I don't find it cumbersome or unmaintainable, and it really could be useful sometimes as a quick reminder that this particular variable is "unsafe". Actually, I got it on the automatic, so I would have to force myself quite hard to abandon it :) Anyway, it seems to be an universal standard in Russian gamedev.

Audric said:

Find the last line that played a sound, and in the 'Effect' column, write C00 : It's a 'pattern break', it informs the tracker that lines below shouldn't be played.

THANKS! I'll try that!

EDIT: Yes, it works. Great!

Go to: