May 06, 2024, 11:51:34 PM

News:

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


PlayWave Problem.

Started by Tony, December 02, 2008, 04:52:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tony

I'm having a problem playing a wav file that is loaded as a resource into a MEMORY variable and played via PLAYWAVE. The first time, it plays fine, but after that, it's silence, but PLAYWAVE returns a 1, indicating success. It doesn't happen with every wav file, only with certain ones, but I don't know why it would play some, but not all. Now If I play the the sound file straight from the hard drive using PLAYWAVE it plays the first time and every time.

I've attached a simple project that illustrates the issue. Hopefully, someone can shed some light on this.

Thanks,

  Tony.

sapero

This may be a temporary solution: call LOADRESOURCE just before PLAYWAVE. It helps.

Tony

Quote from: sapero on December 02, 2008, 06:14:15 PM
This may be a temporary solution: call LOADRESOURCE just before PLAYWAVE. It helps.

Thanks sapero. I can deal with that as a work-around for now.  :)

Tony

While we're on the subject....below is a wav file that I used in the IB version of my Pyramid game. However, it doesn't work at all for me using EB whether from a resource or straight from the disk. I would be interested to hear if anyone else is able to use it successfully with EB.

Thanks,

  Tony.

Tony

So, is this a compiler bug or something else?  :)

Ionic Wind Support Team

Something else.

PlayWave just calls the Windows API function PlaySound,  which is the same API function Windows uses to play all of those OS sounds such as startup,shutdown, etc.  Emergence does nothing with or to the file, it just directs Windows to play it.

Paul.
Ionic Wind Support Team

Tony

It's just strange that it only happens with EBasic. The same file plays fine using other programs and the original IBasic version of Pyramid plays the sound as it should.

Ionic Wind Support Team

They both use the same API function.

DECLARE IMPORT,PlaySoundA(name as POINTER,handle as UINT,flags as UINT),INT

PlaySoundA(GetStartPath() + "blah.wav",NULL,0x20002|@SNDSYNC)

Nothing special and the same command has been in there for many,many years.  Perhaps it is a path or naming problem?  I know if you name a wave file the same as a registered windows sound then the function will fail.

Paul.
Ionic Wind Support Team

Tony

December 03, 2008, 03:18:53 PM #8 Last Edit: December 03, 2008, 03:20:35 PM by Tony
I understand that, but I don't think that is the case here, since they are loaded as resources and not from disk. Using the built-in PLAYWAVE or calling the PlaySound API directly, gives me the same results. For a wav file that is read from disk, both play it fine the first time and subsequent times. It's when I have the a wav file compiled into my EXE as a resource that the problem begins. It plays fine the first time, but silence on subsequent times whether I use PLAYWAVE or PlaySound. The only work around was the one suggested by sapero, to call LOADRESOURCE first and then PLAYWAVE each time I need to play the sound.

As I said in my original post, this behaviour only happens with some sound files and only when using them as resources but I'm not sure why that may be. Since they play fine straight from disk, I thought perhaps the MEMORY variable was being corrupted somehow, since it plays once and then fails afterwards.

Ionic Wind Support Team

Tony,
I am not sure.  It's some issue with Windows and PlaySound as if you change it to RValue=PLAYWAVE(DealWav,@SNDSYNC|@SNDNOSTOP)

Windows still thinks the previous wave is still playing.  When you end the program you can see the threads that were started to play the wave file ending.

It's possible it isn't being stored in resources properly too.  I've seen it before where resource sizes end up 1 byte larger.

Paul.
Ionic Wind Support Team

Tony

Thanks for the info Paul. That makes sense to me. It isn't a deal breaker. I was just wanting to know how it worked, or in this case, why it didn't work, like most of us programmers do.  :)


sapero

December 03, 2008, 06:01:37 PM #11 Last Edit: December 03, 2008, 06:38:00 PM by sapero
The DealCard.wav file has some additional chunks: bext, iXML, SNDM, \x00SME, \x87\x4B\x64\xC9.
The latest one has invalid length. If you re-encode the file using for example Audacity (it will remove the additional chunks), the wave will play multiple times.

Or fix the file in memory:SUB LoadWavFile

RValue=LOADRESOURCE(@IDDEAL,256,DealWav)

declare extern memcmp alias _memcmp(...),int
declare extern memcpy alias _memcpy(...),int
pointer p = DealWav + 12 ' skip RIFFsizeWAVE
pointer fmt = 0
pointer dat = 0
int fmtlen
int datlen
' find 'fmt ' and 'data'
while 1
if ((fmt=0) and (memcmp(p, "fmt ", 4)=0))
fmt = p
fmtlen = 8+ *<int>(fmt+4)
elseif ((dat=0) and (memcmp(p, "data", 4)=0))
dat = p
datlen = 8+ *<int>(dat+4)
endif
if (fmt and dat)
' copy 'fmt ' chunk right after RIFFsizeWAVE
memcpy(DealWav + 12, fmt, fmtlen)
' append 'data' chunk to 'fmt '
memcpy(DealWav + 12 + fmtlen, dat, datlen)
' update size in RIFFsizeWAVE
*<int>(DealWav+4) = 4 +fmtlen +datlen
return
endif
p = p + 8 + *<int>(p+4)
endwhile
ENDSUB


The Congrats.wav has 4 additional zero-bytes in format chunk. Maybe someone put the whole WAVEFORMATEX structure to file instead 4 bytes less ;D

Tony

You are the man sapero!!  ;D Thanks for taking the time to not only discover the issue but come up with a resolution as well. I've downloaded Audacity and will be using it as part of my programmer's toolbox from now on.

Thanks,

  Tony.