[SOLVED] How do check audio BPM?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
zikesha93
Prole
Posts: 11
Joined: Thu Sep 10, 2015 9:00 am
Location: your underwear

[SOLVED] How do check audio BPM?

Post 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?
Last edited by zikesha93 on Fri Jan 22, 2016 5:39 am, edited 1 time in total.
User avatar
Kalamitous
Prole
Posts: 9
Joined: Thu Jun 18, 2015 4:34 am
Location: Behind you.

Re: How do check audio BPM?

Post 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)
Last edited by Kalamitous on Fri Jan 22, 2016 5:57 pm, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How do check audio BPM?

Post 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 :3

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.
Last edited by zorg on Sat Jan 23, 2016 1:05 pm, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Kalamitous
Prole
Posts: 9
Joined: Thu Jun 18, 2015 4:34 am
Location: Behind you.

Re: How do check audio BPM?

Post by Kalamitous »

zorg wrote: Or, you know, with [wiki]SoundData:getDuration[/wiki]
Wow, I didn't even know that existed lol.
User avatar
zikesha93
Prole
Posts: 11
Joined: Thu Sep 10, 2015 9:00 am
Location: your underwear

Re: How do check audio BPM?

Post 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.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How do check audio BPM?

Post 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)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Kalamitous
Prole
Posts: 9
Joined: Thu Jun 18, 2015 4:34 am
Location: Behind you.

Re: How do check audio BPM?

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

Who is online

Users browsing this forum: No registered users and 214 guests