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/waveindart.cpp

    r10185 r21358  
    1010 * Project Odin Software License can be found in LICENSE.TXT
    1111 *
    12  *
    1312 */
    1413
    15 
    16 /****************************************************************************
    17  * Includes                                                                 *
    18  ****************************************************************************/
    19 
    20 
     14/******************************************************************************/
     15// Includes
     16/******************************************************************************/
    2117
    2218#define  INCL_BASE
     
    4137#endif
    4238
    43 #ifndef max
    44 #define max(a, b) ((a > b) ? a : b)
    45 #endif
    46 
    4739LONG APIENTRY WaveInHandler(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags);
    4840
     41/******************************************************************************/
     42/******************************************************************************/
     43
    4944static BOOL fwaveInFixedBuffers = FALSE;
    5045
    51 //******************************************************************************
     46/******************************************************************************/
     47/******************************************************************************/
    5248// ODIN_waveInSetFixedBuffers
    5349//
    5450// Tell WINMM to use DART buffers of the same size as the first buffer delivered
    5551// by waveInAddBuffer
    56 //
    57 //******************************************************************************
     52
    5853void WIN32API ODIN_waveInSetFixedBuffers()
    5954{
     
    6560              : WaveInOut(pwfx, fdwOpen, nCallback, dwInstance)
    6661{
    67  MCI_GENERIC_PARMS  GenericParms;
    68  MCI_AMP_OPEN_PARMS AmpOpenParms;
    69  APIRET rc;
    70 
    71     fOverrun        = FALSE;
     62    DeviceId      = 0;
     63    ulBufSize     = DART_BUFSIZE_REC;
    7264    fMixerSetup   = FALSE;
     65    fOverrun      = FALSE;
     66    mixHandle     = 0;
     67    pmixReadProc  = NULL;
     68    MixBuffer     = NULL;
     69    BufferParms   = NULL;
     70
     71    dprintf(("DartWaveIn: samplerate %d, numChan %d bps %d (%d), format %x",
     72            SampleRate, nChannels, BitsPerSample, pwfx->nBlockAlign, pwfx->wFormatTag));
     73}
     74
     75/******************************************************************************/
     76/******************************************************************************/
     77MMRESULT DartWaveIn::open()
     78{
     79    MCI_AMP_OPEN_PARMS AmpOpenParms;
     80    MCI_GENERIC_PARMS  GenericParms = {0};
     81    MCI_MIXSETUP_PARMS MixSetupParms;
     82    APIRET rc;
    7383
    7484    MixBuffer     = (MCI_MIX_BUFFER *)malloc(PREFILLBUF_DART_REC*sizeof(MCI_MIX_BUFFER));
    75     MixSetupParms = (MCI_MIXSETUP_PARMS *)malloc(sizeof(MCI_MIXSETUP_PARMS));
    7685    BufferParms   = (MCI_BUFFER_PARMS *)malloc(sizeof(MCI_BUFFER_PARMS));
    77     if(!MixBuffer || !MixSetupParms || !BufferParms) {
     86    if(!MixBuffer || !BufferParms) {
    7887        dprintf(("ERROR: malloc failed!!"));
    79         ulError = MMSYSERR_NOMEM;
    80         return;
    81     }
    82 
    83     ulBufSize       = DART_BUFSIZE_REC;
    84 
    85     dprintf(("waveInOpen: samplerate %d, numChan %d bps %d (%d), format %x", SampleRate, nChannels, BitsPerSample, pwfx->nBlockAlign, pwfx->wFormatTag));
     88        return MMSYSERR_NOMEM;
     89    }
     90
    8691    // Setup the open structure, pass the playlist and tell MCI_OPEN to use it
    87     memset(&AmpOpenParms,0,sizeof(AmpOpenParms));
    88 
    89     AmpOpenParms.usDeviceID = ( USHORT ) 0;
    90     AmpOpenParms.pszDeviceType = ( PSZ ) MCI_DEVTYPE_AUDIO_AMPMIX;
    91 
    92     rc = mymciSendCommand(0, MCI_OPEN, MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE,
     92    memset(&AmpOpenParms, 0, sizeof(AmpOpenParms));
     93    AmpOpenParms.usDeviceID = 0;
     94    AmpOpenParms.pszDeviceType = (PSZ)MCI_DEVTYPE_AUDIO_AMPMIX;
     95
     96    rc = mymciSendCommand(0, MCI_OPEN,
     97                          MCI_WAIT | MCI_OPEN_TYPE_ID | MCI_OPEN_SHAREABLE,
    9398                          (PVOID) &AmpOpenParms, 0);
    94     DeviceId = AmpOpenParms.usDeviceID;
    9599    if(rc) {
    96100        dprintf(("MCI_OPEN failed\n"));
    97101        mciError(rc);
    98         ulError = MMSYSERR_NODRIVER;
    99     }
    100     if(rc == 0) {
    101         //Grab exclusive rights to device instance (NOT entire device)
    102         GenericParms.hwndCallback = 0;  //Not needed, so set to 0
    103         rc = mymciSendCommand(DeviceId, MCI_ACQUIREDEVICE, MCI_EXCLUSIVE_INSTANCE,
    104                             (PVOID)&GenericParms, 0);
    105         if(rc) {
    106             dprintf(("MCI_ACQUIREDEVICE failed\n"));
    107             mciError(rc);
    108             ulError = MMSYSERR_NOTENABLED;
    109         }
    110     }
    111 
    112     if(!ulError)
    113         callback(WIM_OPEN, 0, 0);
     102        return MMSYSERR_NODRIVER;
     103    }
     104
     105    DeviceId = AmpOpenParms.usDeviceID;
     106
     107    //Grab exclusive rights to device instance (NOT entire device)
     108    rc = mymciSendCommand(DeviceId, MCI_ACQUIREDEVICE,
     109                          MCI_EXCLUSIVE_INSTANCE,
     110                          (PVOID)&GenericParms, 0);
     111    if(rc) {
     112        dprintf(("MCI_ACQUIREDEVICE failed\n"));
     113        mciError(rc);
     114        return MMSYSERR_NOTENABLED;
     115    }
     116
     117    dprintf(("device acquired\n"));
     118    dprintf(("bps %d, sps %d chan %d\n", BitsPerSample, SampleRate, nChannels));
     119
     120    // Set the MixSetupParms data structure
     121    memset(&MixSetupParms, 0, sizeof(MCI_MIXSETUP_PARMS));
     122    MixSetupParms.ulBitsPerSample = BitsPerSample;
     123    MixSetupParms.ulSamplesPerSec = SampleRate;
     124    MixSetupParms.ulFormatTag     = MCI_WAVE_FORMAT_PCM;
     125    MixSetupParms.ulChannels      = nChannels;
     126    MixSetupParms.ulFormatMode    = MCI_RECORD;
     127    MixSetupParms.ulDeviceType    = MCI_DEVTYPE_WAVEFORM_AUDIO;
     128    MixSetupParms.pmixEvent       = WaveInHandler;
     129
     130    rc = mymciSendCommand(DeviceId, MCI_MIXSETUP,
     131                          MCI_WAIT | MCI_MIXSETUP_INIT,
     132                          (PVOID)&MixSetupParms, 0);
     133    if ( rc != MCIERR_SUCCESS ) {
     134        mymciSendCommand(DeviceId, MCI_RELEASEDEVICE,
     135                         MCI_WAIT,
     136                         (PVOID)&GenericParms, 0);
     137        mciError(rc);
     138        return MMSYSERR_NOTSUPPORTED;
     139    }
     140
     141    // Save the mixer handle & the ptr to the read proc.
     142    mixHandle    = MixSetupParms.ulMixHandle;
     143    pmixReadProc = MixSetupParms.pmixRead;
     144
     145
     146    callback(WIM_OPEN, 0, 0);
     147
     148    return MMSYSERR_NOERROR;
    114149}
    115150/******************************************************************************/
     
    117152DartWaveIn::~DartWaveIn()
    118153{
    119    MCI_GENERIC_PARMS    GenericParms;
     154   MCI_GENERIC_PARMS    GenericParms = {0};
    120155
    121156   State = STATE_STOPPED;
    122157
    123     if(!ulError)
     158    if (DeviceId)
    124159    {
    125         // Generic parameters
    126         GenericParms.hwndCallback = 0;   //hwndFrame
    127 
    128160        // Stop recording.
    129         mymciSendCommand(DeviceId, MCI_STOP,MCI_WAIT, (PVOID)&GenericParms,0);
    130 
    131         mymciSendCommand(DeviceId,
    132                       MCI_BUFFER,
    133                       MCI_WAIT | MCI_DEALLOCATE_MEMORY,
    134                       (PVOID)&BufferParms,
    135                       0);
    136 
    137         // Generic parameters
    138         GenericParms.hwndCallback = 0;   //hwndFrame
     161        mymciSendCommand(DeviceId, MCI_STOP,
     162                         MCI_WAIT, (PVOID)&GenericParms, 0);
     163
     164        if (fMixerSetup)
     165            mymciSendCommand(DeviceId, MCI_BUFFER,
     166                             MCI_WAIT | MCI_DEALLOCATE_MEMORY,
     167                             (PVOID)&BufferParms, 0);
    139168
    140169        // Close the device
    141         mymciSendCommand(DeviceId, MCI_CLOSE, MCI_WAIT, (PVOID)&GenericParms, 0);
    142     }
    143     if(!ulError)
    144     {
     170        mymciSendCommand(DeviceId, MCI_CLOSE,
     171                         MCI_WAIT,
     172                         (PVOID)&GenericParms, 0);
     173
    145174        callback(WIM_CLOSE, 0, 0);
    146175    }
     
    148177    if(MixBuffer)
    149178        free(MixBuffer);
    150     if(MixSetupParms)
    151         free(MixSetupParms);
    152179    if(BufferParms)
    153180        free(BufferParms);
     
    180207    if(fMixerSetup == FALSE)
    181208    {
    182         dprintf(("device acquired\n"));
    183         /* Set the MixSetupParms data structure to match the loaded file.
    184          * This is a global that is used to setup the mixer.
    185          */
    186         memset(MixSetupParms, 0, sizeof( MCI_MIXSETUP_PARMS ) );
    187 
    188         MixSetupParms->ulBitsPerSample = BitsPerSample;
    189         MixSetupParms->ulSamplesPerSec = SampleRate;
    190         MixSetupParms->ulFormatTag     = MCI_WAVE_FORMAT_PCM;
    191         MixSetupParms->ulChannels      = nChannels;
    192 
    193         dprintf(("bps %d, sps %d chan %d\n", BitsPerSample, SampleRate, nChannels));
    194 
    195         /* Setup the mixer for recording of wave data
    196          */
    197         MixSetupParms->ulFormatMode = MCI_RECORD;
    198         MixSetupParms->ulDeviceType = MCI_DEVTYPE_WAVEFORM_AUDIO;
    199         MixSetupParms->pmixEvent    = WaveInHandler;
    200 
    201         rc = mymciSendCommand(DeviceId, MCI_MIXSETUP, MCI_WAIT | MCI_MIXSETUP_INIT,
    202                               (PVOID)MixSetupParms, 0);
    203 
    204         if ( rc != MCIERR_SUCCESS ) {
    205             mciError(rc);
    206             mymciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
    207                            (PVOID)&GenericParms, 0);
    208             return(MMSYSERR_NOTSUPPORTED);
    209         }
    210 
    211209        /*
    212210         * Set up the BufferParms data structure and allocate
     
    227225            {
    228226                dprintf(("mix setup %d, %d\n", pwh->dwBufferLength, pwh->dwBufferLength));
    229    
    230227                ulBufSize = pwh->dwBufferLength/2;
    231228            }
     
    237234        else ulBufSize = minbufsize;
    238235
    239         MixSetupParms->ulBufferSize = ulBufSize;
    240 
    241236        BufferParms->ulNumBuffers = PREFILLBUF_DART_REC;
    242         BufferParms->ulBufferSize = MixSetupParms->ulBufferSize;
     237        BufferParms->ulBufferSize = ulBufSize;
    243238        BufferParms->pBufList     = MixBuffer;
    244239
     
    247242        }
    248243
    249         rc = mymciSendCommand(DeviceId,
    250                             MCI_BUFFER,
    251                             MCI_WAIT | MCI_ALLOCATE_MEMORY,
    252                             (PVOID)BufferParms,
    253                             0);
     244        rc = mymciSendCommand(DeviceId, MCI_BUFFER,
     245                              MCI_WAIT | MCI_ALLOCATE_MEMORY,
     246                              (PVOID)BufferParms, 0);
    254247
    255248        if(ULONG_LOWD(rc) != MCIERR_SUCCESS) {
    256249            mciError(rc);
    257             mymciSendCommand(DeviceId, MCI_RELEASEDEVICE, MCI_WAIT,
    258                           (PVOID)&GenericParms, 0);
    259             return(MMSYSERR_NOTSUPPORTED);
     250            mymciSendCommand(DeviceId, MCI_RELEASEDEVICE,
     251                             MCI_WAIT,
     252                             (PVOID)&GenericParms, 0);
     253            return MMSYSERR_NOTSUPPORTED;
    260254        }
    261255
     
    263257        //(until we really support the mixer extensions anyway)
    264258        /* Set the connector to 'microphone' */
    265         memset( &ConnectorParms, '\0', sizeof( MCI_CONNECTOR_PARMS ) );
     259        memset(&ConnectorParms, 0, sizeof(MCI_CONNECTOR_PARMS));
    266260        ConnectorParms.ulConnectorType = MCI_MICROPHONE_CONNECTOR;
    267         rc = mymciSendCommand(DeviceId, MCI_CONNECTOR, MCI_WAIT |
    268                               MCI_ENABLE_CONNECTOR | MCI_CONNECTOR_TYPE,
    269                               ( PVOID ) &ConnectorParms, 0 );
     261        rc = mymciSendCommand(DeviceId, MCI_CONNECTOR,
     262                              MCI_WAIT | MCI_ENABLE_CONNECTOR | MCI_CONNECTOR_TYPE,
     263                              (PVOID)&ConnectorParms, 0 );
    270264
    271265        /* Allow the user to hear what is being recorded
    272266         * by turning the monitor on
    273267         */
    274         memset( &AmpSetParms, '\0', sizeof( MCI_AMP_SET_PARMS ) );
     268        memset(&AmpSetParms, 0, sizeof( MCI_AMP_SET_PARMS ) );
    275269        AmpSetParms.ulItem = MCI_AMP_SET_MONITOR;
    276         rc = mymciSendCommand(DeviceId,
    277                             MCI_SET,
    278                             MCI_WAIT | MCI_SET_ON | MCI_SET_ITEM,
    279                             ( PVOID ) &AmpSetParms,
    280                             0 );
     270        rc = mymciSendCommand(DeviceId, MCI_SET,
     271                              MCI_WAIT | MCI_SET_ON | MCI_SET_ITEM,
     272                              (PVOID)&AmpSetParms, 0);
    281273
    282274        wmutex.enter();
     
    284276    }
    285277
    286     for(i=0;i<PREFILLBUF_DART_REC;i++) {
     278    for(i=0; i< PREFILLBUF_DART_REC; i++) {
    287279        memset(MixBuffer[i].pBuffer, 0, MixBuffer[i].ulBufferLength);
    288280    }
    289281    dprintf(("Dart opened, bufsize = %d\n", MixBuffer[0].ulBufferLength));
    290282
    291     dprintf(("MixSetupParms = %X\n", MixSetupParms));
    292283    State    = STATE_RECORDING;
    293284    fOverrun = FALSE;
     
    298289    // Start recording.
    299290    USHORT selTIB = RestoreOS2FS(); // save current FS selector
    300     MixSetupParms->pmixRead(MixSetupParms->ulMixHandle, &MixBuffer[0], PREFILLBUF_DART_REC);
     291    pmixReadProc(mixHandle, &MixBuffer[0], PREFILLBUF_DART_REC);
    301292    SetFS(selTIB);           // switch back to the saved FS selector
    302293
     
    506497/******************************************************************************/
    507498/******************************************************************************/
    508 void DartWaveIn::mciError(ULONG ulError)
     499void DartWaveIn::mciError(ULONG rc)
    509500{
    510501#ifdef DEBUG
    511502    char szError[256] = "";
    512503
    513     mymciGetErrorString(ulError, szError, sizeof(szError));
     504    mymciGetErrorString(rc, szError, sizeof(szError));
    514505    dprintf(("WINMM: DartWaveIn: %s\n", szError));
    515506#endif
     
    586577    // MCI_MIXSETUP_PARMS->pMixWrite does alter FS: selector!
    587578    USHORT selTIB = RestoreOS2FS(); // save current FS selector
    588     MixSetupParms->pmixRead(MixSetupParms->ulMixHandle, pBuffer, 1);
     579    pmixReadProc(mixHandle, pBuffer, 1);
    589580    SetFS(selTIB);           // switch back to the saved FS selector
    590581}
Note: See TracChangeset for help on using the changeset viewer.