News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Sound play thread problem

Started by gabor, June 30, 2005, 06:47:11 AM

Previous topic - Next topic

gabor

Hi everyone!


I am really confused about the error I am bumping into again and again. This is the situation:

- I created a small app that plays raw pcm samples from a file.
- I use DirectSound's streaming buffer concept. The sound-play is done by an own mixing procedure in a separate thread.
- I set up a secondary buffer that is small (only 1 sec) and is played in a loop, endlessly.
- The mixing thread is syncronized to the play by notification events, and the primary thread sets an event too when it is quitting. The thread procedure does nothing else, but waits for those events and responses.

The problem is when I load a sample and I close the application afterwards I get a write access exception at the address of the DirectSound buffer. When I close the application, the main process calls WaiForSingleObject with the mixing thread's handle, this way it waits until the thread terminated.
For me the program seems trying to write into the DSound buffer after the buffer is destroyed. This write is called from the mixing thread only or should be called from there at least...So, that is confusing:
how come that this write is called after the caller thread terminated?
And why is this happening only when I've loaded a sample?
When it runs "blank", by default it plays a 1MB buffer why does not raise this write access exception?

I attached my code, please look at it! I created a make file for a debug version as well.

Greets,
Gábor



[attachment deleted by admin]

AeroASM


gabor

Sorry I simply left it out... I updated the attached zip file.

Greetings!

Mark Jones

I don't have any PCM files. :)

I tried loading a .wav file instead... interesting "clicking" sound... no application errors though. :bg
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

gabor

Mark, thanks for the test!

Wav files are PCM file with a 44 byte header, you can simply cut it off.

No errors at quiting??? Oh, gosh this will be even tougher than I expected.