www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/12/15/04:34:12

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Tim Nicholson" <T DOT J DOT Nicholson AT btinternet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: sound(frequency,duration) function?
Date: Sat, 15 Dec 2001 09:22:19 +0000 (UTC)
Organization: Skyforce avionics Limited
Lines: 46
Message-ID: <9vf4ob$72c$1@helle.btinternet.com>
References: <pLwS7.874$G11 DOT 148285 AT news DOT uswest DOT net>
NNTP-Posting-Host: host217-35-65-100.in-addr.btopenworld.com
X-Trace: helle.btinternet.com 1008408139 7244 217.35.65.100 (15 Dec 2001 09:22:19 GMT)
X-Complaints-To: usenet AT helle DOT btinternet DOT com
NNTP-Posting-Date: Sat, 15 Dec 2001 09:22:19 +0000 (UTC)
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MSMail-Priority: Normal
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Are you using allegro?

If so, set up a timer function at a frequency of say 10hz and a couple of
global unsigned integers to contain a counter and the required duration.

To play the sound place some code in your main program along the lines of:

    duration = 15;  (seconds * 10, therefore this is 1.5 seconds)
    counter = 0;
    sound(freq); // frequency in hertz

In the timer function enter some code along the lines of
{
    if(counter++ == duration)
        nosound();
}

Remember to lock the variables and functions (See the allegro FAQ)

If you are not using allegro then you will need to either write an interrupt
routine from scratch or simply place a test instruction in the main program
loop
which checks the current time against the time that the sound started
playing and stops it when required - This is a bit hit and miss as it
assumes that the program loop will always run fast enough to stop the sound
at the right time - I would go for the allegro option personally.

Tim

"Derek" <djny AT flashmail DOT com> wrote in message
news:pLwS7.874$G11 DOT 148285 AT news DOT uswest DOT net...
> Hello, is there a function that you can call in which you tell it the
> frequency and the duration, and the program can still keep executing while
> the sound is playing, then the sound will turn off once the duration
stops?
>
> I am aware of sound(), sleep(), and nosound(), but the sleep() will
> completely stop the whole program, and I don't want that.
>
> Thanks,
>
> Derek Young
>
>


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019