* Playing a sine wave
@ 1999-05-12 1:22 Hrafnkell Eiriksson
1999-05-12 8:56 ` Hannu Savolainen
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Hrafnkell Eiriksson @ 1999-05-12 1:22 UTC (permalink / raw)
To: linux-sound
Hi
Is it possible to use the sequencer stuff in the OSS sound driver
to let the sound card play a sine wave of a given frequency?
Any pointers to info on how to do that if it is possible?
--
//-----------------------//-------------------------------------------------
// Hrafnkell Eiriksson // Student of Computer- and Electrical engineering
// hkelle@rhi.hi.is // at the Univeristy of Iceland
// // "Blessed are they who go around in circles,
// Finger for PGP key // for they shall be known as Wheels"
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Playing a sine wave 1999-05-12 1:22 Playing a sine wave Hrafnkell Eiriksson @ 1999-05-12 8:56 ` Hannu Savolainen 1999-05-12 17:16 ` Eric Mitchell ` (4 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: Hannu Savolainen @ 1999-05-12 8:56 UTC (permalink / raw) To: linux-sound On Wed, 12 May 1999, Hrafnkell Eiriksson wrote: > Hi > > Is it possible to use the sequencer stuff in the OSS sound driver > to let the sound card play a sine wave of a given frequency? In theory it's possible to play sine waves using the OPL3 FM synth chip available on most older (ISA) soundcards. However this is very inpractical way. A much easier way is using /dev/dsp. You only need to construct few cycles of sine wave at given frequency to a buffer. Then just keep writing this buffer to /dev/dsp as many times as you need. In fact it may even be possible that somebody has already written this kind of app (look at ftp://sunsite.unc.edu/pub/Linux/apps/sound). Best regards, Hannu ----- Hannu Savolainen (hannu@opensound.com) http://www.opensound.com (Open Sound System (OSS)) http://www.compusonic.fi (Finnish OSS pages) ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Playing a sine wave 1999-05-12 1:22 Playing a sine wave Hrafnkell Eiriksson 1999-05-12 8:56 ` Hannu Savolainen @ 1999-05-12 17:16 ` Eric Mitchell 1999-05-12 17:59 ` Itai Nahshon ` (3 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: Eric Mitchell @ 1999-05-12 17:16 UTC (permalink / raw) To: linux-sound Hannu Savolainen wrote: > > On Wed, 12 May 1999, Hrafnkell Eiriksson wrote: > > > Hi > > > > Is it possible to use the sequencer stuff in the OSS sound driver > > to let the sound card play a sine wave of a given frequency? > In theory it's possible to play sine waves using the OPL3 FM synth chip > available on most older (ISA) soundcards. However this is very inpractical > way. > > A much easier way is using /dev/dsp. You only need to construct few cycles > of sine wave at given frequency to a buffer. Then just keep writing this > buffer to /dev/dsp as many times as you need. In fact it may even be > possible that somebody has already written this kind of app (look at > ftp://sunsite.unc.edu/pub/Linux/apps/sound). The source for esound (http://www.tux.org/~ricdude/EsounD.html) includes the code necessary to do this in the file, esd.c. I have reproduced it below for your convenience: Feel free to ask if you have any questions on the code. buf is the buffer to store the audio data in, format determines whether to use 8bit unsigned or 16bit signed data, magl is the magnitude for the left side, magr is the magnitude for the right side, freq is the desired frequency in Hertz, speed is the playback rate of the audio device, length is the number of samples to be stored in buf, offset is used to get a perfect sine waves, buffer after buffer, by setting offset to the product of the number of buffers already played and the length of the buffer in samples. void set_audio_buffer( void *buf, esd_format_t format, int magl, int magr, int freq, int speed, int length, long offset ) { int i; float sample; float kf = 2.0 * 3.14 * (float)freq / (float)speed; unsigned char *uc_buf = (unsigned char *)buf; signed short *ss_buf = (signed short *)buf; /* printf( "fmt=%d, ml=%d, mr=%d, freq=%d, speed=%d, len=%ld\n", format, magl, magr, freq, speed, length ); */ switch ( format & ESD_MASK_BITS ) { case ESD_BITS8: for ( i = 0 ; i < length ; i+=2 ) { sample = sin( (float)(i+offset) * kf ); uc_buf[i] = 127 + magl * sample; uc_buf[i+1] = 127 + magr * sample; } break; case ESD_BITS16: /* assume same endian */ for ( i = 0 ; i < length ; i+=2 ) { sample = sin( (float)(i+offset) * kf ); ss_buf[i] = magl * sample; ss_buf[i+1] = magr * sample; } break; default: fprintf( stderr, "unsupported format for set_audio_buffer: 0x%08x\n", format ); exit( 1 ); } return; } > Best regards, > > Hannu > ----- > Hannu Savolainen (hannu@opensound.com) > http://www.opensound.com (Open Sound System (OSS)) > http://www.compusonic.fi (Finnish OSS pages) -- +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+ | Eric B. Mitchell mailto:emitchell@altaira.com | | tel: (301) 809 - 3534 Altair Aerospace Corporation | | tel: (800) 7 - ALTAIR 4201 Northview Dr. Suite 410 | | fax: (301) 805 - 8122 Bowie, MD 20716 | +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+ ,___ /"\ / o=\ /"""---==/ / \_/ \__/ ---==/ | //\ || /""TT""/ //\ || ||""\ | // \ || || // \ || ||__/ | //--=\ |L--/ || //--=\ || || "=, \ ---==/ \____---==/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Playing a sine wave 1999-05-12 1:22 Playing a sine wave Hrafnkell Eiriksson 1999-05-12 8:56 ` Hannu Savolainen 1999-05-12 17:16 ` Eric Mitchell @ 1999-05-12 17:59 ` Itai Nahshon 1999-05-12 20:22 ` Cornelius Creedon ` (2 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: Itai Nahshon @ 1999-05-12 17:59 UTC (permalink / raw) To: linux-sound >> Is it possible to use the sequencer stuff in the OSS sound driver >> to let the sound card play a sine wave of a given frequency? >In theory it's possible to play sine waves using the OPL3 FM synth chip >available on most older (ISA) soundcards. However this is very inpractical >way. > >A much easier way is using /dev/dsp. You only need to construct few cycles >of sine wave at given frequency to a buffer. Then just keep writing this >buffer to /dev/dsp as many times as you need. In fact it may even be >possible that somebody has already written this kind of app (look at >ftp://sunsite.unc.edu/pub/Linux/apps/sound). See http://metalab.unc.edu/pub/Linux/apps/sound/dtmf-dial-0.2.tar.gz It combines two sine waves and outputs to /dev/dsp. You are welcome to hack on it. Internally it has the function to produce sine waves at any integer frequency and sampling rate. Itai ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Playing a sine wave 1999-05-12 1:22 Playing a sine wave Hrafnkell Eiriksson ` (2 preceding siblings ...) 1999-05-12 17:59 ` Itai Nahshon @ 1999-05-12 20:22 ` Cornelius Creedon 1999-05-12 21:44 ` Jeff Tranter 1999-05-13 3:25 ` Hrafnkell Eiriksson 5 siblings, 0 replies; 7+ messages in thread From: Cornelius Creedon @ 1999-05-12 20:22 UTC (permalink / raw) To: linux-sound hm. there is a package called siggen to do such things, dont know which devices it uses though... -cc On Wed, 12 May 1999, Hrafnkell Eiriksson wrote: > Hi > > Is it possible to use the sequencer stuff in the OSS sound driver > to let the sound card play a sine wave of a given frequency? > Any pointers to info on how to do that if it is possible? > > -- > //-----------------------//------------------------------------------------- > // Hrafnkell Eiriksson // Student of Computer- and Electrical engineering > // hkelle@rhi.hi.is // at the Univeristy of Iceland > // // "Blessed are they who go around in circles, > // Finger for PGP key // for they shall be known as Wheels" > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Playing a sine wave 1999-05-12 1:22 Playing a sine wave Hrafnkell Eiriksson ` (3 preceding siblings ...) 1999-05-12 20:22 ` Cornelius Creedon @ 1999-05-12 21:44 ` Jeff Tranter 1999-05-13 3:25 ` Hrafnkell Eiriksson 5 siblings, 0 replies; 7+ messages in thread From: Jeff Tranter @ 1999-05-12 21:44 UTC (permalink / raw) To: linux-sound On Wed, 12 May 1999, Hannu Savolainen wrote: > A much easier way is using /dev/dsp. You only need to construct few cycles > of sine wave at given frequency to a buffer. Then just keep writing this > buffer to /dev/dsp as many times as you need. In fact it may even be > possible that somebody has already written this kind of app (look at > ftp://sunsite.unc.edu/pub/Linux/apps/sound). Yes, I wrote such a program using /dev/dsp. Look for "wave" on sunsite.unc.edu, probably in the directory mentioned above unless they moved it. It can do sine, square, triangle, and ramp waveforms, in stereo. -- Jeff Tranter (mailto:tranter@pobox.com http://www.pobox.com/~tranter) Currently running Linux 2.2.7 Learn more at http://www.linux.org ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Playing a sine wave 1999-05-12 1:22 Playing a sine wave Hrafnkell Eiriksson ` (4 preceding siblings ...) 1999-05-12 21:44 ` Jeff Tranter @ 1999-05-13 3:25 ` Hrafnkell Eiriksson 5 siblings, 0 replies; 7+ messages in thread From: Hrafnkell Eiriksson @ 1999-05-13 3:25 UTC (permalink / raw) To: linux-sound On 12. May 1999, Hannu Savolainen wrote: > A much easier way is using /dev/dsp. You only need to construct few cycles > of sine wave at given frequency to a buffer. Then just keep writing this > buffer to /dev/dsp as many times as you need. In fact it may even be > possible that somebody has already written this kind of app (look at > ftp://sunsite.unc.edu/pub/Linux/apps/sound). What about creating a patch with the sine wave and use the wavetable stuff to play it. Thay way the wavetable could change the playback frequency etc. (Please note that I hardly know what a wavetable is nor what it can do :) -- //-----------------------//------------------------------------------------- // Hrafnkell Eiriksson // Student of Computer- and Electrical engineering // hkelle@rhi.hi.is // at the Univeristy of Iceland // // "Blessed are they who go around in circles, // Finger for PGP key // for they shall be known as Wheels" ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1999-05-13 3:25 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 1999-05-12 1:22 Playing a sine wave Hrafnkell Eiriksson 1999-05-12 8:56 ` Hannu Savolainen 1999-05-12 17:16 ` Eric Mitchell 1999-05-12 17:59 ` Itai Nahshon 1999-05-12 20:22 ` Cornelius Creedon 1999-05-12 21:44 ` Jeff Tranter 1999-05-13 3:25 ` Hrafnkell Eiriksson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox