From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([69.77.167.62] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1JI8a3-0008Ff-DB for garchives@archives.gentoo.org; Thu, 24 Jan 2008 20:21:47 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 494CAE070F; Thu, 24 Jan 2008 20:21:17 +0000 (UTC) Received: from sentinel.math.Princeton.EDU (sentinel.math.Princeton.EDU [128.112.16.31]) by pigeon.gentoo.org (Postfix) with ESMTP id 027C8E070F for ; Thu, 24 Jan 2008 20:21:17 +0000 (UTC) Received: from sentinel.math.Princeton.EDU (localhost.localdomain [127.0.0.1]) by sentinel.math.Princeton.EDU (Postfix) with ESMTP id D94F729809B for ; Thu, 24 Jan 2008 15:21:15 -0500 (EST) X-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,DK_POLICY_SIGNSOME,SPF_HELO_PASS X-Spam-Check-By: sentinel.math.Princeton.EDU Received: from localhost.localdomain (HELO sentinel.math.Princeton.EDU) (127.0.0.1) by sentinel.math.Princeton.EDU (qpsmtpd/0.32) with ESMTP; Thu, 24 Jan 2008 15:21:09 -0500 Received: from fine408a.math.Princeton.EDU (fine408a.math.Princeton.EDU [128.112.16.63]) by sentinel.math.Princeton.EDU (Postfix) with ESMTP for ; Thu, 24 Jan 2008 15:21:09 -0500 (EST) Received: from fine408a.math.Princeton.EDU (localhost.localdomain [127.0.0.1]) by fine408a.math.Princeton.EDU (8.13.8/8.13.8) with ESMTP id m0OKL9tw010668 for ; Thu, 24 Jan 2008 15:21:09 -0500 Received: (from wwong@localhost) by fine408a.math.Princeton.EDU (8.13.8/8.13.8/Submit) id m0OKL9Ct010665 for gentoo-user@lists.gentoo.org; Thu, 24 Jan 2008 15:21:09 -0500 X-Authentication-Warning: fine408a.math.Princeton.EDU: wwong set sender to wwong@princeton.edu using -f Date: Thu, 24 Jan 2008 15:21:09 -0500 From: Willie Wong To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] tone generator Message-ID: <20080124202109.GA10245@math.princeton.edu> References: <938704.35667.qm@web31715.mail.mud.yahoo.com> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <938704.35667.qm@web31715.mail.mud.yahoo.com> User-Agent: Mutt/1.4.2.2i X-Archives-Salt: 1d28887f-ff1c-41e9-b820-6c9817f0c7e9 X-Archives-Hash: b95819f425383db92d87d0b628f9e07b On Thu, Jan 24, 2008 at 11:41:04AM -0800, maxim wexler wrote: > Anybody know of a gentoo/linux tone generator that > will output test tones, sine waves, triangle waves and > the like. > > Prefer command line/ncurses. > One of my friends coded something like this once as a plug-in for XMMS. Can't seem to find it now. Perhaps you'd have better luck than I. On the other hand, a little bit of C++ should be fairly easy. First you need the 'play' program from sox. 'play' can play files in the 'raw' format, which is just a stream of words that gives the amplitude of the waveform. For example play -t raw -s l -f s -c 1 -r 30000 - takes as input stdin, plays mono channel sound from a stream that is signed-linear, 300000 hertz sample rate, and with amplitude described by 32 bit long word. Next you just need a waveform generator. A C++ snipplet from something I cobbled together several years ago (yes yes, my coding practice can stand much improvement, so sue me) #include #include #include int main() { int rate = 30000; int coramp = 0xCEFFFFF; int tempamp=0; float totalamp=0; int f_count; while(1) for(f_count=0; f_count < rate; f_count++) { totalamp=sinf( ((float)f_count) * 440 / rate * 2 * M_PI); tempamp = (int) (coramp * totalamp); printf("%c%c%c%c%c%c%c%c", (char) (tempamp), (char) (tempamp >> 8), (char) (tempamp >> 16), (char) (tempamp >> 24), (char) (tempamp), (char) (tempamp >> 8), (char) (tempamp >> 16), (char) (tempamp >> 24)); } return 0; } Yes, it is an infinite loop. The sinf makes it a sine wave. You can code your own triangle wave. THe 440 makes it output A-440. It is the frequency. coramp is an amplifying factor. compile it, run it like ./a.out | play -t raw -s l -f s -c 1 -r 30000 - And you should get A-440 out of your speakers. W -- Willie W. Wong wwong@math.princeton.edu 408 Fine Hall, Department of Mathematics, Princeton University, Princeton A mathematician's reputation rests on the number of bad proofs he has given. -- gentoo-user@lists.gentoo.org mailing list