~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to lib-src/portaudio-v19/src/hostapi/coreaudio/pa_mac_core_blocking.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
152
152
         goto error;
153
153
      }
154
154
 
155
 
      assert( 0 == RingBuffer_Init(
 
155
      assert( 0 == PaUtil_InitializeRingBuffer(
156
156
            &blio->inputRingBuffer,
157
157
            ringBufferSize*blio->inputSampleSize,
158
158
            data ) );
165
165
         goto error;
166
166
      }
167
167
 
168
 
      assert( 0 == RingBuffer_Init(
 
168
      assert( 0 == PaUtil_InitializeRingBuffer(
169
169
            &blio->outputRingBuffer,
170
170
            ringBufferSize*blio->outputSampleSize,
171
171
            data ) );
246
246
#endif
247
247
   blio->statusFlags = 0;
248
248
   if( blio->outputRingBuffer.buffer ) {
249
 
      RingBuffer_Flush( &blio->outputRingBuffer );
 
249
      PaUtil_FlushRingBuffer( &blio->outputRingBuffer );
250
250
      bzero( blio->outputRingBuffer.buffer,
251
251
             blio->outputRingBuffer.bufferSize );
252
252
      /* Advance buffer */
253
 
      RingBuffer_AdvanceWriteIndex( &blio->outputRingBuffer, blio->outputRingBuffer.bufferSize );
 
253
      PaUtil_AdvanceRingBufferWriteIndex( &blio->outputRingBuffer, blio->outputRingBuffer.bufferSize );
254
254
 
255
255
      /* Update isOutputFull. */
256
256
#ifdef PA_MAC__BLIO_MUTEX
266
266
*/
267
267
   }
268
268
   if( blio->inputRingBuffer.buffer ) {
269
 
      RingBuffer_Flush( &blio->inputRingBuffer );
 
269
      PaUtil_FlushRingBuffer( &blio->inputRingBuffer );
270
270
      bzero( blio->inputRingBuffer.buffer,
271
271
             blio->inputRingBuffer.bufferSize );
272
272
      /* Update isInputEmpty. */
332
332
 
333
333
   /* --- Handle Input Buffer --- */
334
334
   if( blio->inChan ) {
335
 
      avail = RingBuffer_GetWriteAvailable( &blio->inputRingBuffer );
 
335
      avail = PaUtil_GetRingBufferWriteAvailable( &blio->inputRingBuffer );
336
336
 
337
337
      /* check for underflow */
338
338
      if( avail < frameCount * blio->inputSampleSize * blio->inChan )
342
342
 
343
343
      /* copy the data */
344
344
      /*printf( "reading %d\n", toRead );*/
345
 
      assert( toRead == RingBuffer_Write( &blio->inputRingBuffer, input, toRead ) );
 
345
      assert( toRead == PaUtil_WriteRingBuffer( &blio->inputRingBuffer, input, toRead ) );
346
346
#ifdef PA_MAC__BLIO_MUTEX
347
347
      /* Priority inversion. See notes below. */
348
348
      blioSetIsInputEmpty( blio, false );
352
352
 
353
353
   /* --- Handle Output Buffer --- */
354
354
   if( blio->outChan ) {
355
 
      avail = RingBuffer_GetReadAvailable( &blio->outputRingBuffer );
 
355
      avail = PaUtil_GetRingBufferReadAvailable( &blio->outputRingBuffer );
356
356
 
357
357
      /* check for underflow */
358
358
      if( avail < frameCount * blio->outputSampleSize * blio->outChan )
365
365
                frameCount * blio->outputSampleSize * blio->outChan - toWrite );
366
366
      /* copy the data */
367
367
      /*printf( "writing %d\n", toWrite );*/
368
 
      assert( toWrite == RingBuffer_Read( &blio->outputRingBuffer, output, toWrite ) );
 
368
      assert( toWrite == PaUtil_ReadRingBuffer( &blio->outputRingBuffer, output, toWrite ) );
369
369
#ifdef PA_MAC__BLIO_MUTEX
370
370
      /* We have a priority inversion here. However, we will only have to
371
371
         wait if this was true and is now false, which means we've got
391
391
       long avail;
392
392
       long toRead;
393
393
       do {
394
 
          avail = RingBuffer_GetReadAvailable( &blio->inputRingBuffer );
 
394
          avail = PaUtil_GetRingBufferReadAvailable( &blio->inputRingBuffer );
395
395
/*
396
396
          printf( "Read Buffer is %%%g full: %ld of %ld.\n",
397
397
                  100 * (float)avail / (float) blio->inputRingBuffer.bufferSize,
418
418
       } while( avail == 0 );
419
419
       toRead = MIN( avail, frames * blio->inputSampleSize * blio->inChan );
420
420
       toRead -= toRead % blio->inputSampleSize * blio->inChan ;
421
 
       RingBuffer_Read( &blio->inputRingBuffer, (void *)cbuf, toRead );
 
421
       PaUtil_ReadRingBuffer( &blio->inputRingBuffer, (void *)cbuf, toRead );
422
422
       cbuf += toRead;
423
423
       frames -= toRead / ( blio->inputSampleSize * blio->inChan );
424
424
 
431
431
          /* of course, in the meantime, the callback may have put some sats
432
432
             in, so
433
433
             so check for that, too, to avoid a race condition. */
434
 
          if( RingBuffer_GetReadAvailable( &blio->inputRingBuffer ) ) {
 
434
          if( PaUtil_GetRingBufferReadAvailable( &blio->inputRingBuffer ) ) {
435
435
             blioSetIsInputEmpty( blio, false );
436
436
             if( ret )
437
437
                return ret;
468
468
       long toWrite;
469
469
 
470
470
       do {
471
 
          avail = RingBuffer_GetWriteAvailable( &blio->outputRingBuffer );
 
471
          avail = PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer );
472
472
/*
473
473
          printf( "Write Buffer is %%%g full: %ld of %ld.\n",
474
474
                  100 - 100 * (float)avail / (float) blio->outputRingBuffer.bufferSize,
496
496
 
497
497
       toWrite = MIN( avail, frames * blio->outputSampleSize * blio->outChan );
498
498
       toWrite -= toWrite % blio->outputSampleSize * blio->outChan ;
499
 
       RingBuffer_Write( &blio->outputRingBuffer, (void *)cbuf, toWrite );
 
499
       PaUtil_WriteRingBuffer( &blio->outputRingBuffer, (void *)cbuf, toWrite );
500
500
       cbuf += toWrite;
501
501
       frames -= toWrite / ( blio->outputSampleSize * blio->outChan );
502
502
 
508
508
             return ret;
509
509
          /* of course, in the meantime, we may have emptied the buffer, so
510
510
             so check for that, too, to avoid a race condition. */
511
 
          if( RingBuffer_GetWriteAvailable( &blio->outputRingBuffer ) ) {
 
511
          if( PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer ) ) {
512
512
             blioSetIsOutputFull( blio, false );
513
513
             if( ret )
514
514
                return ret;
536
536
void waitUntilBlioWriteBufferIsFlushed( PaMacBlio *blio )
537
537
{
538
538
    if( blio->outputRingBuffer.buffer ) {
539
 
       long avail = RingBuffer_GetWriteAvailable( &blio->outputRingBuffer );
 
539
       long avail = PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer );
540
540
       while( avail != blio->outputRingBuffer.bufferSize ) {
541
541
          if( avail == 0 )
542
542
             Pa_Sleep( PA_MAC_BLIO_BUSY_WAIT_SLEEP_INTERVAL );
543
 
          avail = RingBuffer_GetWriteAvailable( &blio->outputRingBuffer );
 
543
          avail = PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer );
544
544
       }
545
545
    }
546
546
}
551
551
    PaMacBlio *blio = & ((PaMacCoreStream*)stream) -> blio;
552
552
    VVDBUG(("GetStreamReadAvailable()\n"));
553
553
 
554
 
    return RingBuffer_GetReadAvailable( &blio->inputRingBuffer )
 
554
    return PaUtil_GetRingBufferReadAvailable( &blio->inputRingBuffer )
555
555
                         / ( blio->outputSampleSize * blio->outChan );
556
556
}
557
557
 
561
561
    PaMacBlio *blio = & ((PaMacCoreStream*)stream) -> blio;
562
562
    VVDBUG(("GetStreamWriteAvailable()\n"));
563
563
 
564
 
    return RingBuffer_GetWriteAvailable( &blio->outputRingBuffer )
 
564
    return PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer )
565
565
                         / ( blio->outputSampleSize * blio->outChan );
566
566
}
567
567