[OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?)
[OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?)
- Subject: [OT] Don't draw every 10th sample(!) (Was Re: Best drawing technology for audio waveforms, envelopes, etc.?)
- From: Alastair Houghton <email@hidden>
- Date: Mon, 25 Jun 2007 19:14:12 +0100
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
_______________________________________________
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