Malcolm McLean wrote On 07/19/07 18:14,:
(... *Still* declining to defend his claim that strstr()
and its caller "talk to each other" with integers ...)
"Eric Sosman" <Er*********@sun.comwrote in message
news:1184880234.495526@news1nwk...
> And what language do you propose to use to manipulate
those samples? Not 64-bit-only C, that's for sure. Here's
my way of reducing the volume of one sample:
uint16_t *sample = ...;
*sample -= *sample / 10;
... and here's what you want me to do instead:
/* 8-bit (?) */ unsigned char *samplebytes = ...;
/* 64-bit */ unsigned int sample;
sample = samplebytes[0] + (samplebytes[1] << 8);
sample -= sample / 10;
samplebytes[0] = sample;
samplebytes[1] = sample >8;
It won't wash, Malcolm. It wouldn't wash even if Herakles
ran a couple rivers over it.
/* 64 bit int only code */
void reduce10(unsigned char *audio, int N)
{
int i;
int sample;
for(i=0;i<N;i++)
{
sample = get16(audio + i * 2);
sample -= sample/10;
put16(audio + i * 2, sample);
}
}
#define get16(ptr) ( ( (int)ptr[0] << 8) + ptr[1])
#define put16(ptr, x) do{ptr[0] = (x >>8) & 0xFF; ptr[1] = x &
0xFF;}while(0)
The last macro is a bit of nuisance, I'd be the first to agree. You'll use
these all the time when writing samples to and from the buffer. It might
just make a difference for such a simple manipulation as knocking off 10%.
Do you think you *improve* things by taking one simple
line of code and obfuscating it with an intermediate variable
and two macros (both unsafe from side-effects)?
Compare
void up10(uint16_t *sample, size_t N)
{
size_t i;
for(i=0;i<N;i++)
sample[i] += sample[i]/10;
}
Superfically this looks OK, but here are a few ways to break it.
up10(boomingadvert, N);
If you're worried about clipping, observe that using
64 bits won't fix it. All it'll do is postpone the clip
until the point when the samples are chopped to 16 bits
for burning to the CD. (Or do you propose that CDs should
record 64-bit samples, too? You want to cut the playing
time to from 80 to 20 minutes? One LP side = 2 CD64's?)
I'll admit one small advantage: By using lots of extra
bits the sample would survive amplification followed by a
subsequent diminution: up by ten percent and then back down
by fifty wouldn't clip. But that's not how you *do* sound
editing: You boost the volume, say "Oops! It clipped," hit
the Undo button, and boost again by a smaller amount.
up10(sample, N - window);
I don't understand what breakage you suggest here,
nor how 64-bit ints would cure it.
short *samples; /* from your colleague Fred */
up10((uint16_t *) samples, N);
Fred gave me the wrong stuff. If he gave the same
wrong stuff to you, you'd be equally in the soup.
--
Er*********@sun.com