syedhali / EZAudio

An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
Other
4.94k stars 822 forks source link

Issue in generating overlapped waveform #253

Open bhushanb02 opened 8 years ago

bhushanb02 commented 8 years ago

Hi Syed,

I have to generate two waveforms for single audio. First waveform would be a compressed whole waveform and second waveform is a overlap on first one of rolling plot type. So that it will look like filling the first waveform(Like iMessage did while playback of recorded audio).

Please see my code below :

func showDisplayWaveform()  {
        // Plot the whole waveform for display
        self.displayAudioPlot = EZAudioPlot()
        self.displayAudioPlot!.frame = CGRect(x: 0, y: 0, width:320, height: 40)
        self.displayAudioPlot!.backgroundColor = UIColor.clearColor()
        self.displayAudioPlot!.color = UIColor.orangeColor()
        self.displayAudioPlot!.plotType = .Buffer
        self.displayAudioPlot!.shouldFill = true
        self.displayAudioPlot!.shouldMirror = true
        self.displayAudioPlot!.gain = 3.0
        self.addSubview(self.displayAudioPlot!)

        self.audioFile = EZAudioFile(URL: testFilePathURL())
        let waveformData = self.audioFile!.getWaveformData()
        self.displayAudioPlot!.updateBuffer(waveformData.buffers[0], withBufferSize: waveformData.bufferSize)
    }

    func showPlayingWaveform()  {
        // Setup Player
        self.player = EZAudioPlayer(delegate: self)
        self.player?.playAudioFile(self.audioFile)

        self.playingAudioPlot = EZAudioPlotGL()
        self.playingAudioPlot?.frame = CGRect(x: 0, y: 0, width: 320, height: 40)
        self.playingAudioPlot?.backgroundColor = UIColor.clearColor()
        self.playingAudioPlot?.color = UIColor.yellowColor()
        self.playingAudioPlot?.plotType = .Rolling
        self.playingAudioPlot?.shouldFill = true
        self.playingAudioPlot?.shouldMirror = true
        self.playingAudioPlot?.gain = 6.0

        let length = self.displayAudioPlot?.displayAudioPlot()
        self.playingAudioPlot?.setRollingHistoryLength(length!)

        self.addSubview(self.playingAudioPlot!)
    }

    func audioPlayer(audioPlayer: EZAudioPlayer!, playedAudio buffer: UnsafeMutablePointer<UnsafeMutablePointer<Float>>, withBufferSize bufferSize: UInt32, withNumberOfChannels numberOfChannels: UInt32, inAudioFile audioFile: EZAudioFile!) {

        dispatch_async(dispatch_get_main_queue()) { () -> Void in
            if let playingAudioPlot = s
![screen shot 2015-12-10 at 11 46 35 pm](https://cloud.githubusercontent.com/assets/2226208/11724153/618f9528-9f98-11e5-8f9f-0de31cec7c11.png)
elf.playingAudioPlot {
                playingAudioPlot.updateBuffer(buffer[0], withBufferSize: bufferSize)
            }
        }
    }

I have also set rollingHistoryLength of playingAudioPlot using displayAudioPlot's rollingHistoryLength. But end up with the overlay like this : screen shot 2015-12-10 at 11 46 35 pm

Please point me in right direction and let me know in case if you need more information.

Mindbowser commented 8 years ago

@syedhali We are also having similar requirement, let us know if you have better way of handling it, quick help is appreciated.

DenisLaboureyras commented 8 years ago

Any progress ? I'm interested in this feature as well :)

skg54 commented 6 years ago

Not sure if this is the best solution but I captured 2 images of the EZAudioPlot https://stackoverflow.com/questions/3539717/getting-a-screenshot-of-a-uiscrollview-including-offscreen-parts/3539944#3539944

And animated a UIBezierPath mask on the top one to make it disappear in a left to right manner https://stackoverflow.com/questions/24644362/animated-image-wipe-for-waveform-color-change