dmrschmidt / DSWaveformImage

Generate waveform images from audio files on iOS, macOS & visionOS in Swift. Native SwiftUI & UIKit views.
MIT License
1.04k stars 113 forks source link

Width issue #6

Closed cortnum closed 5 years ago

cortnum commented 6 years ago

Hi,

This is an otherwise amazing framework, however there is one big issue that is plauging me, which prevents us from using this in our app.

When I set a width for the waveform, it does not properly fill out the image. It is as if it just appends a bunch of "silence" for the extra width, until I hit a certain width, where it starts rendering correctly again until it once more appends "silence" when making the image bigger.

I have attached screenshots of widths 260 (which shows only silence), 264 (which is almost perfect) and 300 (which shows "appended silence").

screenshot screenshot screenshot

Here is our code:

    AudioExporter.instance.exportSongToM4A(song: self.song!, completionHandler: { (success) in
        let waveformImageDrawer = WaveformImageDrawer()
        let waveformSize = CGSize(width: 264, height: sequenceHeight)
        let scale = UIScreen.main.scale

        DispatchQueue.main.async {
            print("export finished: \(success)")
            if success {
                if let trackWaveformImage = waveformImageDrawer.waveformImage(fromAudioAt: self.song!.exportUrlM4A(),
                                                                              size: waveformSize,
                                                                              color: UIColor.white,
                                                                              backgroundColor: UIColor.clear,
                                                                              style: .filled,
                                                                              position: .middle,
                                                                              scale: scale) {

                    DispatchQueue.main.async {
                        let trackWaveformImageView = UIImageView(frame: CGRect(origin: CGPoint(x: x, y: y), size: waveformSize))
                        trackWaveformImageView.image = trackWaveformImage
                        trackWaveformImageView.contentMode = .scaleToFill

                        self.waveformViews.append(trackWaveformImageView)
                        self.sequenceScrollView.addSubview(trackWaveformImageView)
                        self.sequenceScrollView.bringSubview(toFront: self.scrubberImageView)
                    }
                }
            } else {
                //TODO: Nothing?
            }
        }
    })

Any help would be appreciated

Cheers,

/Mikkel

dmrschmidt commented 5 years ago

Hey Mikkel,

sorry for the uber-late reply. I haven't been paying a lot of attention to github and the notification here drowned among all the others unfortunately. I'm assuming it is way too late to ask, but would it still be possible to provide me with one of the audio assets you used, which produced this problem so I can replicate it and fix the issue?

I'd very much appreciate it :) Thanks, Dennis

dmrschmidt commented 5 years ago

closed with #8 and #12