Sounds

Blitz3D Forums/Blitz3D Beginners Area/Sounds

_PJ_(Posted 2006) [#1]
Im sure there was some mention of accessing beeper controls from within blitz somewhere but ^^&*^*&%ered if I can find it :)

--------------

I just started toying around with some code, and I got stuckl into making a quaint little game that so far uses NO external media (woooh!) Unfortuantely, it's of course rather quiet. Are there any ideas on how to make sound effects at all without loading anything in?

I don't care even if it sounds like a strangled, dying ZX Spectrum (god bless), just any sort of functioning audible recognition will do!


Pineapple(Posted 2006) [#2]
I think you might be thinking of the WinAPI 'Beep' function... Here's what MSDN say:-

Beep
The Beep function generates simple tones on the speaker. The function is synchronous; it does not return control to its caller until the sound finishes.

BOOL Beep(
DWORD dwFreq, // sound frequency
DWORD dwDuration // sound duration
);
Parameters
dwFreq
[in] Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
Windows 95/98/Me: The Beep function ignores this parameter.

dwDuration
[in] Specifies the duration, in milliseconds, of the sound.
Windows 95/98/Me: The Beep function ignores this parameter.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Terminal Services: The beep is redirected to the client.

Windows 95/98/Me: On computers with a sound card, the function plays the default sound event. On computers without a sound card, the function plays the standard system beep.

Example Code
For an example, see Registering a Control Handler Function.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.


Ross C(Posted 2006) [#3]
Isn't there a Control character to perform a system BEEP?


Pineapple(Posted 2006) [#4]
Could be, though... I have tried wrapping up the characters in a For... Next loop and I cannot hear anything on my setup (Because my setup is rather pap!)


_PJ_(Posted 2006) [#5]
Hmm.........


Thanks, Dabz- I think that was what I remembered seeing. Shame, though- all that API stuff is over my head ;)


markcw(Posted 2006) [#6]
I remember doing this, there was a dll for speaker beep on the forum here somewhere, but it was a dead link... so I nabbed someone else's code in Purebasic and made a beep.dll.

I then wrote a bit of code to create sounds from a spectrum game, which was cool enough, but I was never happy with it because it sounded crap and I think some setups can't do a beep, not sure though... so I decided to use wave files.

I could upload a zip with the beep.dll and an example usage if you like.


_PJ_(Posted 2006) [#7]
Yes please! or you can email to:
teutanis_support@...


Stevie G(Posted 2006) [#8]
Malice,

Have a look at what Cygnus did in this .....

http://www.blitzbasic.com/codearcs/codearcs.php?code=1188

No external resource or DLL's!!!


markcw(Posted 2006) [#9]
ok, since the dll is very small the easiest thing for me is just to post a .bb file that creates the dll from a data block, rather than host it somewhere. So just run this file and put beep.dll in userlibs folder like it says.

Edit: fixed a bug where frequencies of 0-18 caused a crash. Thought I might as well fix it as it was a bit of a pain.




markcw(Posted 2006) [#10]
Next step is to create a file called beep.decls in the userlibs folder and put this in it.

.lib "beep.dll"

Beep%(Frequency%, Duration%)


Now you should be able to run this example code. The main problem with using beep is that it uses a delay to make the beep, so you can't stop it pausing the engine. This is why I'll be doing something like Cygnus' retrosound demo for my sounds. :)




_PJ_(Posted 2006) [#11]
Waheyy! That's all great! Thanks peeps!