From owner-freebsd-multimedia Wed Jul 18 13:17:56 2001 Delivered-To: freebsd-multimedia@freebsd.org Received: from av.fks.lan (tc4-1-13.cyberport.net [216.166.149.108]) by hub.freebsd.org (Postfix) with ESMTP id CC69637B401 for ; Wed, 18 Jul 2001 13:17:51 -0700 (PDT) (envelope-from myke@ees.com) Received: from localhost (myke@localhost) by av.fks.lan (8.11.3/8.11.1) with ESMTP id f6IKIJa41917; Wed, 18 Jul 2001 14:18:20 -0600 (MDT) (envelope-from myke@ees.com) X-Authentication-Warning: av.fks.lan: myke owned process doing -bs Date: Wed, 18 Jul 2001 14:18:18 -0600 (MDT) From: Mike Holling X-Sender: myke@av.fks.lan To: Christoph Kukulies Cc: multimedia@FreeBSD.ORG Subject: Re: writing a sine to a .wav In-Reply-To: <200107181542.f6IFgtl63993@gilberto.physik.rwth-aachen.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-multimedia@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > 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