Jump to content

Detecting bpm with Bass.dll


Recommended Posts

What I am trying to do is get the bpm from a song that is playing on the computer using bass.dll from http://www.un4seen.com/.

This is my code

While 1
$bpmdata=DllCall("bass.dll","Long", "BASS_ChannelGetAttribute","DWORD","HMUSIC","DWORD","BASS_ATTRIB_MUSIC_BPM","float","                  ")

msgbox(0,"$bpmdata",$bpmdata)
msgbox(0,"$bpmdata[0]",$bpmdata[0])
msgbox(0,"$bpmdata[1]",$bpmdata[1])
msgbox(0,"$bpmdata[2]",$bpmdata[2])


Wend

And here is a page from the bass help file.

BASS_ChannelGetAttribute

--------------------------------------------------------------------------------

Retrieves the value of a channel's attribute.

BOOL BASS_ChannelGetAttribute(

DWORD handle,

DWORD attrib,

float *value

);

Parameters

handle The channel handle... a HCHANNEL, HMUSIC, HSTREAM, or HRECORD.

attrib The attribute to set the value of... one of the following.

BASS_ATTRIB_EAXMIX EAX wet/dry mix. (HCHANNEL/HMUSIC/HSTREAM only)

BASS_ATTRIB_FREQ Sample rate.

BASS_ATTRIB_MUSIC_AMPLIFY Amplification level. (HMUSIC)

BASS_ATTRIB_MUSIC_BPM BPM. (HMUSIC)

BASS_ATTRIB_MUSIC_PANSEP Pan separation level. (HMUSIC)

BASS_ATTRIB_MUSIC_PSCALER Position scaler. (HMUSIC)

BASS_ATTRIB_MUSIC_SPEED Speed. (HMUSIC)

BASS_ATTRIB_MUSIC_VOL_CHAN A channel volume level. (HMUSIC)

BASS_ATTRIB_MUSIC_VOL_GLOBAL Global volume level. (HMUSIC)

BASS_ATTRIB_MUSIC_VOL_INST An instrument/sample volume level. (HMUSIC)

BASS_ATTRIB_PAN Panning/balance position.

BASS_ATTRIB_VOL Volume level.

other attributes may be supported by add-ons, see the documentation.

value Pointer to a variable to receive the attribute value.

Return value

If successful, then TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.

Error codes

BASS_ERROR_HANDLE handle is not a valid channel.

BASS_ERROR_ILLTYPE attrib is not valid.

some attributes may have additional error codes, see the documentation.

I have been searching through the forums for several days and I need someone to show me if I was close to it or was completely wrong and should start from scratch. Cheers.

Edited by TheDarkEngineer

Trust me to make SkyNet with AutoIt...

Link to comment
Share on other sites

Maybe something like this:

Global Const $BASS_ATTRIB_MUSIC_BPM = 0x103

; DLL Stuff
$test_mp3 = "d:\my documents\My Music\Nirvana20-20Smells20Like20Teen20Spirit.mp3"
;$test_mp3 = "d:\my documents\autoit\Media Player\Downloaded Files\BASS DLL\SAMPLES\6chan\6chan.ogg"
$bassdll = DllOpen("bass.dll")

$ret = DllCall($bassdll, "int", "BASS_Init", "int", -1, _
        "int", 44100, _
        "int", 0, _
        "hwnd", 0, _
        "ptr", 0)
If Not $ret[0] Then
    MsgBox(0, "Error", 'Error initializing audio!');
    Exit
EndIf

$fName = DllStructCreate("char[255]")
DllStructSetData($fName, 1, $test_mp3)
$stream = DllCall($bassdll, "int", "BASS_StreamCreateFile", "int", False, "ptr", DllStructGetPtr($fName), "uint64", 0, "uint64", 0, "dword", 0x200)
$music_handle = $stream[0]
$fName = 0
$ret = DllCall($bassdll, "int", "BASS_ChannelPlay", "dword", $music_handle, "int", 0)

$return2 = DllStructCreate ("ptr")

$bpmdata = DllCall("bass.dll","int", "BASS_ChannelGetAttribute","DWORD",$music_handle, "DWORD",$BASS_ATTRIB_MUSIC_BPM, "ptr", DllStructGetPtr ($return2))

$ret = DllStructGetData ($return2, 1)
MsgBox (0, "", $ret)

Still learning dll calls using Structs... Getting better though :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...