Generating waveform from any music file ios

和自甴很熟 提交于 2019-12-20 08:21:07

问题


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

  1. WaveForm on IOS
  2. rendering a waveform on an iphone
  3. audio waveform visualisation with iPhone

Github Example Links

  • 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?


回答1:


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.

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.

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




回答2:


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.



来源:https://stackoverflow.com/questions/19699780/generating-waveform-from-any-music-file-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!