Page 1 of 1
[SOLVED] How do check audio BPM?
Posted: Thu Jan 21, 2016 7:22 pm
by zikesha93
Is their a way to get soundDatas BPM rate? or even better the total amount of time it takes to play a song? I've been browsing the wiki and I can't seem to see a function for this. It might sound like a stupid question but its helpful for timing audio sequences. I think there was one function to check if love.audio is still playing a sound (if the sound has stopped) or maybe that was something else.
Edit: I think I was mixing up LOVE documentation for another engine.
Renpy Audio Functions
renpy.seen_audio(filename)
Returns True if the given filename has been played at least once on the current user's system.
renpy.music.get_playing(channel='music')
If the given channel is playing, returns the playing file name. Otherwise, returns None.
renpy.music.is_playing(channel='music')
Returns True if the channel is currently playing a sound, False if it is not, or if the sound system isn't working.
Is there a LOVE equivalent for the above?
Re: How do check audio BPM?
Posted: Thu Jan 21, 2016 10:49 pm
by Kalamitous
Getting the BPM would require an FFT module. You can get the soundData's length in seconds with this formula:
Code: Select all
soundData:getSize() / soundData:getSampleRate() / soundData:getChannels() / (soundData:getBitDepth() / 8)
Re: How do check audio BPM?
Posted: Fri Jan 22, 2016 1:04 am
by zorg
Kalamitous wrote:Getting the BPM would require an FFT module. You can get the soundData's length in seconds with this formula:
Code: Select all
soundData:getSize() / soundData:getSampleRate() / soundData:getChannels() / (soundData:getBitDepth() / 8)
Or, you know, with [wiki]SoundData:getDuration[/wiki]
zikesha93 wrote:
Renpy Audio Functions
renpy.seen_audio(filename)
Returns True if the given filename has been played at least once on the current user's system.
renpy.music.get_playing(channel='music')
If the given channel is playing, returns the playing file name. Otherwise, returns None.
renpy.music.is_playing(channel='music')
Returns True if the channel is currently playing a sound, False if it is not, or if the sound system isn't working.
The first can be implemented fairly simply by yourself (though i'd rephrase it to "if the given filename has been played at least once from the start of the application.", though if you want this to work persistently, as how i'm guessing the ren'py function makes it sound, then that's a bit more work, basically your own small-ish audio handling lib
The last function behaves just like [wiki]Source:isPlaying[/wiki], and the middle one is a hybrid of the last and a function returning the filename one used to create a source... also your own audio lib territory.
Re: How do check audio BPM?
Posted: Fri Jan 22, 2016 3:23 am
by Kalamitous
zorg wrote:
Or, you know, with [wiki]SoundData:getDuration[/wiki]
Wow, I didn't even know that existed lol.
Re: How do check audio BPM?
Posted: Fri Jan 22, 2016 5:38 am
by zikesha93
Thanks, I completely forgot about love.sound. Will check there in the wiki for more details. Thanks for the BPM formula. I'm sure I can work on a very small sound library.
Re: How do check audio BPM?
Posted: Fri Jan 22, 2016 7:09 am
by zorg
zikesha93 wrote:Thanks, I completely forgot about love.sound. Will check there in the wiki for more details. Thanks for the BPM formula. I'm sure I can work on a very small sound library.
Just to be clear, in no post in this thread was a formula for Tempo detection written, unless you mean the suggestion to look into Fast Fourier Transforms. The only formula was for getting the duration the slow way (and it was wrong, since it was missing a pair of parentheses around the "getBitDepth / 8" part)
Re: How do check audio BPM?
Posted: Fri Jan 22, 2016 5:56 pm
by Kalamitous
zorg wrote:zikesha93 wrote:(and it was wrong, since it was missing a pair of parentheses around the "getBitDepth / 8" part)
Oops, my bad. Fixed.