从任何音乐文件 ios 生成波形
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19699780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generating waveform from any music file ios
提问by Vishal Khatri
I'm looking for how to draw the sound waves according to music.
我正在寻找如何根据音乐绘制声波。
I want waves like this image
我想要像这张图片那样的波浪
here is some discussion about displaying Waves from music
这里有一些关于从音乐中显示 Waves 的讨论
Github Example Links
Github 示例链接
- https://github.com/gyetvan-andras/cocoa-waveform
- https://github.com/benalavi/waveform
- https://github.com/JingWZ/WaveView
- https://github.com/gyetvan-andras/cocoa-waveform
- https://github.com/ioslovers/ATTabandHoldAudioRecord
- https://github.com/hezone/ECGWavesPlayer
- https://github.com/iluvcapra/JHWaveform
- https://github.com/gyetvan-andras/cocoa-waveform
- https://github.com/benalavi/waveform
- https://github.com/JingWZ/WaveView
- https://github.com/gyetvan-andras/cocoa-waveform
- https://github.com/ioslovers/ATTabandHoldAudioRecord
- https://github.com/hezone/ECGWavesPlayer
- https://github.com/iluvcapra/JHWaveform
But not getting any idea about this type of wavefrom, is this possible to draw waves like this image?
但是对这种类型的wavefrom没有任何想法,是否可以像这张图片一样绘制波浪?
回答by JConway
Disclaimer: A lot of this has been discovered through trial and error, I may have some serious false assumptions in play here:
免责声明:很多都是通过反复试验发现的,我在这里可能有一些严重的错误假设:
You would need to use the AudioUnits framework. When initialising the playback you can create an AURenderCallbackStruct. You can specify in this struct a playback callback function which provides you with a few arguments which will contain the information you need.
您需要使用 AudioUnits 框架。初始化播放时,您可以创建一个 AURenderCallbackStruct。您可以在此结构中指定一个播放回调函数,该函数为您提供一些包含您需要的信息的参数。
the callback function will have a signature like this:
回调函数将具有如下签名:
static OSStatus recordingCallback (void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData)
In here there is an array of audio data which can be used for getting amplitude of the audio buffer for each frequency bin, or for calculating the DB value of the frequency bin.
这里有一个音频数据数组,可用于获取每个频率仓的音频缓冲区的幅度,或用于计算频率仓的 DB 值。
I don't know what that graph is showing, but it looks to me like a smoothed display of the amplitudes of each of the sample bins.
我不知道该图显示的是什么,但在我看来,它就像是每个样本箱振幅的平滑显示。
Audio Units are not simple, but its worth playing with for a while until you get a grip.
音频单元并不简单,但值得玩一会儿,直到您掌握为止。
Here is a skeleton of my callback function so you have more of a grasp as to what I mean:
这是我的回调函数的骨架,因此您对我的意思有更多的了解:
EDIT: removed dead link, I've lost this code sorry
编辑:删除了死链接,对不起,我丢失了这段代码
回答by Tendulkar
I, too have been trying sincerely for the last three months but I didn't find a solution. For the time being I used static images based on the type of song (static data songs). I added the images to a UIScrollView
and changed the contentOffset
based on the current position of the audio.
过去三个月我也一直在真诚地尝试,但我没有找到解决方案。暂时我使用基于歌曲类型的静态图像(静态数据歌曲)。我将图像添加到 aUIScrollView
并contentOffset
根据音频的当前位置更改了。