April 27, 2024, 01:27:57 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Making simple sounds

Started by barry, December 31, 2006, 09:07:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

barry

I've found playwave and playmidi but does Ebasic have anything simpler that can create a simple notification beep?  I tried searching the help on "beep" and "sound" but no luck.

And, if I have to include a wav file to do it what's the best way to do that and still have a standalone exe?  Can my program rely on the Windows system sounds having consistant names and locations?  Packing "ding.wav" into a string seemingly won't work since it's longer than the allowable maximum constant string length. I don't see any obvious way to make it a resource.

I have the feeling I'm overlooking something real obvious here so go ahead and embarass me.  :D

Barry

Barney

December 31, 2006, 11:14:02 AM #1 Last Edit: December 31, 2006, 12:22:35 PM by Barney
This should do it.

DECLARE IMPORT, MessageBeep(uType AS UINT), INT

CONST MB_ICONASTERISK = 0x00000040
CONST MB_ICONEXCLAMATION = 0x00000030
CONST MB_ICONHAND = 0x00000010
CONST MB_ICONQUESTION = 0x00000020
CONST MB_OK = 0x00000000

DECLARE IMPORT, Beep(dwFreq as INT, dwDuration as INT),INT

Beep(1000,1000)
MessageBeep(MB_ICONASTERISK)
Beep(2000,1000)
MessageBeep(MB_ICONEXCLAMATION)
Beep(3000,1000)
MessageBeep(MB_ICONHAND)
Beep(4000,1000)
MessageBeep(MB_ICONQUESTION)
Beep(5000,1000)
MessageBeep(MB_OK)

END


The MessageBeep function plays a waveform sound. The waveform sound for each sound type is identified by an entry in the registry.

The Beep function generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the sound finishes. Frequency and duration parameters are ignored under Win9x.

Barney

Ionic Wind Support Team

See the asteroids and smashout examples.  I convert wave files to DATA statements, load them into memory at startup and then play them as needed.

See also the update announcement to 1.57. http://www.ionicwind.com/forums/index.php/topic,1270.0.html which shows how to use DirectSound to create simple tones directly.

If you want to embed wave sounds as DATA statments here is a little program to help you along:


'program to convert a wave file
'into program DATA statements for EBASIC
'see the smashout! demo for ideas on
'how to use the embedded sound
'the same technique could be used
'to convert any binary data into
'data statements

def filename,filter,out:string
def waveMem:MEMORY
def waveFile:BFILE
def text:FILE
def length:int
def c:char
def x,z:int
filter = "WAVE files (*.wav)|*.wav|All Files (*.*)|*.*||"
filename = filerequest("Load WAVE file",0,1,filter)
if len(filename) > 0
if(OpenFile(waveFile,filename,"R") = 0)
length = len(waveFile)
AllocMem waveMem,length,1
Read waveFile,waveMem
closefile waveFile
endif
endif

if(waveMem <> NULL)
filter = "EBASIC (*.eba)|*.eba||"
filename = filerequest("Save EBASIC file",0,0,filter)
if(len(filename))
if(OpenFile(text,filename,"W") = 0)
write text,"DATABEGIN " + "wave_name"
write text,"DATA " + ltrim$(str$(length))
out = "DATA "
for x = 0 to length-1
readmem waveMem,x+1,c
out = out + ltrim$(str$(c))
if z = 25
z = 0
write text,out
out = "DATA "
else
if x <> (length-1)
out = out + ","
endif
endif
z = z + 1
next x
if(z < 26)
write text,out
endif
write text,"DATAEND"
closefile text
endif
endif
endif

freemem waveMem

end


Have fun!
Paul.
Ionic Wind Support Team

barry

Two good answers.  I'll try them both.

Thanks, guys.

Barry

Boris

I frequently use:


declare "kernel32",Beep(dwFreq:INT,dwDuration:INT),INT
'
'
'
'
beep (freq,duration)


(1000,100) should give you a generic short beep. Experiment with the values. I think the frequency is in Hz and the duration is in milliseconds.

Note: The program will 'pause' for the duration of the beep so try not to use long durations.
Thank you for not breeding