Re: Peak and averagePowerForChannel are nice, but what about the actual current power?
Re: Peak and averagePowerForChannel are nice, but what about the actual current power?
- Subject: Re: Peak and averagePowerForChannel are nice, but what about the actual current power?
- From: Hamish Allan <email@hidden>
- Date: Sat, 16 May 2009 14:00:38 +0100
On Sat, May 16, 2009 at 5:39 AM, Ochen Kaylan <email@hidden> wrote:
> Why the need: There are a few different reasons I need the instantaneous
> power. The easiest one to explain is waveforms. You can't draw waveforms
> with only average or peak power.
The way most audio editors draw waveforms is to determine the maximum
and minimum peaks of the waveform for the time period covered by each
pixel, something like:
// Assume samples[] of CGFloats between -1.0 and 1.0 with length numSamples
// Assume numHorizontalPixels
CGFloat samplesPerPixel = numSamples / numHorizontalPixels;
CGFloat sampleOffset = 0.0;
for (horizontalOffset = 0; horizontalOffset < numHorizontalPixels;
++horizontalOffset)
{
NSInteger sample = sampleOffset, endSample = sample + round(samplesPerPixel);
if (endSample > numSamples) endSample = numSamples;
CGFloat maxHeight = -1.0, minHeight = 1.0;
while (s < endSample)
{
CGFloat height = samples[s++];
if (height > maxHeight) maxHeight = height;
if (height < minHeight) minHeight = height;
}
// insert code for drawing vertical line between minHeight and
maxHeight at horizontalOffset
sample += samplesPerPixel;
}
> If the audio is 10 minutes long, but the
> waveform is only going to be 100 pixels wide, there's no need to have the
> instantaneous power of every sample. A few a second is plenty for that
> scenario.
You wrote previously: "Right, but the problem is the falloff period.
If the first sample is -10db and the second sample is 0db, the average
called on sample one will be -10db, but the average called on sample
two will be something shy of -5db (the average minus the falloff
increment.) Unless the falloff period is less than the frequency of
the calls, the average will always be different than the
instantaneous, whatever the granularity is."
But now you're proposing to arbitrarily choose either the 0db or the
-10db. How can that possibly be an improvement?
To look at it another way: think of the number of zero crossings there
are in any given wave. If every thousandth sample happens to be on a
zero crossing, would you consider those samples representative of the
waveform?
> Do you have any suggestions on how a waveform can be drawn without
> digging into the PCM data, mapping the entire file, averaging the
> instantaneous powers to fit the display needs, and rendering it out? I'm
> fine doing it that way, but that's not easy on the processor, nor is it
> terrible quick. Pulling meter data from an AVAudioPlayer is a snap, if only
> instantaneous power was retrievable.
If you think digging into the PCM data isn't quick, think again about
what you're trying to do. If the audio is 10 minutes long, it'll take
you 10 minutes to draw the waveform.
Hamish
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Peak and averagePowerForChannel are nice, but what about the actual current power? (From: Ochen Kaylan <email@hidden>) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: Ochen Kaylan <email@hidden>) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: Hamish Allan <email@hidden>) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: email@hidden) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: Hamish Allan <email@hidden>) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: email@hidden) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: Hamish Allan <email@hidden>) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: email@hidden) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: Brian Willoughby <email@hidden>) |
| >Re: Peak and averagePowerForChannel are nice, but what about the actual current power? (From: Ochen Kaylan <email@hidden>) |