Changeset 468 for OCO/trunk/drv16/wavestrm.cpp
- Timestamp:
- Nov 4, 2009, 4:21:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OCO/trunk/drv16/wavestrm.cpp
r396 r468 115 115 // if there is a buffer on the InProcess Queue 116 116 // only check the first one as any others are just waiting..... 117 if (qhInProcess.IsElements()) { 117 if (qhInProcess.IsElements()) 118 { 118 119 // if any data has been written from this stream buffer 119 120 ptempbuff = (PSTREAMBUFFER)qhInProcess.Head(); 120 if (ptempbuff->ulDonepos) { 121 _vRealignBuffer(endpos, ptempbuff); 122 } /* end if ulDonepos */ 121 if (ptempbuff->ulDonepos) 122 { 123 _vRealignBuffer(endpos, ptempbuff); 124 } /* end if ulDonepos */ 123 125 } 124 126 … … 131 133 // If the rc is 1 then put it on the head of the InProcess queue. 132 134 133 while (qhDone.IsElements()) { 135 while (qhDone.IsElements()) 136 { 134 137 pTempHead->PushOnHead(qhDone.PopHead()); 135 138 } /* endwhile */ 136 139 137 while (pTempHead->IsElements()) { 140 while (pTempHead->IsElements()) 141 { 138 142 usRC = _vRealignBuffer(endpos, (PSTREAMBUFFER)pTempHead->Head()); 139 143 if (usRC) … … 159 163 #pragma on (unreferenced) 160 164 { 161 ULONG space, byteswritten ;162 163 dgprintf(("AddBuffers"));165 ULONG space, byteswritten, curspace,i; 166 167 // dgprintf(("AddBuffers %d",fFirst == TRUE?1:2)); 164 168 165 169 byteswritten = 0; 166 if (ulStreamType & STREAM_WRITE) { 170 if (ulStreamType & STREAM_WRITE) 171 { 167 172 // get the space available in the hardware buffer 168 173 // only call GetSpace once because the amount of free space in … … 170 175 // could keep us in this loop writing 4 or 8 bytes at a time. 171 176 // In extream cases we will stay stuck in this loop long enough to casue a trap rjj 172 if(pahw->GetSpace(StreamId, &_configinfo, &space) == FALSE) { 173 dgprintf(("WAVESTREAM::AddBuffers Error 1")); 177 if (pahw->GetSpace(StreamId, &_configinfo, &space) == FALSE) 178 { 179 // dgprintf(("WAVESTREAM::AddBuffers Error 1")); 174 180 return; 175 181 } 176 space &= ( ~(_configinfo.ulSampleSize - 1)); 177 while (space && qhInProcess.IsElements()) { 178 byteswritten = AddBuffer(space); 182 space &= (~(_configinfo.ulSampleSize - 1)); 183 curspace = space; 184 while (space && qhInProcess.IsElements()) 185 { 186 // Fisrt time going in task time 187 // for I7 need give time for interrupt time 188 if (fFirst == TRUE) //PS+++ 189 { 190 DevHelp_ProcBlock (space, 20, 0); 191 } 192 // dgprintf(("AddBuffers write %ld SSize:%ld %d",space, _configinfo.ulSampleSize, fFirst == TRUE?1:2)); 193 byteswritten = AddBuffer(space > curspace? curspace: space); 194 if (pahw->GetSpace(StreamId, &_configinfo, &curspace) == FALSE) 195 { 196 // dgprintf(("WAVESTREAM::AddBuffers Error 2")); 197 return; 198 } 179 199 if(byteswritten == (ULONG)-1) 180 200 break; 201 if (!curspace) 202 { 203 curspace = _configinfo.ulSampleSize; 204 } 181 205 space -= byteswritten; 182 206 space &= ( ~(_configinfo.ulSampleSize - 1)); … … 184 208 185 209 } 210 // dgprintf(("AddBuffers %d End",fFirst == TRUE?1:2)); 186 211 } 187 212 //****************************************************************************** … … 197 222 ULONG Buff_left, byteswritten, start_pos; 198 223 199 ddprintf(("AddBuffer"));224 // ddprintf(("AddBuffer")); 200 225 // make sure we have a buffer to copy from..... 201 if (!pTemp) { 226 if (!pTemp) 227 { 202 228 return (ULONG)-1; 203 229 } … … 212 238 } 213 239 240 if (!pTemp->ulBuffsz || !space) 241 { 242 dgprintf(("WAVESTREAM::AddBuffer NULL, Bufsz:%ld Space:%ld",pTemp->ulBuffsz, space)); 243 //PS+++ if is ZERO do nothing and ask for give new buffer, See REMARK in mmpm2.inf 244 qhDone.PushOnTail(qhInProcess.PopHead()); 245 // DebugInt3(); 246 return 0; 247 } 214 248 // get the buffer pointer and amount of data remaining 215 249 pdataBuf = (ULONG)pTemp->pBuffptr + pTemp->ulBuffpos; … … 217 251 Buff_left = min(Buff_left, space); 218 252 219 if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &byteswritten) == FALSE) { 253 if (pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &byteswritten) == FALSE) 254 { 220 255 dgprintf(("AddBuffer: pahw->Transfer failed!!")); 256 // DebugInt3(); 221 257 return (ULONG)-1; 222 258 } 223 if(byteswritten == 0) { 259 if (byteswritten == 0) 260 { 261 dgprintf(("AddBuffer: No more room!!")); 262 // DebugInt3(); 224 263 return (ULONG)-1; //no more room 225 264 } … … 231 270 232 271 // check to see if the buffer has been copied and needs to be put on the done queue 233 if (pTemp->ulBuffpos >= (pTemp->ulBuffsz & 0xFFFFFFFC)) { 272 if (pTemp->ulBuffpos >= (pTemp->ulBuffsz & 0xFFFFFFFC)) 273 { 234 274 qhDone.PushOnTail(qhInProcess.PopHead()); 235 275 } 236 dgprintf(("WAVESTREAM::AddBuffer sz %lx, bywr %lx dp %lx", Buff_left, byteswritten,pTemp->ulDonepos));276 // dgprintf(("WV::AddBuffer sz %lx, bywr %lx dp %lx", Buff_left, byteswritten,pTemp->ulDonepos)); 237 277 return byteswritten; 238 278 } … … 255 295 256 296 // read wave data 257 if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &bytesread) == FALSE) { 297 if(pahw->Transfer(StreamId, &_configinfo, pdataBuf, Buff_left, &bytesread) == FALSE) 298 { 258 299 dprintf(("_vReadAudioBuf: pahw->Transfer failed!!")); 259 300 return FALSE; … … 284 325 // can be returned and finally process any events pending. 285 326 //****************************************************************************** 327 //USHORT ProcNumber = 0; 286 328 void DBGCALLCONV WAVESTREAM::Process(void) 287 329 { 288 330 PSTREAMBUFFER ptemp; 289 331 ULONG ulCurBytesProcessed = 0; 290 // ULONG bytesinc; 332 // USHORT CurProcNumber = ProcNumber++; 333 ULONG space; 291 334 292 335 #ifdef DEBUG 293 ddprintf(("WAVESTREAM::Process"));336 // ddprintf(("WAVESTREAM::Process %d",CurProcNumber)); 294 337 #endif 295 338 … … 304 347 return; 305 348 } 306 ddprintf(("StPos: %lx", ulCurBytesProcessed));349 // ddprintf(("StPos: %lx", ulCurBytesProcessed)); 307 350 // save the bytes processed in the stream object 308 351 _ulBytesProcessed = ulCurBytesProcessed; 309 352 353 // if ((pahw->GetSpace(StreamId, &_configinfo, &space) != FALSE) && (space > _configinfo.ulBytesPerIRQ)) 310 354 switch (ulStreamType & STREAM_WRITE) { 311 355 … … 322 366 case STREAM_WRITE: 323 367 { 324 if(qhDone.IsElements()) { 368 if (qhDone.IsElements()) 369 { 325 370 ptemp = (PSTREAMBUFFER)qhDone.Head(); 326 371 while ((_ulBytesProcessed + _configinfo.ulBytesPerIRQ) >= ptemp->ulDonepos) … … 330 375 } 331 376 } 332 if (qhInProcess.IsElements()){ 377 if (qhInProcess.IsElements()) 378 { 333 379 AddBuffers(FALSE); 334 380 } … … 345 391 346 392 ProcessEvents(); 393 // ddprintf(("WAVESTREAM::Process %d End",CurProcNumber)); 347 394 } 348 395 //****************************************************************************** … … 353 400 { 354 401 PSTREAMBUFFER pStreamBuf = new STREAMBUFFER(uLength, pbuf); 355 402 356 403 return Write(pStreamBuf); 357 404 } … … 390 437 ULONG Seconds, MilliSeconds, Overflow, Processed; 391 438 439 //PS++ optimize code 440 Processed = _ulBytesProcessed; 392 441 if (ulStreamState == STREAM_STREAMING) // if the stream is active 393 442 { 394 395 396 if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE)397 398 DebugInt3();443 if (ulStreamType & STREAM_WRITE) 444 { 445 if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE) 446 { 447 // DebugInt3(); 399 448 Processed = _ulBytesProcessed; //last known position 400 } 401 } 402 else 403 Processed = _ulBytesProcessed; 404 } 405 else 406 Processed = _ulBytesProcessed; 449 } 450 } 451 } 407 452 408 453 // if we haven't processed anything then just return … … 411 456 return(_ulTimeBase); 412 457 413 Seconds = Processed / _configinfo.ulPCMConsumeRate;458 Seconds = Processed / _configinfo.ulPCMConsumeRate; 414 459 Overflow = Processed - (Seconds * _configinfo.ulPCMConsumeRate); 415 460 MilliSeconds = (Overflow * 1000) / _configinfo.ulPCMConsumeRate; 416 461 MilliSeconds += (Seconds * 1000); 417 return (MilliSeconds + _ulTimeBase);462 return (MilliSeconds + _ulTimeBase); 418 463 } 419 464 //****************************************************************************** … … 423 468 ULONG Processed; 424 469 470 //PS++ optimize code 471 Processed = _ulBytesProcessed; 425 472 if (ulStreamState == STREAM_STREAMING) // if the stream is active 426 473 { 427 if (ulStreamType & STREAM_WRITE) { 428 if(pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE) 429 { 474 if (ulStreamType & STREAM_WRITE) 475 { 476 if (pahw->GetPosition(StreamId, &_configinfo, &Processed) == FALSE) 477 { 430 478 DebugInt3(); 431 479 Processed = _ulBytesProcessed; //last known position 432 480 } 433 481 } 434 else 435 Processed = _ulBytesProcessed; 436 } 437 else 438 Processed = _ulBytesProcessed; 482 } 439 483 440 484 return Processed; … … 446 490 ULONG writepos = 0; 447 491 492 // May be lock? 448 493 cli(); 449 494 PSTREAMBUFFER pTemp = (PSTREAMBUFFER)qhDone.Tail(); 450 495 451 if(!pTemp) { 496 if(!pTemp) 497 { 452 498 pTemp = (PSTREAMBUFFER)qhInProcess.Head(); 453 499 } 454 if(pTemp) { 500 if(pTemp) 501 { 455 502 writepos = pTemp->ulBuffpos; 456 503 } … … 478 525 #endif 479 526 480 if(ulStreamState == STREAM_STREAMING) { 527 if(ulStreamState == STREAM_STREAMING) 528 { 481 529 ddprintf(("StartStream: already playing!!")); 482 530 return NO_ERROR; … … 485 533 // configure the wave device 486 534 // (NOTE: Must call this function; sample rate position is reset there) 487 if(pahw->ConfigDev(StreamId, &_configinfo, (pTemp) ? pTemp->ulBuffsz : 0) == FALSE) { 535 if(pahw->ConfigDev(StreamId, &_configinfo, (pTemp) ? pTemp->ulBuffsz : 0) == FALSE) 536 { 488 537 ddprintf(("StartStream: ConfigDev failed!!")); 489 goto fail; 538 return ERROR_INSUFF_BUFFER; 539 // goto fail; 490 540 } 491 541 // prepare wave device for playback/recording 492 if(pahw->Prepare(StreamId) == FALSE) { 542 if(pahw->Prepare(StreamId) == FALSE) 543 { 493 544 ddprintf(("StartStream: Prepare failed!!")); 494 545 goto fail; … … 499 550 ulStreamState = STREAM_STREAMING; 500 551 //Adding the first buffer also starts playback 501 if(ulStreamType == STREAM_WAVE_PLAY) { 552 if (ulStreamType == STREAM_WAVE_PLAY) 553 { 554 pahw->SetVolume(StreamId, getMixerStreamId(), volume); //PS 502 555 AddBuffers(TRUE); 503 556 //Must set volume after adding buffers (voices inside sblive driver might not 504 557 //be allocated otherwise (first start) ) 505 dprintf(("SetVolume %lx",volume)); 506 pahw->SetVolume(StreamId, getMixerStreamId(), volume); 507 } 508 else { 558 // dprintf(("SetVolume %lx",volume)); 559 // PS, removing to high 560 // pahw->SetVolume(StreamId, getMixerStreamId(), volume); 561 } 562 else 563 { 509 564 ulSavedInputGain = pahw->QueryVolume(StreamId, getMixerStreamId()); 510 565 pahw->SetInputSrc(StreamId, getMixerStreamId(), inputsrc); 511 566 pahw->SetVolume(StreamId, getMixerStreamId(), inputgain); 512 567 513 if(pahw->Start(StreamId) != TRUE) { 568 if(pahw->Start(StreamId) != TRUE) 569 { 514 570 dprintf(("pahw->Start failed!!")); 515 571 goto fail; 516 572 } 517 573 } 518 ddprintf(("WAVESTREAM::StartStream %lx ", StreamId));574 ddprintf(("WAVESTREAM::StartStream %lx End", StreamId)); 519 575 return NO_ERROR; 520 576 … … 665 721 if(DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0) 666 722 { 667 //dgprintf(("Error in DevHelp_VMAlloc Conversion Buffer"));723 dgprintf(("Error in DevHelp_VMAlloc Conversion Buffer")); 668 724 DebugInt3(); //should never happen!! 669 725 _configinfo.usConversion = CONVERT_NONE; … … 676 732 LIN linAddr; 677 733 678 if (DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0)734 if (DevHelp_VMAlloc((VMDHA_FIXED | VMDHA_CONTIG), CONVERSION_BUFFER_SIZE, (ULONG)-1L, &linAddr, &pSelOff) != 0) 679 735 { 680 //dgprintf(("Error in DevHelp_VMAlloc SR Conversion Buffer"));681 736 dgprintf(("Error in DevHelp_VMAlloc SR Conversion Buffer")); 737 DebugInt3(); //should never happen!! 682 738 } 683 739 else _configinfo.pSRateConvBuffer = linAddr;
Note:
See TracChangeset
for help on using the changeset viewer.