Author Topic: Playing with PlaySound  (Read 1433 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Playing with PlaySound
« on: July 12, 2021, 02:32:17 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Playing with PlaySound
« Reply #1 on: July 13, 2021, 06:10:42 AM »
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

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Playing with PlaySound
« Reply #2 on: July 13, 2021, 06:18:10 PM »
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:

Code: [Select]
.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--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Playing with PlaySound
« Reply #3 on: July 13, 2021, 08:39:52 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

daydreamer

  • Member
  • *****
  • Posts: 2399
  • my kind of REAL10 Blonde
Re: Playing with PlaySound
« Reply #4 on: July 15, 2021, 09:30:33 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
http://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