IonicWind Software

Aurora Compiler => General Discussion => Topic started by: J B Wood (Zumwalt) on November 27, 2006, 12:01:17 PM

Title: WAV file play...
Post by: J B Wood (Zumwalt) on November 27, 2006, 12:01:17 PM
How do I play a WAV sound and have it included as an internal resource?
Or heck, just play it from disk?
Title: Re: WAV file play...
Post by: Ionic Wind Support Team on November 27, 2006, 12:26:08 PM
#define SND_FILENAME  0x20000
#define SND_MEMORY  0x4
#define SND_NODEFAULT  0x2
DECLARE IMPORT,PlaySoundA(name as POINTER,handle as UINT,flags as UINT),INT;

PlaySoundA("bam.wav", NULL, SND_NODEFAULT | SND_FILENAME);
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 27, 2006, 12:38:55 PM
Did I ever mention how cool you are?
Slapping this code into the game.

Now to do this as a resource sometime in the future :)
Title: Re: WAV file play...
Post by: joske on November 27, 2006, 02:19:22 PM
With mciSendString you can play wav, mp3, mid, avi, mpg, wmv.

DECLARE IMPORT,mciSendStringA(lpszCommand:STRING,lpszReturnString:POINTER,cchReturn:INT,hwndCallback:UINT),int

mciSendString: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_mcisendstring.asp

Multimedio Command Strings:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_multimedia_command_strings.asp

I can post some IBasic pro examples if that helps
Title: Re: WAV file play...
Post by: LarryMc on November 27, 2006, 02:45:26 PM
Quote from: joske on November 27, 2006, 02:19:22 PM
I can post some IBasic pro  examples if that helps

EBasic ;)
Title: Re: WAV file play...
Post by: Ionic Wind Support Team on November 27, 2006, 02:47:36 PM
He was asking for Aurora code.  But we can convert it easy enough.
Title: Re: WAV file play...
Post by: joske on November 28, 2006, 01:03:47 AM
Here is a nice example, it is rather easy to see how to use mciSendString

http://www.codingmonkeys.com/index.php?topic=524.0 (IBasic pro)


Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 28, 2006, 06:15:35 AM
Thanks, trying to find a way to do multiple at the same time. Spent a few hours last night trying to decipher what I need to do for DirectSound since once the sound bytes are loaded into memory cache, I call them by the cache ID. Didn't get very far with it though.
Title: Re: WAV file play...
Post by: Kale on November 28, 2006, 06:20:18 AM
Aurora needs native sound playing commands to round off the game making capabilities.
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 28, 2006, 06:29:16 AM
Paul has sound in the plans from what I read somewhere, not a top of the list item for Aurora at the moment since through third party stuff it is doable.
I still can't believe I made a game on top of the 3d space using 3d sprites on a flat surface. I am still debating on removing the back image and placing a spinng world there instead...
Title: Re: WAV file play...
Post by: DominiqueB on November 29, 2006, 12:20:22 PM
Here is the IBpro mci player ported to EBasic (did it last night)

Dominique
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 29, 2006, 12:37:19 PM
Thanks, going to take a look at the code to see how you did it.
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 29, 2006, 01:05:08 PM
Can mciSendStringA play more than 1 sound file at a time?
I notice in the code before you play the next sound you are calling "close all"
Title: Re: WAV file play...
Post by: LarryMc on November 29, 2006, 01:50:21 PM
I know it can play multiple tracks on a CD.
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 29, 2006, 02:16:38 PM
I probably don't have this declared right:




DECLARE IMPORT, mciSendStringA(lpszCommand as string,lpszReturnString as STRING,cchReturn as INT,hwndCallback as INT),INT;





In EBasic its declared as:




DECLARE "winmm",mciSendStringA(lpszCommand:STRING,lpszReturnString:STRING,cchReturn:INT,hwndCallback:INT),INT





Do I have the declaration correct?
Title: Re: WAV file play...
Post by: Ionic Wind Support Team on November 29, 2006, 02:39:49 PM
Anytine you see hwnd it is a uint or int.
Title: Re: WAV file play...
Post by: LarryMc on November 29, 2006, 02:47:17 PM
This works in my program:
   


DECLARE IMPORT,mciSendStringA(lpszCommand:STRING,lpszReturnString:STRING,cchReturn:INT,hwndCallback:int),int



even though Paul said hwndCallback:int should be an uint.

I didn't know any better when I wrote my program; but since it always 0 in my program I guess that's why it didn't hurt me.
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 29, 2006, 02:57:38 PM
I just modified it to add some space in the code brackets...
Anyway, changing it from pointer to int doesn't matter for me either.
I get no sound with this...




string statusBuf,command;
command="Open " + GetStartPath()+ "snd\\LevelStart.wav Type WaveAudio alias lvlStart";
int j=messagebox(NULL, command, "Command");
mciSendStringA(command,"",0,0);
mciSendStringA("set lvlStart time format milliseconds" ,"",0,0);
command = "Status lvlStart length";
mciSendStringA(command,statusBuf,254,0);
j=messagebox(NULL, statusBuf, "Status");
mciSendStringA("status lvlStart position",statusBuf,254,0);
j=messagebox(NULL, statusBuf, "Status");
mciSendStringA("play lvlStart","",0,0);
command = "Close lvlStart";
mciSendStringA(command,"",0,0);




Title: Re: WAV file play...
Post by: LarryMc on November 29, 2006, 03:33:27 PM
In the IBPro example the output is tied to the handle of a text control.
In your Aurora code you haven't tied it to anything.  Maybe that;s where the problem lies.

I don't know how to help you in Aurora.
I'm IBpro/Ebasic freak. ;)
Title: Re: WAV file play...
Post by: Steven Picard on November 29, 2006, 04:13:22 PM
Johnathon,

Your code should work but I don't thinking you're letting it actually have time to finish (or even start) playing .  Add a message box after the play command to see what I'm talking about:
messagebox(null,"Click OK when you're done listening.","Instructions");
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 29, 2006, 06:51:35 PM
Didn't make a difference still no sound.
I am thinking it has something to do with EBasic pointing to the dll through this:
DECLARE "winmm"

But in Aurora I am only doing a DECLARE IMPORT but not telling it where to look for it?
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 29, 2006, 07:30:18 PM
Blasted all!!!

*sigh*
Ok, I broke down and found out more about the mci object and did one more declare of:
DECLARE IMPORT, mciGetErrorStringA(int fdwError, string lpszErrorText,UINT cchErrorText),int;

Well, the 'result' from the call to the send for the open, returns error 259..
Error 259 when pulled from the geterror call returns... blah... "The Driver"
*sigh*
It is not automatically recognizing the driver based on my send, *gets out the sledgehammer*
Title: Re: WAV file play...
Post by: Parker on November 29, 2006, 07:36:18 PM
Allowing you to use a string is just a leftover from IBStd where DLLs were loaded dynamically and it needed them. It was left in IBPro for compatibility with IBStd, and so it's in EBasic for compatibility with IBPro. But it doesn't mean anything; the compiler just sees it as IMPORT.
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 29, 2006, 07:42:25 PM
But I have absolutely no problems with the EBasic code but I can't get the mci to work in Aurora.
Makes no sense to me.. going to just wait on a sound mechanism for Aurora, this is giving me a serious headache.
Title: Re: WAV file play...
Post by: ExMember001 on November 29, 2006, 08:15:03 PM
you can also use bass.dll , well i know its kinda big engine for a wav or 2 but you can open more than 1 stream at the same time and add effect...
well just an idea ;)
Title: Re: WAV file play...
Post by: Ionic Wind Support Team on November 29, 2006, 10:46:43 PM
Try this:

command="Open \"" + GetStartPath()+ "snd\\LevelStart.wav\" Type WaveAudio alias lvlStart";

If the path has spaces it has to be enclosed in quotes, otherwise MCI cannot parse the string.

Not to dissapoint you but MCI can't play more than one wave file per device either.  You can play a midi file and a wave file at the same time with MCI, but not two wave files unless you have two WaveAudio devices.  As I mentioned in a PM Windows does not have a built-in facility for mixing waveform audio simply.  You either have to mix the wave data yourself before sending to the device driver, or mix them before storing in a DirectSound buffer.  Mixing involves addition and averaging of the raw wavefrom data, which is stored in 16 bit words per sample. 

That is one of the big things I miss about computers like the Amiga.  The Amiga had dedicated sound on the motherboard for 4 channel waveform audio.  You just filled up buffers and initiated playback with pointers to those buffers.  The hardware abstraction of Windows makes that impossible without using DirectSound as the layer between your data and the sound card.  Since each sound card handles I/O differently.  Back in the DOS days we had to code for each available card on the market, SB being the most common.

Paul.

Title: Re: WAV file play...
Post by: Steven Picard on November 30, 2006, 12:09:13 AM
Jonathon's sample code worked for me after I put in a messagebox to let the sound play.  However, I did change the filename to hit a wav file on my computer for testing.  I didn't even think to see if his path was correct.
Title: Re: WAV file play...
Post by: J B Wood (Zumwalt) on November 30, 2006, 06:25:16 AM
Going to pull out my Amiga 500 that is sitting on the shelf at the house and just gauk at its abilities.
That machine rocks hard, still does. I love paying games on it.
MOD files played on Amiga's are killer..

but I digress

Thanks for the heads on on MCI Paul, I thought maybe it would do more than 1 and figured that was the mechanism you were talking about in the PM. I'll just stick to what you told me in the PM and then update the code later to manipulate the sound.

All I am needing to do, or wanting to do is something like:

int return=sound.load(file,bufferid)
return would be any error code.
This would load the sound into some sort of sound buffer or sound cache, with an id that I can call later like:

bool status=sound.play(bufferid)
status would be success play ro fail play
this way, anywhere in the code I could just pass in the sound object, play by the id, and never have to reload the sound into the cache, increased game load time, but good use if you ask me
Title: Re: WAV file play...
Post by: Steven Picard on December 05, 2006, 08:34:22 PM
Quote from: Jonathan (zumwalt) Wood on November 30, 2006, 06:25:16 AM
Going to pull out my Amiga 500 that is sitting on the shelf at the house and just gauk at its abilities.
That machine rocks hard, still does. I love paying games on it.
MOD files played on Amiga's are killer..

The Amiga is still my all-time favorite computer.... sigh...