Generating waveform from any music file ios

后端 未结 2 1600
悲&欢浪女
悲&欢浪女 2021-01-30 07:10

I\'m looking for how to draw the sound waves according to music.

I want waves like this image

\"enter

相关标签:
2条回答
  • 2021-01-30 07:54

    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

    0 讨论(0)
  • 2021-01-30 08:10

    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.

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