fredi-68 / Ram

ProtOS Discord Bot (Codename: Ram) DISCLAIMER: This repository is a mirror of my local network source control. Information may or may not be inaccurate. Updates only whenever I can be bothered.
0 stars 0 forks source link

Add auto crossfade feature to audio engine #4

Open fredi-68 opened 6 years ago

fredi-68 commented 6 years ago

While I am struggling to see any practical use for this, it would be pretty cool to have anyways. Not like any of the other shit is practical. This would require the audio engine to pull synchronous sounds from the queue early and slowly adjust the volume of currently playing synchronous sounds to make a smooth transition. The difficult part is knowing when to start transitioning, since that requires knowledge of the length of each sound as well as the current playback position. I believe FFMPEG has a way of determining those without having to decode the entire audio file so this may actually not be too difficult, but would probably require us to download online resources completely before playing them, instead of streaming (which may kill our playback, if sounds are being queued).

fredi-68 commented 5 years ago

Had a look at the FFMPEG docs and ffprobe has a way of checking for track length. If we are playing directly from stream we can read the sound length directly from memory so we are good on that as well. The only thing we have to be careful of is cases where a sounds duration cannot be determined, for example if the length is unknown at the point of playback (like a live audio stream).

fredi-68 commented 5 years ago

Modified audio.FFMPEGSound to use FFPROBE to load metadata before playing a sound. Also started on implementing the necessary code in audio.ChannelStream but am not quite sure how I will do the whole "pulling from queue early" thing. I could make a new field/list to store the crossfade target or store the current state of playing sounds in some sort of Sound attribute.