home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- * File Name : DOUPAPP.C
- *
- * Description : This file contains the C source code required for Play
- * thread processing of the Buffering Playlist sample program.
- * A separeate thread is created which is responsible for
- * Playing the wave file from the memory playlist.
- *
- *
- * MMPM/2 API's: List of all MMPM/2 API's that are used in this module.
- *
- * mciSendCommand
- * MCI_PLAY
- * MCI_SET
- * mmioOpen
- * mmioGetHeader
- * mmioRead
- * mmioSeek
- *
- *
- * Copyright (C) IBM 1993
- ******************************************************************************/
- #define INCL_DOS /* required to use Dos APIs. */
- #define INCL_OS2MM /* required for MCI and MMIO headers */
- #define INCL_WINMESSAGEMGR /* required to use Win APIs. */
- #define INCL_WIN /* required to use Win APIs. */
- #include <os2.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <os2me.h>
-
- #include "doubapp.h"
- #include "doubplay.h"
- #define WAVE_FILE_NAME "mywave.wav"
-
-
- /*************************************************************************
- * Name : PlayTheWave
- *
- * Description : This function initially opens the wave file to be played
- * and tells the MCD information about the file
- * that is about to be played. The Samples Per Second,
- * Bits Per Sample, and the number of channels with which
- * the waveform file was created has to be told to the MCD.
- * This function initially fills up the allocated buffer
- * of the playlist with the wave file. For 0 - MAXBUFF
- * the wave file is filled into the memory. The Wave file
- * is read in continously from 0 -MAXBUFF. So the wave file
- * may be repeated several times in the allocated buffer.
- * This same buffer is dynamically re-filled again and again
- * when the application recieves the MCIPlAYLISTMESSAGE.
- *
- * Concepts : The wave file is first opened and then continuously read
- * into the buffer. If the end of the wave file is reached
- * then we seek to the starting of the wave and keep on reading
- * the wave file till the buffer fills up. This function
- * is done by creating a separate thread where the MCI_PLAY is
- * issued. This thread is only created when the user
- * presses the Play button. This displays the double buffering
- * concept because while the playlist is continuously looping
- * due to the BRANCH instruction and playing the wave file,
- * the buffer for the wave file is constantly being filled with
- * the data from the wave file in the MainDialogProc.
- *
- *
- * MMPM/2 API's : mmioOpen
- * mmioGetHeader
- * mmioRead
- * mmioSeek
- * mciSendCommand
- * MCI_SET
- * MCI_CUE
- *
- * Parameters : None.
- *
- * Return : None.
- *
- *************************************************************************/
- void PlayTheWave()
- {
-
- MCI_WAVE_SET_PARMS lpWaveSet;
- ULONG ulReturn;
- MCI_PLAY_PARMS mciPlayParameters;
- MMAUDIOHEADER mmHeader;
- int i;
- long ulBytesRead;
- CHAR achError[STRING_SIZE];
-
- /* Globals */
- extern PLAY_LIST_STRUCTURE_T aplayList[2*MAXBUFF+1];
- extern char achDataBuffer[MAXBUFF][MAXSIZE];
- extern HMMIO hmmioFileHandle;
- extern USHORT usWaveDeviceId;
- extern HWND hwndDiag;
-
- /* Open the Wave File MyWave.Wav for Reading */
- hmmioFileHandle = mmioOpen(WAVE_FILE_NAME,
- (PMMIOINFO) NULL,
- MMIO_READ);
- /* If the Wave File could not be opened */
- if (!hmmioFileHandle)
- {
-
- WinPostMsg(hwndDiag,
- WM_PLAYFAILED,
- MPFROMLONG((APIRET)(LONG)IDS_CANT_OPEN_WAVE),
- MPFROMLONG((LONG) FALSE) );
- return;
- }
-
- /*
- * Get the Header Information for the file so that we can set the channels,
- * Samples Per Second and Bits Per Sample to play the memory playlist.
- */
-
- ulReturn = mmioGetHeader(hmmioFileHandle,
- (PVOID) &mmHeader,
- sizeof(MMAUDIOHEADER),
- (PLONG) &ulBytesRead,
- (ULONG) NULL,
- (ULONG) NULL);
- if (ulReturn != 0 )
- {
- /* MCI Error, Send a message to the Dialog to display the Error. */
- WinPostMsg(hwndDiag,
- WM_PLAYFAILED,
- MPFROMLONG((APIRET)(LONG)ulReturn),
- MPFROMLONG((LONG) TRUE) );
- return;
- }
-
- /* Set the WaveSet Structure */
- memset(&lpWaveSet, 0, sizeof(lpWaveSet));
- lpWaveSet.ulLevel = 100;
- lpWaveSet.ulSamplesPerSec = mmHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec;
- lpWaveSet.usBitsPerSample = mmHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample;
- lpWaveSet.usChannels = mmHeader.mmXWAVHeader.WAVEHeader.usChannels;
- lpWaveSet.ulAudio = MCI_SET_AUDIO_ALL;
- lpWaveSet.hwndCallback = (HWND) NULL;
-
- /* Set the Channels for the MCD */
- ulReturn
- = mciSendCommand(usWaveDeviceId,
- MCI_SET,
- MCI_WAIT | MCI_WAVE_SET_CHANNELS,
- (PVOID) &lpWaveSet,
- (USHORT)NULL);
- if (ulReturn != 0 )
- {
- /* MCI Error, Send a message to the Dialog to display the Error. */
- WinPostMsg(hwndDiag,
- WM_PLAYFAILED,
- MPFROMLONG((APIRET)(LONG)ulReturn),
- MPFROMLONG((LONG) TRUE) );
- return;
- }
- /* Set the Samples Per Second */
- ulReturn
- = mciSendCommand(usWaveDeviceId,
- MCI_SET,
- MCI_WAIT | MCI_WAVE_SET_SAMPLESPERSEC,
- (PVOID) &lpWaveSet,
- (USHORT)NULL);
- if (ulReturn != 0 )
- {
- /* MCI Error, Send a message to the Dialog to display the Error. */
- WinPostMsg(hwndDiag,
- WM_PLAYFAILED,
- MPFROMLONG((APIRET)(LONG)ulReturn),
- MPFROMLONG((LONG) TRUE) );
- return;
- }
- /* Set the Bits per Sample */
- ulReturn
- = mciSendCommand(usWaveDeviceId,
- MCI_SET,
- MCI_WAIT | MCI_WAVE_SET_BITSPERSAMPLE,
- (PVOID) &lpWaveSet,
- (USHORT)NULL);
- if (ulReturn != 0 )
- {
- /* MCI Error, Send a message to the Dialog to display the Error. */
- WinPostMsg(hwndDiag,
- WM_PLAYFAILED,
- MPFROMLONG((APIRET)(LONG)ulReturn),
- MPFROMLONG((LONG) TRUE) );
- return;
- }
-
-
- mciPlayParameters.hwndCallback = hwndDiag;
-
- /* From 0 - MAXBUFF, fill the memory Playlist buffer with the wave file. */
-
- for (i=0; i<MAXBUFF; i++)
- {
-
- ulBytesRead =
- mmioRead(hmmioFileHandle,
- (HPSTR) achDataBuffer[i],
- MAXSIZE);
- /*
- * If the end of the wave file is reached then Seek to the starting
- * of the wave file and start reading the wave into the appropriate
- * buffer
- */
- if (ulBytesRead == 0)
- {
- mmioSeek(hmmioFileHandle, 0, SEEK_SET);
-
- ulBytesRead =
- mmioRead(hmmioFileHandle,
- (HPSTR) achDataBuffer[i],
- MAXSIZE);
- }
-
- }
-
- /* Send the Play Command to begin the playing of the memory playlist. */
- ulReturn
- = mciSendCommand(usWaveDeviceId,
- MCI_PLAY,
- MCI_NOTIFY,
- (PVOID) &mciPlayParameters,
- 0);
- if (ulReturn != 0 )
- {
- /* MCI Error, Send a message to the Dialog to display the Error. */
- WinPostMsg(hwndDiag,
- WM_PLAYFAILED,
- MPFROMLONG((APIRET)(LONG)ulReturn),
- MPFROMLONG((LONG) TRUE) );
- return;
- }
- else
- {
- /*
- * Playing of the wave file has started so send a message telling the
- * application to start animation and update the state
- */
- WinPostMsg(hwndDiag,
- WM_PLAYSTARTED,
- 0,
- 0);
- }
- DosExit(EXIT_THREAD, 0);
- }
-
-
-