Change music at end of loop point
Moderator: GZDoom Developers
Change music at end of loop point
From my understanding, ZDoom will utilize loop points in background music to seamlessly loop music without repeating unwanted parts of the intro. Would it be possible to have a function that changes music after the end of the current loop point is reached?
Having that feature would drastically improve the ability to implement a dynamic soundtrack akin to Doom 2016 or simply combat/non-combat states.
Having that feature would drastically improve the ability to implement a dynamic soundtrack akin to Doom 2016 or simply combat/non-combat states.
Re: Change music at end of loop point
Have you managed to find the solution? I'm currently working on the randomized music mod and having this feature is essential.
Re: Change music at end of loop point
I've actually thought a lot about a feature like this, but have not yet made an attempt at adding it.
It would have to be possible to specify multiple loop start and end points per music track, because there might be a brief delay when starting a completely new music track. For OGG and FLAC that might be accomplished using sets of tags with specific names. You could treat each set of loop points as a track, and then queue a track change to occur after the current one reaches it's loop end point. A QueueMusic ACS command using the same parameters as SetMusic might be used for that, where the order parameter specifies the track to queue up next. Or perhaps a QueueTrack command that would only queue a new track within the current music track.
It would have to be possible to specify multiple loop start and end points per music track, because there might be a brief delay when starting a completely new music track. For OGG and FLAC that might be accomplished using sets of tags with specific names. You could treat each set of loop points as a track, and then queue a track change to occur after the current one reaches it's loop end point. A QueueMusic ACS command using the same parameters as SetMusic might be used for that, where the order parameter specifies the track to queue up next. Or perhaps a QueueTrack command that would only queue a new track within the current music track.
- Chicken McNuggets
- Posts: 2
- Joined: Sat Jan 25, 2020 4:10 pm
Re: Change music at end of loop point
Damn, great idea! Was searching for the solution for weeks. Though, it's rather strange that ZDoom doesn't send a message of some kind by itself, as it seems that it loops untagged and unmapped tracks automatically.
- Chris
- Posts: 2942
- Joined: Thu Jul 17, 2003 12:07 am
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Change music at end of loop point
By the time a track ends or hits the loop point, it's either already stopped or has already buffered some looped samples. Any kind of notification for a loop or end event would have to be sent ahead of time, so that the decoder/reader can do something at the appropriate time ahead of actual playback (which could have dozens or hundreds of milliseconds of audio still waiting to play). Though even then you'll have limitations if you want smooth transitions. For Ogg and FLAC and the like, the format of a new track will have to be the same as the old one; for instance, you can't queue up mono 44.1khz samples after stereo 48khz samples without a break in playback since the sample timing and channel positioning isn't the same. Switching to/from MIDI will also be a problem if using an external MIDI synth.
And that's assuming tracks are correctly authored to seamlessly switch at specific points. It would need careful management by the sound engineer, with limits on how things are put together. It's possible various formats are amenable to this (e.g. Ogg Vorbis files containing multiple audio streams), which can help ensure coherency between tracks/streams, although I'm not familiar with utilizing them.
And that's assuming tracks are correctly authored to seamlessly switch at specific points. It would need careful management by the sound engineer, with limits on how things are put together. It's possible various formats are amenable to this (e.g. Ogg Vorbis files containing multiple audio streams), which can help ensure coherency between tracks/streams, although I'm not familiar with utilizing them.
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49073
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Change music at end of loop point
I noticed that OpenAL has sufficient lag here when trying to implement streaming audio for some of the video formats in Raze. I had to fudge quite a bit to make them match up.
From that experience I have to conclude that such a notification feature is not going to work without some major changes to the music system.
From that experience I have to conclude that such a notification feature is not going to work without some major changes to the music system.
- Chris
- Posts: 2942
- Joined: Thu Jul 17, 2003 12:07 am
- Graphics Processor: ATI/AMD with Vulkan/Metal Support
Re: Change music at end of loop point
Worse, different systems will have a different amount of lag. OpenAL Soft has extensions to measure the active latency of a sound source (or more generally, the device), though proper A/V sync for video playback can get somewhat involved.Graf Zahl wrote:I noticed that OpenAL has sufficient lag here when trying to implement streaming audio for some of the video formats in Raze. I had to fudge quite a bit to make them match up.
For a form of this feature, however, OpenAL and streaming lag doesn't really factor into it. It's in the decoder's domain; when the decoder would read sample 'X' from the file (the end loop point or some other predefined point), jump to time point 'Y' (or bitstream 'Z') to read samples instead. From OpenAL's perspective, it's just playing a continuous stream of samples, it doesn't really care about what the decoder or zmusic is doing to get them. The trick, as it were, is largely in defining how scripts can control the flow of a music stream. What would be needed is a way for songs to define break points and seek points (as defined by the music creator; where it can stop reading the current samples and start reading other samples, without causing an obvious click or pop when played), and a way for scripts to set a seek point the decoder should start reading from the next time it reaches a break point.
- Chicken McNuggets
- Posts: 2
- Joined: Sat Jan 25, 2020 4:10 pm
Re: Change music at end of loop point
I've almost offended the ZDoom and got a detailed explanation of where and why I was wrong. Man, I love this community.Chris wrote:By the time a track ends or hits the loop point, it's either already stopped or has already buffered some looped samples. Any kind of notification for a loop or end event would have to be sent ahead of time, so that the decoder/reader can do something at the appropriate time ahead of actual playback (which could have dozens or hundreds of milliseconds of audio still waiting to play). Though even then you'll have limitations if you want smooth transitions. For Ogg and FLAC and the like, the format of a new track will have to be the same as the old one; for instance, you can't queue up mono 44.1khz samples after stereo 48khz samples without a break in playback since the sample timing and channel positioning isn't the same. Switching to/from MIDI will also be a problem if using an external MIDI synth.
And that's assuming tracks are correctly authored to seamlessly switch at specific points. It would need careful management by the sound engineer, with limits on how things are put together. It's possible various formats are amenable to this (e.g. Ogg Vorbis files containing multiple audio streams), which can help ensure coherency between tracks/streams, although I'm not familiar with utilizing them.
Re: Change music at end of loop point
I did suggested ChangeMusicVolume in the past and I just got. "No". Hopefully, this function exist now.Samuel Seblingchark wrote: Having that feature would drastically improve the ability to implement a dynamic soundtrack akin to Doom 2016 or simply combat/non-combat states.
Doom 2016 use a short piece of music to play when combat is done. Normally it is some guitar riff to represent the transitions between combat and no combat. You can do the same method.