Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Generate a tone using ruby?

Reply
Thread Tools

Generate a tone using ruby?

 
 
Jeremiah Dodds
Guest
Posts: n/a
 
      07-26-2006
Hey everyone, I'm looking for a simple way to generate a tone in ruby .
. any suggestions?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
William James
Guest
Posts: n/a
 
      07-26-2006

Jeremiah Dodds wrote:
> Hey everyone, I'm looking for a simple way to generate a tone in ruby .
> . any suggestions?
>
> --
> Posted via http://www.ruby-forum.com/.


print "\a"

 
Reply With Quote
 
 
 
 
Jeremiah Dodds
Guest
Posts: n/a
 
      07-26-2006
William James wrote:
> Jeremiah Dodds wrote:
>> Hey everyone, I'm looking for a simple way to generate a tone in ruby .
>> . any suggestions?
>>
>> --
>> Posted via http://www.ruby-forum.com/.

>
> print "\a"


Well, yeah sure. What I'd like to be able to do is generate a tone of a
specific frequency. Like an A note, or a D sharp.


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
William James
Guest
Posts: n/a
 
      07-27-2006

Jeremiah Dodds wrote:
> William James wrote:
> > Jeremiah Dodds wrote:
> >> Hey everyone, I'm looking for a simple way to generate a tone in ruby .
> >> . any suggestions?
> >>
> >> --
> >> Posted via http://www.ruby-forum.com/.

> >
> > print "\a"

>
> Well, yeah sure. What I'd like to be able to do is generate a tone of a
> specific frequency. Like an A note, or a D sharp.
>
>
> --
> Posted via http://www.ruby-forum.com/.


require "Win32API"
Beep = Win32API.new("kernel32", "Beep", ["I", "I"], 'v')
def beep freq, duration
Beep.call(freq, duration)
end

beep 600, 400

 
Reply With Quote
 
Hans Fugal
Guest
Posts: n/a
 
      07-27-2006
Jeremiah Dodds wrote:
> William James wrote:
>> Jeremiah Dodds wrote:
>>> Hey everyone, I'm looking for a simple way to generate a tone in ruby .
>>> . any suggestions?
>>>
>>> --
>>> Posted via http://www.ruby-forum.com/.

>> print "\a"

>
> Well, yeah sure. What I'd like to be able to do is generate a tone of a
> specific frequency. Like an A note, or a D sharp.
>
>


I presume you want to play it out the speaker? I'm not sure if there's a
portable way to do that, but in most unices it would be a matter of
sending the audio data for that frequency to a special file, e.g.
/dev/dsp. Or perhaps you want to save to a file. In either case, esp.
the latter, ruby/audio would be worth a look.

http://hans.fugal.net/src/ruby-audio/
 
Reply With Quote
 
Jeremiah Dodds
Guest
Posts: n/a
 
      07-27-2006
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.

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Ico
Guest
Posts: n/a
 
      07-27-2006
Jeremiah Dodds <> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fritz!box help required - error tone when using voip Jim UK VOIP 9 07-03-2007 08:41 PM
voipfone + Draytek 2600V: Keypad tone sent twice (using conferencingsystem...) damn-it UK VOIP 0 02-19-2007 10:51 PM
How to generate variable labels for same component within a generate loop Weng Tianxiang VHDL 5 02-16-2006 01:45 PM
How to generate ringback tone on AS5300 ? Ciscokid Cisco 1 12-29-2003 05:49 AM
How to generate ringback tone on a AS5300 ? Ciscokid VOIP 1 12-16-2003 02:26 PM



Advertisments