Change music at end of loop point

Moderator: GZDoom Developers

Guest

Change music at end of loop point

Post by Guest »

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.
Guest

Re: Change music at end of loop point

Post by Guest »

Have you managed to find the solution? I'm currently working on the randomized music mod and having this feature is essential.
User avatar
Exl
Posts: 20
Joined: Wed Jul 01, 2009 5:22 am

Re: Change music at end of loop point

Post by Exl »

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.
User avatar
Chicken McNuggets
Posts: 2
Joined: Sat Jan 25, 2020 4:10 pm

Re: Change music at end of loop point

Post by Chicken McNuggets »

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.
User avatar
Chris
Posts: 2840
Joined: Thu Jul 17, 2003 12:07 am
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: ATI/AMD with Vulkan Support

Re: Change music at end of loop point

Post by Chris »

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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 47968
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Change music at end of loop point

Post by Graf Zahl »

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.
User avatar
Chris
Posts: 2840
Joined: Thu Jul 17, 2003 12:07 am
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: ATI/AMD with Vulkan Support

Re: Change music at end of loop point

Post by Chris »

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.
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.

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.
User avatar
Chicken McNuggets
Posts: 2
Joined: Sat Jan 25, 2020 4:10 pm

Re: Change music at end of loop point

Post by Chicken McNuggets »

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.
I've almost offended the ZDoom and got a detailed explanation of where and why I was wrong. Man, I love this community.
User avatar
Logan MTM
Posts: 677
Joined: Mon Jan 16, 2006 8:53 pm
Location: Rio de Janeiro - Brazil

Re: Change music at end of loop point

Post by Logan MTM »

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.
I did suggested ChangeMusicVolume in the past and I just got. "No". Hopefully, this function exist now.
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.

Return to “Closed Feature Suggestions”