Jeremiah Dodds <apatheticagnostic / gmail.com> wrote:
> Thanks William and Hans. William, if I was on windows that probably 
> would've helped.
> 
> Hans, I don't necessarily need to save to file - it could be handy 
> though. I'll check out ruby-audio.
> 
> I really need to learn not to post these help requests when I'm 
> sleep-deprived - I leave out vital information like what exactly I want 
> to do, and what OS I'm running on.
> 
> I want to generate the sound real-time - so I guess I'll need to figure 
> out how to send it to /dev/dsp or /dev/audio or whatnot.

Something like this might work on *unix :

------------------------------------------------------------

Samplerate = 8000

def beep(frequency, amplitude, duration)

        f = File.open("/dev/dsp", "w")

        wave = ""

        0.step(duration, 1.0/Samplerate) do |t|
                y = Math.sin(t * frequency) * 50 + 127;
                wave << y.to_i.chr
        end

        f.write(wave)
end     

beep(2000, 100, 1)

------------------------------------------------------------

this code assumes the default settings of your soundcard are 8000 hz, 8
bits samples, signed, one channel. If you want more control over these
values, you will have to do fiddling with OSS IOCTL's or alsa libraries.

-- 
:wq
^X^Cy^K^X^C^C^C^C