Ignore:
Timestamp:
Feb 22, 2010, 2:44:21 PM (16 years ago)
Author:
rlwalsh
Message:

add FlashWaveOut class to winmm - see Ticket #2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/winmm/waveoutbase.cpp

    r7196 r21358  
    1414 */
    1515
    16 
    17 /****************************************************************************
    18  * Includes                                                                 *
    19  ****************************************************************************/
    20 
    21 
     16/******************************************************************************/
     17// Includes
     18/******************************************************************************/
    2219
    2320#define  INCL_BASE
     
    3835#include "dbglocal.h"
    3936
    40 #ifndef min
    41 #define min(a, b) ((a > b) ? b : a)
    42 #endif
     37/******************************************************************************/
     38/******************************************************************************/
    4339
    44 #ifndef max
    45 #define max(a, b) ((a > b) ? a : b)
    46 #endif
     40ULONG WaveOut::defvolume = 0xFFFFFFFF;
    4741
    48 //TODO: mulaw, alaw & adpcm
    4942/******************************************************************************/
    5043/******************************************************************************/
     
    5245           : WaveInOut(pwfx, fdwOpen, nCallback, dwInstance)
    5346{
    54     bytesPlayed = bytesCopied = bytesReturned = 0;
    55 
    5647    volume = defvolume;
    5748
     
    6758int WaveOut::getNumDevices()
    6859{
    69  MCI_GENERIC_PARMS  GenericParms;
    70  MCI_AMP_OPEN_PARMS AmpOpenParms;
    71  APIRET rc;
     60    MCI_AMP_OPEN_PARMS AmpOpenParms;
     61    MCI_GENERIC_PARMS  GenericParms = {0};
     62    APIRET rc;
    7263
    73    // Setup the open structure, pass the playlist and tell MCI_OPEN to use it
    74    memset(&AmpOpenParms,0,sizeof(AmpOpenParms));
     64    // Try to open the device to see if it's there
     65    memset(&AmpOpenParms, 0, sizeof(AmpOpenParms));
     66    AmpOpenParms.usDeviceID = 0;
     67    AmpOpenParms.pszDeviceType = (PSZ)MCI_DEVTYPE_AUDIO_AMPMIX;
    7568
    76    AmpOpenParms.usDeviceID = ( USHORT ) 0;
    77    AmpOpenParms.pszDeviceType = ( PSZ ) MCI_DEVTYPE_AUDIO_AMPMIX;
     69    rc = mymciSendCommand(0, MCI_OPEN,
     70                          MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE,
     71                          (PVOID) &AmpOpenParms, 0);
    7872
    79    rc = mymciSendCommand(0, MCI_OPEN,
    80                        MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE,
    81                        (PVOID) &AmpOpenParms,
    82                        0);
     73    if (LOUSHORT(rc) != MCIERR_SUCCESS)
     74        return 0;
    8375
    84    if(rc) {
    85         return 0; //no devices present
    86    }
     76    // Close the device
     77    mymciSendCommand(AmpOpenParms.usDeviceID, MCI_CLOSE,
     78                     MCI_WAIT,
     79                     (PVOID)&GenericParms, 0);
    8780
    88    // Generic parameters
    89    GenericParms.hwndCallback = 0;   //hwndFrame
    90 
    91    // Close the device
    92    mymciSendCommand(AmpOpenParms.usDeviceID, MCI_CLOSE, MCI_WAIT, (PVOID)&GenericParms, 0);
    93 
    94    return 1;
     81    return 1;
    9582}
    9683/******************************************************************************/
    97 //Called if waveOutSetVolume is called by the application with waveout handle NULL
    98 //Sets the default volume of each waveout stream (until it's volume is changed
    99 //with an appropriate waveOutSetVolume call)
     84/******************************************************************************/
     85BOOL WaveOut::queryFormat(ULONG formatTag, ULONG nChannels,
     86                          ULONG nSamplesPerSec, ULONG wBitsPerSample)
     87{
     88    APIRET  rc;
     89    BOOL    winrc = TRUE;
     90    MCI_OPEN_PARMS            OpenParms;
     91    MCI_WAVE_GETDEVCAPS_PARMS DevCapsParms;
     92    MCI_GENERIC_PARMS         GenericParms = {0};
     93#ifdef DEBUG
     94    char szError[64] = "";
     95#endif
     96
     97    dprintf(("WINMM: WaveOut::queryFormat %x srate=%d, nchan=%d, bps=%d", formatTag, nSamplesPerSec, nChannels, wBitsPerSample));
     98
     99    // Open the device.
     100    memset(&OpenParms, 0, sizeof(OpenParms));
     101    OpenParms.pszDeviceType = (PSZ)MCI_DEVTYPE_WAVEFORM_AUDIO;
     102
     103    rc = mymciSendCommand(0, MCI_OPEN,
     104                          MCI_WAIT | MCI_OPEN_TYPE_ID,
     105                          (PVOID)&OpenParms, 0);
     106    if (LOUSHORT(rc) != MCIERR_SUCCESS) {
     107        #ifdef DEBUG
     108        mymciGetErrorString(rc, szError, sizeof(szError));
     109        dprintf(("WINMM: WaveOut::queryFormat: %s\n", szError));
     110        #endif
     111        return FALSE;
     112    }
     113
     114    // See if the device can handle the specified format.
     115    memset(&DevCapsParms, 0, sizeof(MCI_WAVE_GETDEVCAPS_PARMS));
     116    DevCapsParms.ulBitsPerSample = wBitsPerSample;
     117    DevCapsParms.ulFormatTag     = DATATYPE_WAVEFORM;
     118    DevCapsParms.ulSamplesPerSec = nSamplesPerSec;
     119    DevCapsParms.ulChannels      = nChannels;
     120    DevCapsParms.ulFormatMode    = MCI_PLAY;
     121    DevCapsParms.ulItem          = MCI_GETDEVCAPS_WAVE_FORMAT;
     122
     123    rc = mymciSendCommand(OpenParms.usDeviceID, MCI_GETDEVCAPS,
     124                          MCI_WAIT | MCI_GETDEVCAPS_EXTENDED | MCI_GETDEVCAPS_ITEM,
     125                          (PVOID)&DevCapsParms, 0);
     126    if (LOUSHORT(rc) != MCIERR_SUCCESS) {
     127        #ifdef DEBUG
     128        mymciGetErrorString(rc, szError, sizeof(szError));
     129        dprintf(("WINMM: WaveOut::queryFormat: %s\n", szError));
     130        #endif
     131        winrc = FALSE;
     132    }
     133
     134    // Close the device
     135    rc = mymciSendCommand(OpenParms.usDeviceID, MCI_CLOSE,
     136                          MCI_WAIT, (PVOID)&GenericParms, 0);
     137    if (LOUSHORT(rc) != MCIERR_SUCCESS) {
     138        #ifdef DEBUG
     139        mymciGetErrorString(rc, szError, sizeof(szError));
     140        dprintf(("WINMM: WaveOut::queryFormat: %s\n", szError));
     141        #endif
     142        winrc = FALSE;
     143    }
     144
     145    return winrc;
     146}
     147/******************************************************************************/
     148// Called if waveOutSetVolume is called by the application with waveout handle NULL
     149// Sets the default volume of each waveout stream (until it's volume is changed
     150// with an appropriate waveOutSetVolume call)
    100151/******************************************************************************/
    101152void WaveOut::setDefaultVolume(ULONG volume)
     
    112163/******************************************************************************/
    113164/******************************************************************************/
    114 ULONG WaveOut::defvolume = 0xFFFFFFFF;
    115165
Note: See TracChangeset for help on using the changeset viewer.