PLAYWAV statement

Purpose:

PLAYWAV plays the sound contained in a .wav soundfile.

Syntax 1:

PLAYWAV(SoundFile AS STRING [, SoundFlags AS INTEGER])

Parameters:

  • Data type: STRING
    Soundfile The name of sound file to be played.
  • Data type: INTEGER
    SoundFlags [OPTIONAL] This parameter is for flags specifying the sound event characteristics. For example, if SoundFlags was set to SND_SYNC then PLAYWAV would wait to return until after playing the .wav but if SoundFlags was set to SND_ASYNC then the PLAYWAV function would return immediately.
    👉 Please note that if the SoundFlags option is used it must be preceded by a NULL argument specified simply with a comma.

    Other valid flags may be combined with the BOR operator. See the fdwSound parameter on the Microsoft PlaySound function webpage for more information about valid SoundFlags arguments.

Syntax 2:

PLAYWAV("", Resource_ID AS INTEGER [, SoundFlags AS INTEGER])

Parameters:

  • Data type: STRING
    "" An empty string indicating that the .wav is not being loaded from a file.
  • Data type: INTEGER
    Resource_ID An integer resource argument. The resource file(.rc) should be setup as:
    Resource_ID RCDATA "filename.wav"
    
    RCDATA is a resource-definition statement specifying a raw data resource allowing the inclusion of binary data in the executable file.
  • Data type: INTEGER
    SoundFlags [OPTIONAL] This parameter is for flags specifying the sound event characteristics. For example, if SoundFlags is set to SND_SYNC then PLAYWAV would wait to return until after playing the .wav but if SoundFlags was set to SND_ASYNC then the PLAYWAV function would return immediately.

    Other valid flags may be combined with the BOR operator. See the fdwSound parameter on the Microsoft PlaySound function webpage for more information about valid SoundFlags arguments.

Example:

Save the example code below as playwav.bas, save the following batch file into the same directory as playwav.bas and run the batch file to compile and run the example.

Build.bat Compilation Batch file:

CALL povars64.bat
bc playwav

playwav.bas

$IPRINT_OFF

$RESOURCE "$PELLES$\bin\porc.exe"

$COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx64-coff $FILE$.c"

$LINKER "$PELLES$\Bin\polink _
                    -release _
               -machine:X64 _
          -subsystem:console _
             -OUT:$FILE$.exe _
                  $FILE$.obj _
                  $FILE$__.res"

BCX_RESOURCE 1234 RCDATA "C:\Windows\Media\Windows Logon.wav"

PLAYWAV("", 1234)

BCX Console Sample Programs using the PLAYWAV statement.

Here is an alternative to the PLAYWAV statement. This example can play a .mid file and .wav file at the same time. With modifications, the program can play two .wav files at the same time. However, it cannot play two .mid files at the same time. This demo uses the town.mid file distributed with Windows and Scott Frick's BCX.wav file from his MultiSound demo.

Click here to download a .zip containg BCX.wav.

Extract the BCX.wav file and place it in the same directory as the PlayMT.exe compiled from the BCX code below. Run the demo, click on the Start button and then click on the Overlay button and you will hear Scott's .wav voice superimposed over the town.mid music.

GUI "PlayMT"
  
$LIBRARY <winmm.lib>
  
GLOBAL Form1   AS HWND
GLOBAL Button1 AS HWND
GLOBAL Button2 AS HWND
GLOBAL FileName1$
GLOBAL FileName2$
GLOBAL RetStr$
  
MACRO ID_Button1 = 101
MACRO ID_Button2 = 102
  
SUB FORMLOAD
  
  Form1 = BCX_FORM("Play Multi-Thread", 0, 0, 140, 30)
  
  Button1 = BCX_BUTTON("Start", Form1, ID_Button1, 7, 5, 60, 16)
  Button2 = BCX_BUTTON("Overlay", Form1, ID_Button2, 71, 5, 60, 16)
  
  FileName1$ = "C:\Windows\Media\town.mid"
  FileName2$ = "BCX.wav"

  mciSendString("open " & CHR$(34) & FileName1$ & CHR$(34) & " alias mid1", RetStr$, 255, Form1)
  mciSendString("open " & CHR$(34) & FileName2$ & CHR$(34) & " alias wav2", RetStr$, 255, Form1)
  CENTER(Form1)
  SHOW(Form1) ' Show it! 
 
END SUB
  
  
BEGIN EVENTS
  SELECT CASE CBMSG
  
  CASE WM_CREATE
  
    EXIT FUNCTION
  
  CASE WM_COMMAND
    IF CBCTL = ID_Button1 THEN
      mciSendString("seek mid1 to start", RetStr$, 255, Form1)
  
      mciSendString("play mid1", RetStr$, 255, Form1)
      EXIT FUNCTION
    END IF
  
    IF CBCTL = ID_Button2 THEN
      mciSendString("seek wav2 to start", RetStr$, 255, Form1)
      mciSendString("play wav2", RetStr$, 255, Form1)
      EXIT FUNCTION
    END IF
  
  CASE WM_CLOSE
    mciSendString("close all", RetStr$, 255, Form1)
    DestroyWindow(Form1)
    EXIT FUNCTION
  END SELECT
  
END EVENTS