GNOME Bugzilla – Bug 752762
crossfade: New example for crossfading audio tracks using audiomixer
Last modified: 2018-11-03 11:39:30 UTC
Created attachment 307971 [details] [review] crossfade: New example for crossfading audio tracks using audiomixer /* * crossfade: An example application to play a list of audio files with * cross-fade between each file. * * This example application uses the audiomixer element combined with * GstController and pad probes to play a list of audio files in such a way that * the audio is cross-faded while switching between files. * * Each file is played by a decoder bin inside each CrossfadeItem. This bin has * a queue right before its srcpad which has a "max-size-time" of * 2 * CROSSFADE_TIME_MS. When an EOS is detected on the sinkpad of this queue, * the next CrossfadeItem is attached to audiomixer, the correct pad offset is * set, and fadein/fadeout is scheduled using GstControlSources. * * A crossfade can also be scheduled immediately by switching to the next item * "early" using crossfade_app_activate_next_item_early(). * * The list of CrossfadeItems can be edited and added to dynamically; except the * currently-playing item and the next one (which has been prepared already). * * Bugs: * - If the size of the file being played is smaller than 3*CROSSFADE_TIME_MS * and the file was played with a fadein crossfade (i.e., it was not the first * file to be played), the queue before audiomixer which is used to detect a * file going EOS will contain buffers of a total time less than * CROSSFADE_TIME_MS. The crossfade will hence happen in whatever buffer-time * is available. * - If CROSSFADE_TIME_MS is set to a value less than the duration of a single * buffer, no crossfade will happen, but the switch will be gapless. */ This is a decent example of how to use audiomixer for gapless/crossfade playback in an audio player. Although the example expects files, this method of doing crossfade/gapless should also work with arbitrary URIs.
I was recently looking into crossfading and the only thing I could find was rythmbox's implementation. This is a much better example. Is there any reason for not committing it? I was thinking though that since it is quite complex for an application to do all these operations, perhaps much of this logic could be wrapped in a bin at some point. Any thoughts on that?
Most of the complexity is in the EOS handling. It is quite easy to handle on-demand cross-fade; you setup the control sources and let it handle the properties for you, and remove the pad when the cross-fade is done. It is difficult to cross-fade on (near) EOS automatically in a bin because the implementation involves guesswork and a certain amount of queuing. I'm sure it can be done, but someone has to do the work. I'm not sure why this never made it into the examples though; I've forgotten the reason.
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/208.