示例#1
0
/***************************************************************************
** Return elements written. */
ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount, const int hopsize, const int offset )
{
    ring_buffer_size_t size1, size2, numWritten;
    void *data1, *data2;
    numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );

	if(hopsize == 1) {
		if( size2 > 0 )
		{

			memcpy( data1, data, size1*rbuf->elementSizeBytes );
			data = ((char *)data) + size1*rbuf->elementSizeBytes;
			memcpy( data2, data, size2*rbuf->elementSizeBytes );
		}
		else
		{
			memcpy( data1, data, size1*rbuf->elementSizeBytes );
		}
	} else {
		int i, j, k;
		data = ((char *)data) + offset*rbuf->elementSizeBytes;
		if( size2 > 0) {
			for(i = 0; i < size1; i++) {
				for(k = 0; k < rbuf->elementSizeBytes; k++) {
					((char *)data1)[i*rbuf->elementSizeBytes+k] = ((char *)data)[i*rbuf->elementSizeBytes*hopsize+k];
				}
			}
			data = ((char *)data) + size1*rbuf->elementSizeBytes;
			for(j = 0; j < size2; j++) {
				for(k = 0; k < rbuf->elementSizeBytes; k++) {
					((char *)data2)[j*rbuf->elementSizeBytes+k] = ((char *)data)[j*rbuf->elementSizeBytes*hopsize+k];
				}
			}
		} else {
			for(i = 0; i < size1; i++) {
				for(k = 0; k < rbuf->elementSizeBytes; k++) {
					((char *)data1)[i*rbuf->elementSizeBytes+k] = ((char *)data)[i*rbuf->elementSizeBytes*hopsize+k];
				}
			}
		}
	}

    PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
    return numWritten;
}
/* This should be called after stopping or aborting the stream, so that on next
   start, the buffers will be ready. */
PaError resetBlioRingBuffers( PaMacBlio *blio )
{
#ifdef PA_MAC__BLIO_MUTEX
   int result;
#endif
   blio->statusFlags = 0;
   if( blio->outputRingBuffer.buffer ) {
      PaUtil_FlushRingBuffer( &blio->outputRingBuffer );
      bzero( blio->outputRingBuffer.buffer,
             blio->outputRingBuffer.bufferSize );
      /* Advance buffer */
      PaUtil_AdvanceRingBufferWriteIndex( &blio->outputRingBuffer, blio->ringBufferFrames*blio->outputSampleSizeActual*blio->outChan );
      //PaUtil_AdvanceRingBufferWriteIndex( &blio->outputRingBuffer, blio->outputRingBuffer.bufferSize );

      /* Update isOutputFull. */
#ifdef PA_MAC__BLIO_MUTEX
      result = blioSetIsOutputFull( blio, toAdvance == blio->outputRingBuffer.bufferSize );
      if( result )
         goto error;
#endif
/*
      printf( "------%d\n" ,  blio->framesPerBuffer );
      printf( "------%d\n" ,  blio->outChan );
      printf( "------%d\n" ,  blio->outputSampleSize );
      printf( "------%d\n" ,  blio->framesPerBuffer*blio->outChan*blio->outputSampleSize );
*/
   }
   if( blio->inputRingBuffer.buffer ) {
      PaUtil_FlushRingBuffer( &blio->inputRingBuffer );
      bzero( blio->inputRingBuffer.buffer,
             blio->inputRingBuffer.bufferSize );
      /* Update isInputEmpty. */
#ifdef PA_MAC__BLIO_MUTEX
      result = blioSetIsInputEmpty( blio, true );
      if( result )
         goto error;
#endif
   }
   return paNoError;
#ifdef PA_MAC__BLIO_MUTEX
 error:
   return result;
#endif
}
示例#3
0
/***************************************************************************
** Return elements written. */
ring_buffer_size_t PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, ring_buffer_size_t elementCount )
{
    ring_buffer_size_t size1, size2, numWritten;
    void *data1, *data2;
    numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, elementCount, &data1, &size1, &data2, &size2 );
    if( size2 > 0 )
    {

        memcpy( data1, data, size1*rbuf->elementSizeBytes );
        data = ((char *)data) + size1*rbuf->elementSizeBytes;
        memcpy( data2, data, size2*rbuf->elementSizeBytes );
    }
    else
    {
        memcpy( data1, data, size1*rbuf->elementSizeBytes );
    }
    PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
    return numWritten;
}
示例#4
0
/***************************************************************************
** Return bytes written. */
long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes )
{
    long size1, size2, numWritten;
    void *data1, *data2;
    numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
    if( size2 > 0 )
    {

        memcpy( data1, data, size1 );
        data = ((char *)data) + size1;
        memcpy( data2, data, size2 );
    }
    else
    {
        memcpy( data1, data, size1 );
    }
    PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
    return numWritten;
}