1. playing wavs under win98
- Posted by Alan Tu <alantu at STUDENTS.UIUC.EDU>
Mar 21, 2000
-
Last edited Mar 22, 2000
Hi all,
I've put some fine touches on my POPCheck program. It now has a friendly
message dialog saying how many messages there are. I have two WAVs one
saying you have no messages and one saying that you have messages. I think
it would be very cool to play them in the program. The problem is doing this
in Windows.
For a couple reasons (which I won't go into here) Jacques Deschene's sound
effects 2 doesn't work under windows (for one thing, dos_interrupt is used
which isn't supported). How can I play a WAV file in Windows? Thanks.
Alan
2. Re: playing wavs under win98
On Tue, 21 Mar 2000 19:47:22 -0600, Alan Tu wrote:
>How can I play a WAV file in Windows? Thanks.
You could include David Cuny's Win32Lib and use the 'playSound' function.
If you don't want the overhead of Win32Lib, then here is the essential code
(ripped from Win32Lib):
-- start essential code --
include msgbox.e
include dll.e
-- declare integer to hold result of
-- message_box and playSound functions
integer ok
--------------------------------------------
-- wrapper for open_dll with error checking
global function linkDLL(sequence name)
-- dynamically link a DLL
atom handle
-- open the dll
handle = open_dll( name )
if handle = NULL then
-- give error and abort
ok = message_box( "Couldn't find DLL " & name,
"Error", MB_ICONHAND+MB_TASKMODAL )
-- abort
abort(1)
end if
return handle
end function
------------------------------------------------
-- wrapper for define_c_func with error checking
function linkFunc(atom dll, sequence name, sequence args, atom result)
-- dynamically link a C routine as a Euphoria function
integer handle
handle = define_c_func(dll, name, args, result)
if handle = -1 then
-- give error and abort
ok = message_box( "Couldn't link to C function " & name,
"Error", MB_ICONHAND+MB_TASKMODAL )
-- abort
abort(1)
end if
return handle
end function
------------------------------------------------------------
constant
-- get handle for winmm.dll
winmm = linkDLL("winmm.dll"),
-- get handle for PlaySound function in winmm.dll
xPlaySound = linkFunc(winmm, "PlaySound", {C_INT, C_INT, C_INT}, C_INT),
-- Windows constants for PlaySound function
SND_FILENAME = #00020000,
SND_ASYNC = #00000001
-----------------------------------------
-- wrapper for Windows PlaySound function
function playSound( sequence fileName )
atom result, file_string
-- convert to strings
file_string = allocate_string( fileName )
-- play the sound
result = c_func( xPlaySound, {file_string, NULL,
or_bits(SND_FILENAME, SND_ASYNC)})
-- free the string
free( file_string )
-- return result
return result
end function
---------------------------------------
-- example usage for playSound function
ok = playSound( "soundfile.wav" )
puts( 1, "Playing sound. Press a key to end demo..." )
while get_key()=-1 do
-- don't end program before sound is played
end while
-- Brian
3. Re: playing wavs under win98
Thanks, Bryan. winsock.e is already include win32lib. boy this is going to
be so cool!
Alan
----- Original Message -----
From: "Brian Broker" <bkb at CNW.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Wednesday, March 22, 2000 11:57 AM
Subject: Re: playing wavs under win98
> On Tue, 21 Mar 2000 19:47:22 -0600, Alan Tu wrote:
>
> >How can I play a WAV file in Windows? Thanks.
>
> You could include David Cuny's Win32Lib and use the 'playSound' function.
> If you don't want the overhead of Win32Lib, then here is the essential
code
> (ripped from Win32Lib):
>
> -- start essential code --
> include msgbox.e
> include dll.e
>
> -- declare integer to hold result of
> -- message_box and playSound functions
> integer ok
>
> --------------------------------------------
> -- wrapper for open_dll with error checking
> global function linkDLL(sequence name)
>
> -- dynamically link a DLL
> atom handle
>
> -- open the dll
> handle = open_dll( name )
>
> if handle = NULL then
>
> -- give error and abort
> ok = message_box( "Couldn't find DLL " & name,
> "Error", MB_ICONHAND+MB_TASKMODAL )
>
> -- abort
> abort(1)
>
> end if
>
> return handle
>
> end function
>
> ------------------------------------------------
> -- wrapper for define_c_func with error checking
> function linkFunc(atom dll, sequence name, sequence args, atom result)
>
> -- dynamically link a C routine as a Euphoria function
> integer handle
>
> handle = define_c_func(dll, name, args, result)
> if handle = -1 then
> -- give error and abort
> ok = message_box( "Couldn't link to C function " & name,
> "Error", MB_ICONHAND+MB_TASKMODAL )
> -- abort
> abort(1)
> end if
> return handle
> end function
>
> ------------------------------------------------------------
>
> constant
> -- get handle for winmm.dll
> winmm = linkDLL("winmm.dll"),
> -- get handle for PlaySound function in winmm.dll
> xPlaySound = linkFunc(winmm, "PlaySound", {C_INT, C_INT, C_INT}, C_INT),
> -- Windows constants for PlaySound function
> SND_FILENAME = #00020000,
> SND_ASYNC = #00000001
>
> -----------------------------------------
> -- wrapper for Windows PlaySound function
> function playSound( sequence fileName )
>
> atom result, file_string
>
> -- convert to strings
> file_string = allocate_string( fileName )
>
> -- play the sound
> result = c_func( xPlaySound, {file_string, NULL,
> or_bits(SND_FILENAME, SND_ASYNC)})
>
> -- free the string
> free( file_string )
>
> -- return result
> return result
>
> end function
>
> ---------------------------------------
> -- example usage for playSound function
> ok = playSound( "soundfile.wav" )
> puts( 1, "Playing sound. Press a key to end demo..." )
> while get_key()=-1 do
> -- don't end program before sound is played
> end while
>
> -- Brian
>
4. Re: playing wavs under win98
However, the version of win32lib with winsock doesn't have a "function
playsound" in it. I will use the snippet you pasted. Thank you.
Alan
----- Original Message -----
From: "Brian Broker" <bkb at CNW.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Wednesday, March 22, 2000 11:57 AM
Subject: Re: playing wavs under win98
> On Tue, 21 Mar 2000 19:47:22 -0600, Alan Tu wrote:
>
> >How can I play a WAV file in Windows? Thanks.
>
> You could include David Cuny's Win32Lib and use the 'playSound' function.
> If you don't want the overhead of Win32Lib, then here is the essential
code
> (ripped from Win32Lib):
>
> -- start essential code --
> include msgbox.e
> include dll.e
>
> -- declare integer to hold result of
> -- message_box and playSound functions
> integer ok
>
> --------------------------------------------
> -- wrapper for open_dll with error checking
> global function linkDLL(sequence name)
>
> -- dynamically link a DLL
> atom handle
>
> -- open the dll
> handle = open_dll( name )
>
> if handle = NULL then
>
> -- give error and abort
> ok = message_box( "Couldn't find DLL " & name,
> "Error", MB_ICONHAND+MB_TASKMODAL )
>
> -- abort
> abort(1)
>
> end if
>
> return handle
>
> end function
>
> ------------------------------------------------
> -- wrapper for define_c_func with error checking
> function linkFunc(atom dll, sequence name, sequence args, atom result)
>
> -- dynamically link a C routine as a Euphoria function
> integer handle
>
> handle = define_c_func(dll, name, args, result)
> if handle = -1 then
> -- give error and abort
> ok = message_box( "Couldn't link to C function " & name,
> "Error", MB_ICONHAND+MB_TASKMODAL )
> -- abort
> abort(1)
> end if
> return handle
> end function
>
> ------------------------------------------------------------
>
> constant
> -- get handle for winmm.dll
> winmm = linkDLL("winmm.dll"),
> -- get handle for PlaySound function in winmm.dll
> xPlaySound = linkFunc(winmm, "PlaySound", {C_INT, C_INT, C_INT}, C_INT),
> -- Windows constants for PlaySound function
> SND_FILENAME = #00020000,
> SND_ASYNC = #00000001
>
> -----------------------------------------
> -- wrapper for Windows PlaySound function
> function playSound( sequence fileName )
>
> atom result, file_string
>
> -- convert to strings
> file_string = allocate_string( fileName )
>
> -- play the sound
> result = c_func( xPlaySound, {file_string, NULL,
> or_bits(SND_FILENAME, SND_ASYNC)})
>
> -- free the string
> free( file_string )
>
> -- return result
> return result
>
> end function
>
> ---------------------------------------
> -- example usage for playSound function
> ok = playSound( "soundfile.wav" )
> puts( 1, "Playing sound. Press a key to end demo..." )
> while get_key()=-1 do
> -- don't end program before sound is played
> end while
>
> -- Brian
>
5. Re: playing wavs under win98
On Wed, 22 Mar 2000 13:21:47 -0600, Alan Tu wrote:
>However, the version of win32lib with winsock doesn't have a "function
>playsound" in it. I will use the snippet you pasted. Thank you.
>
>Alan
Or, you could download the latest release of Win32Lib from
http://www.rapideuphoria.com/win32lib.zip
which does include the playSound function and hopefully works OK with the
winsock lib. (It should work OK, but if not, it would probably only
require a few tweaks here and there.)
-- Brian