如何在objective-c中获得每首歌曲的节拍数 [英] How to get Beats per minutes of a song in objective-c

查看:87
本文介绍了如何在objective-c中获得每首歌曲的节拍数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多R& D但没有得到任何好的答案。我正在研究iphone中的音乐类型应用程序,我必须根据每分钟的节拍对歌曲进行分类。所以我的第一个任务是找出歌曲的BPM。我们怎么能这样做?我得到了一些答案:
1.使用MPMediaItem类的MPMediaItemPropertyBeatsPerMinute属性,它会正常工作。我对此有疑问,因为有些人说它会返回null。
您是否有任何示例代码或逻辑来实现此目的。

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 to find out BPM of song.How can we do that? I got some answers like: 1.using MPMediaItemPropertyBeatsPerMinute property of MPMediaItem class ,will it work fine. I have doubt on this because some guys said it will return null. Do you have any sample code or logic to get this.

提前致谢。

推荐答案

你可以使用 http://www.un4seen.com/ 用于检测歌曲的BPM。

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

以下是使用此库计算BPM的代码。

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.

这篇关于如何在objective-c中获得每首歌曲的节拍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆