#define INCL_VIO #define __IBMCPP__ #define INCL_OS2MM #include #include #include #include #include #include #include "play.h" static LONG APIENTRY MixHandler(ULONG, PMCI_MIX_BUFFER, ULONG); MCI_MIX_BUFFER MixBuffers[NUM_BUFFERS]; /* Device buffers */ MCI_MIXSETUP_PARMS MixSetupParms; /* Mixer parameters */ MCI_BUFFER_PARMS BufferParms; /* Device buffer parms */ MCI_PLAY_PARMS PlayParams; int ulNumBuffers, BufNr = 0; USHORT DeviceId; HFILE modin = 0; /******************************************************************************/ /******************************************************************************/ int OpenDevice() { APIRET rc; CHAR achBuffer[CCHMAXPATH] = ""; MCI_AMP_OPEN_PARMS AmpOpenParms; MCI_GENERIC_PARMS GenericParms; int i; ULONG Action, Wrote; rc = DosOpen(filename, /* file name from Open dialog */ &modin, /* file handle returned */ &Action, 0L, FILE_NORMAL, OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, OPEN_FLAGS_SEQUENTIAL | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE, (PEAOP2)NULL); if(rc) goto Init_Err; //Read settings from file if(DosRead(modin, (char *)&RecSettings, sizeof(RecSettings), &Wrote)) goto Init_Err; // Setup the open structure, pass the playlist and tell MCI_OPEN to use it memset(&AmpOpenParms,0,sizeof(AmpOpenParms)); AmpOpenParms.usDeviceID = ( USHORT ) 0; AmpOpenParms.pszDeviceType = ( PSZ ) MCI_DEVTYPE_AUDIO_AMPMIX; rc = mciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE, ( PVOID ) &AmpOpenParms, 0 ); if (rc != 0) { mciGetErrorString( rc, (PSZ)achBuffer, sizeof( achBuffer)); cout << "Error: " << achBuffer << endl; goto Init_Err; } DeviceId = AmpOpenParms.usDeviceID; //Grab exclusive rights to device instance (NOT entire device) GenericParms.hwndCallback = 0; //Not needed, so set to 0 rc = mciSendCommand(DeviceId, MCI_ACQUIREDEVICE, MCI_EXCLUSIVE_INSTANCE, (PVOID)&GenericParms, 0); if (rc != 0) { mciGetErrorString( rc, (PSZ)achBuffer, sizeof( achBuffer)); cout << "Error: " << achBuffer << endl; goto Init_Err; } /* Set the MixSetupParms data structure to match the loaded file. * This is a global that is used to setup the mixer. */ memset( &MixSetupParms, 0, sizeof( MCI_MIXSETUP_PARMS ) ); MixSetupParms.ulBitsPerSample = RecSettings.bits; MixSetupParms.ulSamplesPerSec = RecSettings.rate; MixSetupParms.ulFormatTag = RecSettings.format; MixSetupParms.ulChannels = RecSettings.numchan; /* Setup the mixer for playback of wave data */ MixSetupParms.ulFormatMode = MCI_PLAY; MixSetupParms.ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO; MixSetupParms.pmixEvent = MixHandler; rc = mciSendCommand( DeviceId, MCI_MIXSETUP, MCI_WAIT | MCI_MIXSETUP_INIT, ( PVOID ) &MixSetupParms, 0 ); if ( rc != MCIERR_SUCCESS ) { mciGetErrorString( rc, (PSZ)achBuffer, sizeof( achBuffer)); cout << "Error: " << achBuffer << endl; goto Init_Err; } /* Use the suggested buffer size provide by the mixer device * and the size of the audio file to calculate the required * number of Amp-Mixer buffers. */ ulNumBuffers = NUM_BUFFERS; /* * Set up the BufferParms data structure and allocate * device buffers from the Amp-Mixer */ MixSetupParms.ulBufferSize = ulBuffersize; BufferParms.ulNumBuffers = ulNumBuffers; BufferParms.ulBufferSize = MixSetupParms.ulBufferSize; BufferParms.pBufList = MixBuffers; for(i=0;i