[flac-dev] Regain play analysis patches
Earl Chew
earl_chew at yahoo.com
Mon Feb 20 07:40:46 PST 2012
Erik,
It turns out bc(1) is too accurate, and a little slow, for this purpose.
I've switched to using awk(1) which uses floating point.
Do you feel I need to test for the presence of awk(1) ?
It is specified as one of the standard commands in the LSB :
http://refspecs.linuxfoundation.org/LSB_1.0.0/gLSB/command.html
Earl
awk -- '
BEGIN {
samplerate = 8000;
tone = 1000;
duration = 1;
bitspersample = 24;
samplemidpoint = lshift(1, (bitspersample-1));
samplerange = samplemidpoint - 1;
pi = 4 * atan2(1,1);
for (ix = 0; ix < duration * samplerate; ++ix) {
sample = sin(2 * pi * tone * ix / samplerate);
sample *= samplerange;
sample += samplemidpoint;
sample = int(sample);
for (bx = 0; bx < bitspersample/8; ++bx) {
byte[bx] = sample % 256;
sample /= 256;
}
while (bx--) {
printf("%c", byte[bx]);
}
}
}' /dev/null
----- Original Message -----
From: Erik de Castro Lopo <mle+la at mega-nerd.com>
To: flac-dev at xiph.org
Cc: Earl Chew <earl_chew at yahoo.com>
Sent: Friday, February 17, 2012 3:30:00 PM
Subject: Re: [flac-dev] Regain play analysis patches
Earl Chew wrote:
> I'm a little reluctant to introduce another compiled program when there are
> so many other options that will work well enough out of the box.
>
> Here are two ideas:
>
> 1. Use bc(1) to compute the raw samples
> 2. Use perl(1) to compute the raw samples
>
> To generate raw unsigned samples using bc(1) for example:
>
> samplerate = 1000;
> duration = 2;
> bitspersample = 24;
>
> samplerange = 2 ^ (bitspersample-1) - 1;
> samplemidpoint = 2 ^ (bitspersample-1);
>
> pi = 4 * a(1);
>
> scale = 18;
> obase = 16;
>
> for (ix = 0; ix < duration * samplerate; ++ix) {
> sample = samplemidpoint + samplerange * s(2 * pi * ix / samplerate);
> s = scale;
> scale = 0;
> sample /= 1;
> sample;
> scale = s;
> }
>
>
>
> Are you ok with bc(1) ?
Yes, bc looks quite nice.
As Richard Ash mentioned, the test should detect the presence of bc
and it its not available, print a nice big warning, and exit the
script with an error code of 0. If bc is available, run the tests
and any failure should result in the script exiting with a non-zero
error code.
Cheers,
Erik
--
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
More information about the flac-dev
mailing list