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

后端 未结 3 832
后悔当初
后悔当初 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:37

    Get Bpm of audio songs within minute:

    BASS_SetConfig(BASS_CONFIG_IOS_MIXAUDIO, 0); // Disable mixing. To be called before BASS_Init.
    
    if (HIWORD(BASS_GetVersion()) != BASSVERSION) {
        NSLog(@"An incorrect version of BASS was loaded");
    }
    
    // Initialize default device.
    if (!BASS_Init(-1, 44100, 0, NULL, NULL)) {
        NSLog(@"Can't initialize device");
    
    }
    
    //NSArray *array = [NSArray arrayWithObject:@""
    
    NSString *respath = [[NSBundle mainBundle] pathForResource:@"[Songs.PK] Paathshaala - 01 - Aye Khuda" ofType:@"mp3"];
    
    DWORD chan1;
    if(!(chan1=BASS_StreamCreateFile(FALSE, [respath UTF8String], 0, 0, BASS_SAMPLE_LOOP))) {
        NSLog(@"Can't load stream!");
    
    }
    
    mainStream=BASS_StreamCreateFile(FALSE, [respath cStringUsingEncoding:NSUTF8StringEncoding], 0, 0, BASS_SAMPLE_FLOAT|BASS_STREAM_PRESCAN|BASS_STREAM_DECODE);
    
    float playBackDuration=BASS_ChannelBytes2Seconds(mainStream, BASS_ChannelGetLength(mainStream, BASS_POS_BYTE));
    NSLog(@"Play back duration is %f",playBackDuration);
    HSTREAM bpmStream=BASS_StreamCreateFile(FALSE, [respath UTF8String], 0, 0, BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE);
    //BASS_ChannelPlay(bpmStream,FALSE);
    BpmValue= BASS_FX_BPM_DecodeGet(bpmStream,0.0,
                                     playBackDuration,
                                     MAKELONG(45,256),
                                     BASS_FX_BPM_MULT2,
                                    NULL);
    NSLog(@"BPM is %f",BpmValue);
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-11 10:02

    Apple provides aurioTouch sample code which display the input audio in one of the forms, a regular time domain waveform, a frequency domain waveform (computed by performing a fast fourier transform on the incoming signal), and a sonogram view (a view displaying the frequency content of a signal over time, with the color signaling relative power, the y axis being frequency and the x as time).

    0 讨论(0)
提交回复
热议问题