🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.multimedia
4 messages
4 total messages Started by ASFern Sun, 25 May 2003 03:57
Using keyboard to interact with sounds
#698
Author: ASFern
Date: Sun, 25 May 2003 03:57
42 lines
3096 bytes
Hi,
Can anyone help me?
I am working on a program to play wave files to a person who is sleeping.
I am using TMediaPlayer in Builder 5.0
This is what the computer should do:
Play a sound for a given number of seconds. The sound is followed by a silence of a given number of seconds.
This pattern of sound-silence is repeated say 10 or 20 times.
Whilst the pattern (sound-silence) is playing the computer operator (person conducting the test)must be able to press one of five keys, say keys A, B, C, D and E.
When the operator presses one of the five keys the computer acknowledges the action and responds to it by doing something like storing the exact time at which the key was pressed (to be printed later).

The print-out for 1 repetition of the pattern should look like this:
Original pattern:
->Sound1 starts @ 8:00:00 PM
Key A was pressed @ 8:00:05 PM
Key B was pressed @ 8:00:14 PM
Key C was pressed @ 8:00:22 PM
->Sound1 ends @ 8:00:33 PM
->Silence starts @ 8:00:34 PM
Key A was pressed @ 8:00:39 PM
->Silence ends @ 8:00:49 PM
1st repetition:
->Sound1 starts @ 8:00:50 PM
Key D was pressed @ 8:00:59 PM
Key E was pressed @ 8:01:19 PM
->Sound1 ends @ 8:01:29 PM
->Silence starts @ 8:01:30 PM
Key A was pressed @ 8:01:39 PM
->Silence ends @ 8:01:49 PM
2nd repetition ...

My problems are:
*If  I play the sound with wait = true (sync) the computer doesn't acknowledge the pressing of a key.
*If I play the sound async the computer stores the key-pressing time correctly but it doesn't wait to finish playing the sequence of sounds so only the last repetition is played.
*If I use my own time-delay method to wait until the sound has finished, the computer doesn't respond to any key-pressing event.

Question: Is there any way to play a sequence of sounds, wait until a sound finishes before another one starts and at the same time force the computer to do something in response to a key-pressing action?
I have seen games that do just that. People press al kinds of keys whilst sounds are playing and the computer responds to those keys whithout stopping the sound. How do you do that?

I would appreciate any help you can give me (books, references, homepages, sections of code, etc)

Augusto
Re: Using keyboard to interact with sounds
#700
Author: Ted Lyngmo
Date: Mon, 26 May 2003 17:27
31 lines
2429 bytes
ASFern wrote:
 > Hi,
 > Can anyone help me?
 > I am working on a program to play wave files to a person who is sleeping.
 > I am using TMediaPlayer in Builder 5.0

Maybe the PlaySound() function would be enough for this?

 > Question: Is there any way to play a sequence of sounds, wait until a
 > sound finishes before another one starts and at the same time force the
 > computer to do something in response to a key-pressing action?

Sure! You can always play the sounds sync'ed in a thread for example.

Maybe this PlaySoundThread class will help you:

 > 
http://groups.google.com/groups?hl=sv&lr=&ie=UTF-8&oe=UTF-8&frame=right&th=f0c9a76cd07be3da&seekm=3EC61DDF.6010607%40lyncon.se#link6

Btw, I suspect this has something to do with the recorded silence you asked 
about in another thread. My advice is to not have the silence included in the 
samples in an application like this. Use a TTimer() to get the silence you 
need instead. That way you can reuse the same sound, but with different times 
of silence.

Kind regards,
Ted Lyngmo

-- 
Replace MY_FIRST_NAME in my email address with my first name to send a private
email to me.
Re: Using keyboard to interact with sounds
#703
Author: ASFern
Date: Wed, 28 May 2003 00:23
14 lines
1489 bytes
Ted,
Thank you for your help.
The reason I have not used PlaySound is 1) because I haven't found documentation on this function (I am using Builder 5.0).
2)I need to play the sounds for a given amount of time, say I
want to play a 60 s wave file for only 33 s. You can control
the sound length very easily with TMediaPlayer, I am not sure 
that is the case with PlaySound.
The posibility of using multithreads is a good one, I'll look
at that later. Again thanks for your time,

Regards,

ASFern
Re: Using keyboard to interact with sounds
#704
Author: Ted Lyngmo
Date: Wed, 28 May 2003 04:22
30 lines
2170 bytes
ASFern wrote:
 > Ted,
 > Thank you for your help.
 > The reason I have not used PlaySound is 1) because I haven't found
 > documentation on this function (I am using Builder 5.0).

I have it in Builder 4.0, and there I have it in Microsoft Multimedia 
Programmers Reference.

 > 2)I need to play the sounds for a given amount of time, say I
 > want to play a 60 s wave file for only 33 s. You can control
 > the sound length very easily with TMediaPlayer, I am not sure
 > that is the case with PlaySound.

I see. This stops playback of a sound being played:
PlaySound(NULL,NULL,SND_PURGE);
But of course, if the sound is being played synchronically, you would have to 
put this operation in a separate thread.

 > The posibility of using multithreads is a good one, I'll look
 > at that later. Again thanks for your time,

No problem at all.

Kind regards,
Ted Lyngmo

-- 
Replace MY_FIRST_NAME in my email address with my first name to send a private
email to me.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads