Re: [OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?)
Re: [OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?)
- Subject: Re: [OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?)
- From: "Hans Kuder" <email@hidden>
- Date: Mon, 25 Jun 2007 14:45:55 -0400
On 6/25/07, Alastair Houghton <email@hidden> wrote:
On 25 Jun 2007, at 18:29, I. Savant wrote:
> On 6/24/07, Hans Kuder <email@hidden> wrote:
>
> I've never personally plotted a waveform however, it occurs to me
> you would want to scale your plot. Your layers should all have a sense
> of scale (at normal zoom, 1 sample == 1 pixel, or something sane).
> When zoomed out, your scale would change (10 samples == 1 pixel) so
> you plot fewer points (samples) ... only every 10th sample
No, no, no! :-) You *can't* do that, as I already pointed out.
You'll display totally the wrong thing if you pick every Nth sample.
I've lost count of the number of freeware/shareware audio apps
(across various systems) that do that.
> or the mean of those 10 samples.
Neither would this work.
Both of those approaches will radically change the shape of the
waveform as you zoom in and out, and maybe also as you scroll
depending on just how you implement it. To see why, imagine you have
a waveform like this:
xxxxx xxxxx
xx xx xx xx
______x_________x___________x_________x______
x x x x
xx xx xx xx
xxx xxxxx xxx
Now let's say I choose every 22nd sample for some hypothetical zoom
level. So my signal looks like this:
________________________________________
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
and that line of samples might move up and down depending on where I
scroll to (it does in some programs I've seen). You can get many
other similarly unpleasant effects this way (I chose an extreme
example deliberately).
Choosing a mean is even worse, so *please* don't do that if you're
ever writing an audio application. You need to do some statistics of
some sort on the samples and plot the results; "minimaxing" (finding
the lowest and highest sample in the range corresponding to each
horizontal point) and filling between them is the simplest approach
that produces credible results, but as someone else pointed out,
there are other approaches that you might take if you have the
inclination.
> Also, for efficiency, only plot the samples that are visible
> on-screen (and the one before and the one after to allow lines to the
> previous-and-next clipped points).
Yes, that's certainly a good idea. It'd be crazy to plot the entire
waveform each time, though if you're buffering it to a bitmap then
you might take that approach.
Kind regards,
Alastair.
--
http://alastairs-place.net
Yes, if we were on the CoreAudio list we'd have a dozen people shouting
about how this is essentially the same concept as frequency-domain aliasing.
"Zooming out" on a waveform is a resampling process, and if you're not
careful about how you do it you'll get some nasty artifacts.
I have a pretty good fix on how to handle these sorts of data- and
perceptual-level operations, but it would be nice to find a drawing
operation that is more efficient/elegant than drawing an NSBezierPath
through each **perceptual** sample. From what you and Uli have said, it
looks like the best process is to start simple and optimize.
One other thought - rather than drawing one or a few paths horizontally
through each (on-screen) sample, what if I drew each (on-screen) sample as
its own vertical line with height equal to amplitude? This would essentially
be trading one complex path for hundreds of very simple paths. Can anyone
comment on the performance advantages or disadvantages of this?
Thanks,
Hans
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Best drawing technology for audio waveforms, envelopes, etc.? (From: "Hans Kuder" <email@hidden>) |
| >Re: Best drawing technology for audio waveforms, envelopes, etc.? (From: Alastair Houghton <email@hidden>) |
| >Re: Best drawing technology for audio waveforms, envelopes, etc.? (From: "Hans Kuder" <email@hidden>) |
| >Re: Best drawing technology for audio waveforms, envelopes, etc.? (From: "I. Savant" <email@hidden>) |
| >[OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?) (From: Alastair Houghton <email@hidden>) |