Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > sleep 0.2 acts more like sleep 1

Reply
Thread Tools

sleep 0.2 acts more like sleep 1

 
 
Richard
Guest
Posts: n/a
 
      05-13-2007
Hi,

I wrote my private alarm_clock using repeated .wav files to announce
that (1) the clock started and (2) the specified time had elapsed.

For (1), which is too protracted:
3.times do |i|
system "wv_player.exe", DING
sleep 0.2i
end

For (2), which works fine for my purposes:
while true
system "wv_player.exe", ALARM_BELL
sleep 1
end

The two constants are defined:
ALARM_BELL = ENV["WINDIR"] + "\\Media\\chimes.wav"
DING = ENV["WINDIR"] + "\\Media\\ding.wav"

Is there away to play a few DINGs faster? If not, I'll post on a
Windows site to get a suggestion for something better to feed to
Windows Wave Player or maybe Windows Media Player.

I'm running WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.6.

TIA,
Richard

 
Reply With Quote
 
 
 
 
Gordon Thiesfeld
Guest
Posts: n/a
 
      05-13-2007
Have a look at the win32-sound gem. It may already be installed, if
you're using the one-click installer.

 
Reply With Quote
 
 
 
 
Marcin Raczkowski
Guest
Posts: n/a
 
      05-13-2007
On Sunday 13 May 2007 14:40, Gordon Thiesfeld wrote:
> Have a look at the win32-sound gem. It may already be installed, if
> you're using the one-click installer.


first of all running external program (especially so heavy) is couing that=
=20
delay

easiest (and most ugly) solution would be=20
3.times do |i|
=A0=A0=A0=A0=A0=A0=A0Thread.new{system("wv_player. exe", DING)}
=A0=A0=A0=A0=A0=A0=A0=A0sleep 0.2i
end


=2D-=20
Marcin Raczkowski
=2D--
=46riends teach what you should know
Enemies Teach what you have to know

 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      05-15-2007
Hi Marcin,

> first of all running external program (especially so heavy) is couing that
> delay


I agree that making system calls to Windows is probably the key
culprit.

> easiest (and most ugly) solution would be
> 3.times do |i|
> Thread.new{system("wv_player.exe", DING)}
> sleep 0.2i
> end


I agree that threading is a key to getting sub-second responses, if
indeed it's possible with wv_player having to access the file system
three times (I doubt wv-player would cache the selection.)

I tried your introduction of threading, but it produced the sane
result I've been getting (after removing the "i" at the end of the
sleep statement.)

I outlined in a previous response to you (that was really intended for
Gordon) about what I thought I'd have to do to get sub-second
response. I also mentioned that I didn't think my application merited
all that work.

Thanks for your response. I had never looked at threading in Ruby,
so I appreciated giving it a try.

Best wishes,
Richard

 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      05-15-2007
Hi Gordon,

Following is the original text I prepared in response to you. I made
mistakes in posting this thing, so you might see other versions of it
popping up. Please ignore them and excuse me for my sloppiness.

> Have a look at the win32-sound gem.


Thanks for that suggestion.

> It may already be installed, if
> you're using the one-click installer.


It was not already installed, although I think I used one-click (a
long time ago). Downloading/installing it worked fine, however.

Unfortunately, it seemed to offer the same performance as my system
call to "wv_player.exe". I suspect that win32-sound is coded in terms
of the same system call (but I'm too lazy to look.)

I further suspect that to achieve my performance goal, I'd have to do
Win32 programming in C++ to create a thread that, with parameters for
the wave-file-name, repetition-count and sleep-time in milliseconds,
calls wm_player in a loop that honors arguments supplied by the Ruby
script. That's too much work, so I think I'll live with the
limitation I'm experiencing.

Nevertheless, I'm grateful for you taking the trouble to respond to
my question (and offering sound advice).

Best wishes,
Richard


On May 13, 10:37 am, Gordon Thiesfeld <gthiesf...@gmail.com> wrote:
> Have a look at the win32-sound gem. It may already be installed, if
> you're using the one-click installer.



 
Reply With Quote
 
Gordon Thiesfeld
Guest
Posts: n/a
 
      05-15-2007
If I understand your question, you want to play a wav file repeatedly,
as quickly as possible. This code is from the example file in the
win32-sound gem. It plays chimes.wav 5 times in 3 seconds on both of
my XP machines.

<code>
require "win32/sound"
include Win32

wav = "c:\\windows\\media\\chimes.wav"

Sound.play(wav,Sound::ASYNC|Sound::LOOP)
sleep 3
Sound.stop

</code>

Hope it helps.

Gordon




 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      05-22-2007
Hi Gordon,

That's perfect for my purposes:

1. Achieving looping within the playing mechanism is much faster than
using a Ruby loop invoking a Win32 function repeatedly

2. Using an explicit rather than symbolic path is also a speedup, i.e.
"F:\\WINXPPRO\\media\\chimes.wav" instead of ALARM_BELL =
ENV["WINDIR"] + "\\Media\\chimes.wav"

Thank you very much for the addition post.

Best wishes,
Richard


On May 15, 10:41 am, Gordon Thiesfeld <gthiesf...@gmail.com> wrote:
> If I understand your question, you want to play a wav file repeatedly,
> as quickly as possible. This code is from the example file in the
> win32-sound gem. It plays chimes.wav 5 times in 3 seconds on both of
> my XP machines.
>
> <code>
> require "win32/sound"
> include Win32
>
> wav = "c:\\windows\\media\\chimes.wav"
>
> Sound.play(wav,Sound::ASYNC|Sound::LOOP)
> sleep 3
> Sound.stop
>
> </code>
>
> Hope it helps.
>
> Gordon



 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      05-22-2007
Hi Cliff,

I agree completely, but I didn't know where to get (of how to
construct) a longer file. And I'd rather learn a better Ruby
technique (as Cliff provided on May 15, for example) than research
multimedia issues.

But thanks for posting a valid idea.

Best wishes,
Richard

On May 16, 5:11 pm, "Cliff Rowley" <cliffrow...@gmail.com> wrote:
> > -----Original Message-----
> > From: Gordon Thiesfeld [mailto:gthiesf...@gmail.com]
> > Sent: 15 May 2007 15:45
> > To: ruby-talk ML
> > Subject: Re: sleep 0.2 acts more like sleep 1

>
> > If I understand your question, you want to play a wav file
> > repeatedly, as quickly as possible. This code is from the
> > example file in the win32-sound gem. It plays chimes.wav 5
> > times in 3 seconds on both of my XP machines.

>
> > <code>
> > require "win32/sound"
> > include Win32

>
> > wav = "c:\\windows\\media\\chimes.wav"

>
> > Sound.play(wav,Sound::ASYNC|Sound::LOOP)
> > sleep 3
> > Sound.stop

>
> > </code>

>
> > Hope it helps.

>
> > Gordon

>
> It would also make sense to me to use a longer sound file. A 3 second sound
> file containing 15 beeps, or something.. Seems a little less like brute
> force to me, playing the sound only 4 or 5 times in 15 seconds, or
> something.
>
> Just my 2p.



 
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
Plastic that acts like metal Nomen Nescio Digital Photography 9 03-14-2010 12:45 AM
acts like an anchor, i.e., links to another page, but looks like a button AAaron123 ASP .Net 11 11-27-2008 01:01 PM
Passing an object through COM which acts like str but isn't Rafe Python 5 08-15-2008 06:25 PM
RPC Client acts like a server Utku Altinkaya Python 0 07-14-2008 10:15 AM
computer acts like it has spyware but doesn't? Joe_Evil Computer Support 12 03-01-2007 08:50 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57