How to get Beats per minutes of a song in objective-c

后端 未结 3 834
后悔当初
后悔当初 2021-02-11 09:01

I did lots of R&D but did not get any good answer. I am working on music type app in iphone and i have to categorized songs on the basis of beats per minute.So my first task

3条回答
  •  臣服心动
    2021-02-11 09:56

    You can use http://www.un4seen.com/ for detecting BPM of song.

    Here is code for calculating BPM using this library.

    HSTREAM mainStream = BASS_StreamCreateFile(FALSE,[pathStr UTF8String],0,0,BASS_SAMPLE_FLOAT|BASS_STREAM_PRESCAN|BASS_STREAM_DECODE);
    
    float playBackDuration=BASS_ChannelBytes2Seconds(mainStream, BASS_ChannelGetLength(mainStream, BASS_POS_BYTE));
    
    HSTREAM  bpmStream=BASS_StreamCreateFile(FALSE, [pathStr UTF8String], 0, 0, BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE);
    
    float BpmValue= BASS_FX_BPM_DecodeGet(
                                    bpmStream,
                                    0.00,
                                    playBackDuration,
                                    MAKELONG(45,256),
                                    BASS_FX_BPM_MULT2,
                                     NULL);
    
    
        //Check if BpmValue have any value or not.
        //If it haven't any value then set default value to 128.
        if(BpmValue<=0)
              BpmValue = 128.00;
    

    You can do many other things like scratching using this library.

提交回复
热议问题