Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Jul 2001 14:18:18 -0600 (MDT)
From:      Mike Holling <myke@ees.com>
To:        Christoph Kukulies <kuku@gilberto.physik.rwth-aachen.de>
Cc:        multimedia@FreeBSD.ORG
Subject:   Re: writing a sine to a .wav
Message-ID:  <Pine.BSF.4.21.0107181410590.345-100000@av.fks.lan>
In-Reply-To: <200107181542.f6IFgtl63993@gilberto.physik.rwth-aachen.de>

next in thread | previous in thread | raw e-mail | index | archive | help
> Does anyone know of a function (API) or whatever that allows for generating
> .wav data (or .mp3) data out of mathematical functions like sin(x),sin(2x),
> sin(3x) etc.

Here's a quick and dirty perl script to generate a tone.  Just direct the
output to /dev/dsp, which should be set for 8khz mono 8 bit by default:

perl wave.pl > /dev/dsp

You can use sox to convert the output to a .wav file.

#!/usr/bin/perl
# Generate a sine wave at some frequency

$rate="8196";
$pi=3.141;
$seconds=5;
$length= $rate*$seconds;
foreach $f (220) {
    $period= $rate/$f;
    $glob=2*$pi/$period;
    for($s=1;$s<$length;$s++) {
        $out=sin($s*$glob)*127+128;
        printf("%c",$out);
    }
}


- Mike



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-multimedia" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0107181410590.345-100000>