dmrschmidt / DSWaveformImage

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

waveform fit width? #52

Closed AndrewSB closed 1 year ago

AndrewSB commented 1 year ago

both with the WaveformView and WaveformLiveView, theres a bunch of space on the left or right if the audio file / number of samples isn't long enough. is there some way to have the waveform fit width?

Screenshot 2022-11-28 at 12 52 24 PM
dmrschmidt commented 1 year ago

Hmm... For WaveformView it should actually scale correctly to the full width. How long is that audio file? Does it have silence at the end? Could you share the audio maybe, so I could have a look? Definitely doesn't look correct, no.

For the WaveformLiveView the answer I'm afraid for now is "not really possible, no". It would require constant dynamic downsampling, which is quite compute intensive, so it would require to also make use of Accelerate operations. Doable of course, but not currently in scope for me to do.

Apart from that technical side, it's also currently intended for a different use case, which is more to show "time progress" during recording, rather then present the entire recording in one view. So it's designed to be used in places like a voice message recording a la WhatsApp, etc where the waveform "scrolls". I don't think I'd want to change that currently.

AndrewSB commented 1 year ago

ahh hey! nice to have you here live

yeah the waveform at the top is generated by (0 ..< 200).map { _ in Float.random(in: 0 ..< 1) }. if i make the number > 1200, it fills the width

the audio file i'm using is https://rr1---sn-4g5e6nsk.googlevideo.com/videoplayback?expire=1669679074&ei=gvOEY5-JNZSQ1gLk7IHoBg&ip=157.90.242.21&id=o-AHARjRnReqIcHP_PeF7VD3H3WkmGjDFLYVrp2s-KO5k6&itag=140&source=youtube&requiressl=yes&mh=Lp&mm=31%2C29&mn=sn-4g5e6nsk%2Csn-4g5edndd&ms=au%2Crdu&mv=m&mvi=1&pl=23&initcwndbps=287500&vprv=1&mime=audio%2Fmp4&ns=pXFa13Xa7VVvhsIAutUHZrAJ&gir=yes&clen=2887491&dur=178.375&lmt=1652043521368789&mt=1669657070&fvip=2&keepalive=yes&fexp=24001373%2C24007246&c=WEB&txp=4511222&n=P6lkM_epuLRxKLP&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIhAMBXn1p0eIWr7_RKn5ZefhXwn9pODfTVgi6OjfSNhQv7AiBZXNsNGa26hE9mZgJjP63QbMWk80fgX4ndh2-gSxk9YQ%3D%3D&ratebypass=yes&sig=AOq0QJ8wRAIgD5A_vbS4wF4UECx88Dqcr_2y4mQuekTmOMNVzoUKJ9wCIBcLZtLp_q9pTR9QgxAGpDXvuJa7WM2WA7yoz47i6aIe

AndrewSB commented 1 year ago

keeping the scrolling live view is seems like a fine direction, but i'm surprised that the file doesn't fit width

dmrschmidt commented 1 year ago

This is what that same audio file looks like when it is imported into Ableton:

Screenshot 2022-11-28 at 19 21 28

So there must be something strange about the audio file itself.

It looks like its taking up half the space than it should. Which makes me think it does sth like saying it's stereo when it's in fact mono, or claims to have a different sample rate than it actually has or sth. along those lines.

Given that Ableton renders it in the exact same way, I'm inclined to treat the audio file as buggy. I'm still curious what's going on here, but it looks low priority to me?

dmrschmidt commented 1 year ago

Hey @AndrewSB, I wanted to have another look at the file, to understand what the issue with it is. I'm still quite sure the issue is with the file itself and not the library, but I'd like to understand exactly how the file is weird to make sure there's not some other potential issue that may come up later for files like that.

Unfortunately the link you had pasted doesn't work anymore. Do you still have a copy of it lying around anywhere?

And did you maybe figure out what was wrong with it? Which app / encoder / etc. actually created it originally?

AndrewSB commented 1 year ago

for sure! i was downloading it using ytdl from youtube, with one of the highest quality audio options. m4a i think

https://youtu.be/Z0Uh3OJCx3o is the video

AndrewSB commented 1 year ago

let me know what it is, if you figure it out! i'm curious too

dmrschmidt commented 1 year ago

Thanks! If I google ytdl it's giving me tons of things that don't look like what you probably used. Do you have a URL?

AndrewSB commented 1 year ago

found the audio file i was testing with!

https://github.com/dmrschmidt/DSWaveformImage/assets/3814772/dbd1beda-5d95-4646-889b-61aaa6520db0

dmrschmidt commented 1 year ago

Thanks for sharing. So I had another look at it. I'm not intimately familiar enough with the mp4 format to figure out what exactly the problem is with the file, but it definitely has a defect, which passing it to multiple other audio apps confirmed.

So I'll just file this as "mysterious bug in ytdl" and close this issue. Thanks for your help!