Changeset 21358 for trunk/src/winmm/waveindart.cpp
- Timestamp:
- Feb 22, 2010, 2:44:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/winmm/waveindart.cpp
r10185 r21358 10 10 * Project Odin Software License can be found in LICENSE.TXT 11 11 * 12 *13 12 */ 14 13 15 16 /**************************************************************************** 17 * Includes * 18 ****************************************************************************/ 19 20 14 /******************************************************************************/ 15 // Includes 16 /******************************************************************************/ 21 17 22 18 #define INCL_BASE … … 41 37 #endif 42 38 43 #ifndef max44 #define max(a, b) ((a > b) ? a : b)45 #endif46 47 39 LONG APIENTRY WaveInHandler(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags); 48 40 41 /******************************************************************************/ 42 /******************************************************************************/ 43 49 44 static BOOL fwaveInFixedBuffers = FALSE; 50 45 51 //****************************************************************************** 46 /******************************************************************************/ 47 /******************************************************************************/ 52 48 // ODIN_waveInSetFixedBuffers 53 49 // 54 50 // Tell WINMM to use DART buffers of the same size as the first buffer delivered 55 51 // by waveInAddBuffer 56 // 57 //****************************************************************************** 52 58 53 void WIN32API ODIN_waveInSetFixedBuffers() 59 54 { … … 65 60 : WaveInOut(pwfx, fdwOpen, nCallback, dwInstance) 66 61 { 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; 72 64 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 /******************************************************************************/ 77 MMRESULT DartWaveIn::open() 78 { 79 MCI_AMP_OPEN_PARMS AmpOpenParms; 80 MCI_GENERIC_PARMS GenericParms = {0}; 81 MCI_MIXSETUP_PARMS MixSetupParms; 82 APIRET rc; 73 83 74 84 MixBuffer = (MCI_MIX_BUFFER *)malloc(PREFILLBUF_DART_REC*sizeof(MCI_MIX_BUFFER)); 75 MixSetupParms = (MCI_MIXSETUP_PARMS *)malloc(sizeof(MCI_MIXSETUP_PARMS));76 85 BufferParms = (MCI_BUFFER_PARMS *)malloc(sizeof(MCI_BUFFER_PARMS)); 77 if(!MixBuffer || ! MixSetupParms || !BufferParms) {86 if(!MixBuffer || !BufferParms) { 78 87 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 86 91 // 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, 93 98 (PVOID) &AmpOpenParms, 0); 94 DeviceId = AmpOpenParms.usDeviceID;95 99 if(rc) { 96 100 dprintf(("MCI_OPEN failed\n")); 97 101 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; 114 149 } 115 150 /******************************************************************************/ … … 117 152 DartWaveIn::~DartWaveIn() 118 153 { 119 MCI_GENERIC_PARMS GenericParms ;154 MCI_GENERIC_PARMS GenericParms = {0}; 120 155 121 156 State = STATE_STOPPED; 122 157 123 if (!ulError)158 if (DeviceId) 124 159 { 125 // Generic parameters126 GenericParms.hwndCallback = 0; //hwndFrame127 128 160 // 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); 139 168 140 169 // 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 145 174 callback(WIM_CLOSE, 0, 0); 146 175 } … … 148 177 if(MixBuffer) 149 178 free(MixBuffer); 150 if(MixSetupParms)151 free(MixSetupParms);152 179 if(BufferParms) 153 180 free(BufferParms); … … 180 207 if(fMixerSetup == FALSE) 181 208 { 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 data196 */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 211 209 /* 212 210 * Set up the BufferParms data structure and allocate … … 227 225 { 228 226 dprintf(("mix setup %d, %d\n", pwh->dwBufferLength, pwh->dwBufferLength)); 229 230 227 ulBufSize = pwh->dwBufferLength/2; 231 228 } … … 237 234 else ulBufSize = minbufsize; 238 235 239 MixSetupParms->ulBufferSize = ulBufSize;240 241 236 BufferParms->ulNumBuffers = PREFILLBUF_DART_REC; 242 BufferParms->ulBufferSize = MixSetupParms->ulBufferSize;237 BufferParms->ulBufferSize = ulBufSize; 243 238 BufferParms->pBufList = MixBuffer; 244 239 … … 247 242 } 248 243 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); 254 247 255 248 if(ULONG_LOWD(rc) != MCIERR_SUCCESS) { 256 249 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; 260 254 } 261 255 … … 263 257 //(until we really support the mixer extensions anyway) 264 258 /* Set the connector to 'microphone' */ 265 memset( &ConnectorParms, '\0', sizeof( MCI_CONNECTOR_PARMS ));259 memset(&ConnectorParms, 0, sizeof(MCI_CONNECTOR_PARMS)); 266 260 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 ); 270 264 271 265 /* Allow the user to hear what is being recorded 272 266 * by turning the monitor on 273 267 */ 274 memset( &AmpSetParms, '\0', sizeof( MCI_AMP_SET_PARMS ) );268 memset(&AmpSetParms, 0, sizeof( MCI_AMP_SET_PARMS ) ); 275 269 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); 281 273 282 274 wmutex.enter(); … … 284 276 } 285 277 286 for(i=0; i<PREFILLBUF_DART_REC;i++) {278 for(i=0; i< PREFILLBUF_DART_REC; i++) { 287 279 memset(MixBuffer[i].pBuffer, 0, MixBuffer[i].ulBufferLength); 288 280 } 289 281 dprintf(("Dart opened, bufsize = %d\n", MixBuffer[0].ulBufferLength)); 290 282 291 dprintf(("MixSetupParms = %X\n", MixSetupParms));292 283 State = STATE_RECORDING; 293 284 fOverrun = FALSE; … … 298 289 // Start recording. 299 290 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); 301 292 SetFS(selTIB); // switch back to the saved FS selector 302 293 … … 506 497 /******************************************************************************/ 507 498 /******************************************************************************/ 508 void DartWaveIn::mciError(ULONG ulError)499 void DartWaveIn::mciError(ULONG rc) 509 500 { 510 501 #ifdef DEBUG 511 502 char szError[256] = ""; 512 503 513 mymciGetErrorString( ulError, szError, sizeof(szError));504 mymciGetErrorString(rc, szError, sizeof(szError)); 514 505 dprintf(("WINMM: DartWaveIn: %s\n", szError)); 515 506 #endif … … 586 577 // MCI_MIXSETUP_PARMS->pMixWrite does alter FS: selector! 587 578 USHORT selTIB = RestoreOS2FS(); // save current FS selector 588 MixSetupParms->pmixRead(MixSetupParms->ulMixHandle, pBuffer, 1);579 pmixReadProc(mixHandle, pBuffer, 1); 589 580 SetFS(selTIB); // switch back to the saved FS selector 590 581 }
Note:
See TracChangeset
for help on using the changeset viewer.