Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Sound problem

Author
Message
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 13th Dec 2007 03:13
I created a program and i have a certain sound play when a key is pressed, the only this is the sound plays over and over again very fast, i need it so the sound only plays once when the key is hit.
Any ideas?

Thanks
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 13th Dec 2007 12:19
It looks like multiple keypress stored at the keyboard buffer.
The buffer should be flushed once into the keypress code.
Also don't allow the sound to play if it is already playing.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Dec 2007 15:51
if (!dbSoundPlaying(SndID)){
dbPlaySound(SndID);
};

Also - make sure looping isn't on - and in a "Game" (referring to keyboard buffer thing) Use the scancodes etc - unless you truly are after "Buffered keyboard" input.

cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 13th Dec 2007 22:43
ok so here is my program so far



The code you gave me only delays the sound meaning if i hit the key the sound will come out, but i have to wait like 3 seconds for the sound to come out again when i hit the key again, i need it so you could press they key many times and the sound will come out each time instantly, but it will only come out once.

Any ideas, or did i just do something wrong?
Morcilla
21
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 15th Dec 2007 10:59
Here is an idea for DBPro, although I would like to see some other solution, it can be applied to DGDK as well:

http://forum.thegamecreators.com/?m=forum_view&t=119915&b=1
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 15th Dec 2007 15:04 Edited at: 15th Dec 2007 15:16
Hi cfender,

I used to have the same problem. I came with a work around. Here it is:


Oh yeah, here's what it does: You can press and hold the key, and it will play the sound once and not loop. You can tap the key and that'll also work.

Note: You can easily make it into a class to fit your needs

dbPrint ( "Sig" );
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 15th Dec 2007 18:37
Thank you dbGamerX , works perfectly
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 15th Dec 2007 21:12
grr new problem, is there a way to make more then one sound play at the same time, i know this worked in dbpro.
any ideas?
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 15th Dec 2007 22:49 Edited at: 15th Dec 2007 22:50
You use a function. I'll make it for you as soon as I reach home (I don't have VC++ installed on this comp).

What I mean function is:


How it works: it takes the sound ID, takes the button you assigned and checks if the button is pressed. So in reality, it is jumping from the main loop to the function and back while you play.

Cheers,
dbGamerX

dbPrint ( "Sig" );
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 16th Dec 2007 00:43
Thanks dbxgamer i would really appreciate that.
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 16th Dec 2007 15:36
Ok, here is your code. Everything should be self-explanatory



Here's how it works:

PlaySoundOnce ( Sound ID of music or sound you loaded, DirectX macro key, music or sound )

The first argument takes the music or sound you loaded. Make sure you use dbLoadMusic for large music (midi's etc) and dbLoadSound for short music.

The second argument is the directx macro. Like DIK_F1 or DIK_32 etc.

The third argument is the declaration. You have to tell it if you loaded the music as a sound (dbLoadSound) or music (dbLoadMusic).

Cheers,
dbGamerX

dbPrint ( "Sig" );
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 17th Dec 2007 02:28
Thanks alot! I will test and report results asap.
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 18th Dec 2007 03:04
Alright the function worked fine, but I'm still left with the same problem, Say if i assign The key A to one sound and the key B to another. If press them both at the same time, no sound i will come out. It is very important that both sounds will come out at the same time if both keys are pressed because i am creating a virtual drum set/instruments.

Any ideas?
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 18th Dec 2007 12:45
Oh, so you want the function to perform multiple sound effects. I'll make an edited function for you when I get home.

dbGamerX

dbPrint ( "Sig" );
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 18th Dec 2007 13:12
Yeah basically i just need it so multiple keys could be pressed and they will each play there sound together.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 18th Dec 2007 15:17 Edited at: 18th Dec 2007 15:19
@cfender - A Noble Quest

Take Note: Some Key Combinations just don't work. I made this program once - that checked all the scan keys - I have it somewhere maybe - but I would have:



display on the screen - gray on black - then when keys were presseed I would write them in white - so you could see what key combinations worked and didn't.

That Said. You are talking about POLYPHONIC playing. (Multiple keys at a time) like a musical Keyboard or piano.

You might want logic like that used in ELEC Keyboards. For Example - a cheap Radio shack Music Keyboard" usually is 8 note polyphonic.

This would translate to DBPro as 8 reserved "Sound IDs" - And when a new key was pressed - the SOUND ID it would use would be Either: The First Available Sound ID not playing anything, BUT if ALL in use - You Stop the ID that has been playing the Longest, and use that.

No reason to stay with 8 - just an example. I see an Array and Storing "Timer" Values in it - "When Pressed" - and using dbPro to ask if they are in use or not....

[edit]If you're doing a drum machine - or something like it...I'd drop the whole Poly 8 key thingy - and just have a soundid for each key - and associate whatever sound you want there.[/edit]

cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 19th Dec 2007 05:14
Yeah thats exactly what i need, do mind giving a little example? I'm a little lost on how i would go about doing this.

Thank you.
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 20th Dec 2007 00:59
I'm workin on it-
· It's a Class
· it uses two dimensional arrays to sort music and to store assigned keys
· one function called "sfxDetect( void )" will detect everything in that object
· oh yeah, and unlimited key strokes
· easily editable and derivable (lol)

It's easy- like this:
sfx Piano;

Piano.loadSFX("piano_note_G.mid", DIK_F1);
Piano.loadSFX("Piano_note_F.wav", DIK_TAB);

while ( LoopGDK() ) {
Piano.sfxDetect();
}

Easy... I'm working on the script, so at most it'll take another day.

dbPrint ( "Sig" );
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 20th Dec 2007 02:17
Alright Cool.
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 21st Dec 2007 21:53 Edited at: 22nd Dec 2007 02:36
* The script for this class was removed *

Reason: The whole design was a fault.

dbPrint ( "Sig" );
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 21st Dec 2007 23:15 Edited at: 22nd Dec 2007 02:37
OMG I noticed a problem with it... A major one: it does play multiple keys, but only once. I'm trying to figure out the problem right now...

I'm working on a simpler function that will do what you want This I worked out the design on paper... So I'm sure it will be done by tomorrow.

Sorry for the wait cfender.

dbPrint ( "Sig" );
cfender
17
Years of Service
User Offline
Joined: 16th Mar 2007
Location:
Posted: 24th Dec 2007 01:18
Alright man i really appreciate it.
dbGamerX
16
Years of Service
User Offline
Joined: 23rd Nov 2007
Location:
Posted: 24th Dec 2007 20:35
I made the function, but it only plays multiple sounds when you press one key at a time. Also it sort of "overlaps" music.. I'm still trying to fix it. I haven't been home for sometime (Christmas and all) but when I get home I'll post the script here for everyone to take a whack at it.

dbPrint ( "Sig" );

Login to post a reply

Server time is: 2024-11-17 00:06:47
Your offset time is: 2024-11-17 00:06:47