News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Playing with PlaySound

Started by hutch--, July 12, 2021, 02:32:17 PM

Previous topic - Next topic

hutch--

I ocasionally used this API long ago and never took much notice of it but recent test pieces have produced some interesting results.

If you convert an MP3 file to WAV via ffmpeg, it seems that the WAV format is a container format and when you do the conversion, you get a wav extension file that is the same size as the MP4. Now once you have done the conversion, you can play the converted MP3 file with PlaySound.

With another API you can set the playback volume and by putting the function call into a thread, you can get it to run without locking up the main app. It can be stopped with an empty call to PlaySound. It appears that PlaySound cannot be stopped and re-started which is unfortunate. There are some MCI based API calls that can probably do this.

Greenhorn

Quote from: hutch-- on July 12, 2021, 02:32:17 PM
If you convert an MP3 file to WAV via ffmpeg, it seems that the WAV format is a container format and when you do the conversion, you get a wav extension file that is the same size as the MP4. Now once you have done the conversion, you can play the converted MP3 file with PlaySound.

You can also play mp3 files with PlaySound by just renaming the file to *.wav. This works fine with fixed bit rate, but fails on variable bit rate, IIRC.
Ten years ago that I did this and I do not recall totally, maybe this works also without renaming. I renamed the files because I've stored them in the resources ...

Cheers
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

jj2007

It's most of the time a question of the installed codecs. Here are some samples (might be copyrighted somewhere, I'll remove or modify the attachment later) plus my private image viewer based on Gdi+ and IMediaControl. Some lines from the source:

.if InstrOr(esi, ".asf" or ".avi" or ".mp4" or ".mpg" or ".wmv" or ".3gp" or ".webm" or ".mts" or ".voc" or ".ogg" or ".mid" or ".wav" or ".aiff" or ".ra" or ".au" or ".mka", 1)
m2m video, -127 ; flag start immediately
Let cd$=cd$+"*"+eax
.else
Let cd$=cd$+"*.jpg|*.png|*.gif|*.ico|*.jpeg|*.tif*|*.bmp"
.endif


So far, *.wma is the only format that does not play.

P.S.: In case you wonder where the audio files come from, click here :tongue:

hutch--

With audio, I am happy enough to work with MP3 as it is close to universal. With the test piece, an MP3 converted to work in a wav container with ffmpeg plays OK.

daydreamer

Quote from: hutch-- on July 12, 2021, 02:32:17 PM
With another API you can set the playback volume and by putting the function call into a thread, you can get it to run without locking up the main app
I am tryed to do that while I have animation,but got stuck
send message to soundthread when things happen?

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding