コード例 #1
0
ファイル: pablio.c プロジェクト: AbrahamJewowich/FreeSWITCH
/* Called from PortAudio.
 * Read and write data 
 */
static int iblockingIOCallback(const void *inputBuffer, void *outputBuffer,
							   unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo * timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
{
	int c = 0, i = 0, j = 0;
	PABLIO_Stream *data = (PABLIO_Stream *) userData;
	long numBytes = data->bytesPerFrame * framesPerBuffer;
	const int16_t *inputSamples = inputBuffer;
	int16_t *chanSamples = (int16_t*)data->iobuff;

	/* This may get called with NULL inputBuffer during initial setup. */
	if (inputBuffer != NULL) {
		/* retrieve the data for each channel and put it in the ring buffer */
		for (c = 0; c < data->channelCount; c++) {
			for (i = 0, j = c; i < framesPerBuffer; j += data->channelCount, i++) {
				chanSamples[i] = inputSamples[j];
			}
			if (PaUtil_WriteRingBuffer(&data->inFIFOs[c], chanSamples, numBytes) != numBytes) {
				PaUtil_FlushRingBuffer(&data->inFIFOs[c]);
				PaUtil_WriteRingBuffer(&data->inFIFOs[c], chanSamples, numBytes);
			}
		}
	}

	return 0;
}
コード例 #2
0
ファイル: drm_portaudio.cpp プロジェクト: castrouk/LinDrm
_BOOLEAN
CPaCommon::Write(CVector < short >&psData)
{
    if (device_changed)
        ReInit();

    if (stream==NULL)
        return TRUE;

    size_t bytes = psData.Size() * sizeof(short);

    //cout << "Write: got " << bytes << " can put " << PaUtil_GetRingBufferWriteAvailable(&ringBuffer) << endl;
    if (PaUtil_GetRingBufferWriteAvailable(&ringBuffer) < int(bytes))
        return FALSE;			/* TODO use newer data in preference to draining old */

    PaUtil_WriteRingBuffer(&ringBuffer, &psData[0], bytes);
    if (Pa_IsStreamStopped( stream ))
    {
        int err = Pa_StartStream(stream);
        if (err != paNoError) {
            //throw string("PortAudio error: ") + Pa_GetErrorText(err);
		}
    }
    if (xruns==0)
        return FALSE;
    else
        cout << "underrun" << endl;
    xruns = 0;
    return TRUE;
}
コード例 #3
0
ファイル: CoreAudioAUHAL.cpp プロジェクト: aaronjb/plex
int CoreAudioAUHAL::WriteStream(uint8_t *sampleBuffer, uint32_t samplesToWrite)
{
	if (sampleBuffer == NULL || samplesToWrite == 0)
	{
		return 0;
	}
	return PaUtil_WriteRingBuffer(deviceParameters->outputBuffer, sampleBuffer, samplesToWrite);
}
コード例 #4
0
ファイル: MLRingBuffer.cpp プロジェクト: EQ4/madronalib
int MLRingBuffer::write(const MLSample* pSrc, int samples)
{
    int r = 0;
    if (pData)
    {
        r = PaUtil_WriteRingBuffer( &mBuf, pSrc, samples );
    }
    return r;
}
コード例 #5
0
ファイル: audiofifo.cpp プロジェクト: mandraga/Scoreview-Base
void CaudioFifo::push_output_samples(float *psamples, int size)
{
  int available;
  ring_buffer_size_t elementCount;

  assert(size == m_frame_size);
  available = PaUtil_GetRingBufferWriteAvailable(&m_rbufout);
  if (available > 0)
    {
      elementCount = 1;
      PaUtil_WriteRingBuffer(&m_rbufout, psamples, elementCount);
    }
}
コード例 #6
0
void MLPluginController::processFileFromCollection (MLSymbol action, const MLFile fileToProcess, const MLFileCollection& collection, int idx, int size)
{
	MLSymbol collectionName(collection.getName());
	if(action == "process")
	{
		if(collectionName.beginsWith(MLSymbol("convert_presets")))
		{			
			// add file action to queue
			FileAction f(action, fileToProcess, &collection, idx, size);
			PaUtil_WriteRingBuffer( &mFileActionQueue, &f, 1 );
		}
	}
}
コード例 #7
0
ファイル: MLReporter.cpp プロジェクト: drobilla/madronalib
void MLReporter::enqueuePropertyChange(MLSymbol prop, const MLProperty& newVal)
{
	// enqueue change
	int written = PaUtil_WriteRingBuffer( &mChangeQueue, &prop, 1 );

	// store changed value
	mCurrentProperties.setProperty(prop, newVal);
	
#if DEBUG
	if(written < 1)
	{
		debug() << "MLReporter::doPropertyChangeAction: ring buffer full! \n";
	}
#endif
}
コード例 #8
0
ファイル: main.cpp プロジェクト: rgerganov/usdr
static int record_callback(const void *in_buffer, void *out_buffer,
                           unsigned long frames_per_buffer,
                           const PaStreamCallbackTimeInfo* time_info,
                           PaStreamCallbackFlags status_flags,
                           void *user_data)
{
    PaUtilRingBuffer *rbuf = (PaUtilRingBuffer*)user_data;
    const float *rptr = (const float*)in_buffer;

    unsigned long written = PaUtil_WriteRingBuffer(rbuf, rptr, frames_per_buffer);
    if (written != frames_per_buffer) {
        fprintf(stderr, "Audio ring buffer overflow!\n");
        return paComplete;
    }
    return paContinue;
}
コード例 #9
0
ファイル: drm_portaudio.cpp プロジェクト: castrouk/LinDrm
/* This routine will be called by the PortAudio engine when audio is needed.
 * It may called at interrupt level on some machines so don't do anything
 * that could mess up the system like calling malloc() or free().
 */
static int
captureCallback(const void *inputBuffer, void *outputBuffer,
                unsigned long framesPerBuffer,
                const PaStreamCallbackTimeInfo *,
                PaStreamCallbackFlags statusFlags, void *userData)
{
    /* Cast data passed through stream to our structure. */
    CPaCommon *This = (CPaCommon *) userData;
    (void) outputBuffer;		/* Prevent unused variable warning. */
    long bytes = framesPerBuffer*2*sizeof(short);
    long avail = PaUtil_GetRingBufferWriteAvailable(&This->ringBuffer);
    PaUtil_WriteRingBuffer(&This->ringBuffer, inputBuffer, (avail<bytes)?avail:bytes);
    if (statusFlags&paInputOverflow)
        This->xruns++;
    return 0;
}
コード例 #10
0
ファイル: pablio.c プロジェクト: AbrahamJewowich/FreeSWITCH
/************************************************************
 * Write data to ring buffer.
 * Will not return until all the data has been written.
 */
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames, int chan, switch_timer_t *timer)
{
	long bytesWritten;
	char *p = (char *) data;
	long numBytes = aStream->bytesPerFrame * numFrames;

	switch_core_timer_next(timer);

	bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFOs[chan], p, numBytes);
	numBytes -= bytesWritten;
	p += bytesWritten;

	if (numBytes > 0) {
		PaUtil_FlushRingBuffer(&aStream->outFIFOs[chan]);
		return 0;
	}
	return numFrames;
}
コード例 #11
0
ファイル: Audiofile.cpp プロジェクト: NuclearFej/raindrop
uint32 AudioStream::Update()
{
	short tbuf[BUFF_SIZE];
	uint32 eCount = PaUtil_GetRingBufferWriteAvailable(&mRingBuf);
	uint32 ReadTotal;

	if (!mSource) return 0;

	mSource->SetLooping(IsLooping());

	if (ReadTotal = mSource->Read(tbuf, eCount))
	{
		PaUtil_WriteRingBuffer(&mRingBuf, tbuf, ReadTotal);
	}else
	{
		if (!PaUtil_GetRingBufferReadAvailable(&mRingBuf) && !mSource->HasDataLeft())
			mIsPlaying = false;
	}

	return ReadTotal;
}
コード例 #12
0
ファイル: audio.c プロジェクト: CREATEspace/VowelCat
static int recordCallback( const void *inputBuffer, void *outputBuffer,
                           unsigned long framesPerBuffer,
                           const PaStreamCallbackTimeInfo* timeInfo,
                           PaStreamCallbackFlags statusFlags,
                           void *userData)
{

    (void) outputBuffer;
    (void) timeInfo;
    (void) statusFlags;

    audio_t *a = userData;
    const audio_sample_t *rptr = inputBuffer;

    //********Pull samples from input buffer***************************
    PaUtil_WriteRingBuffer(&a->rb, &rptr[0], framesPerBuffer * a->n_channels);

    audio_wakeup(a);

    return paContinue;
}
コード例 #13
0
ファイル: MLProcRingBuffer.cpp プロジェクト: EQ4/madronalib
void MLProcRingBuffer::process(const int frames)
{
	int written;
	const MLSignal& x = getInput(1);

	// build if needed
	if (mParamsChanged) doParams();

	if (mRing.getBuffer())
	{	
		if (x.isConstant())
		{
			written = (int)PaUtil_WriteRingBufferConstant( &mBuf, x[0], frames );	
		}
		else
		{
			written = (int)PaUtil_WriteRingBuffer(&mBuf, (void *)x.getConstBuffer(), frames );	
		}
				
//	debug() << "wrote " << written << " from " << (void *)x.getConstBuffer() << "\n"; 
	}
}
コード例 #14
0
PaError WriteStream( PaStream* stream,
                            const void *buffer,
                            unsigned long frames )
{
    PaMacBlio *blio = & ((PaMacCoreStream*)stream) -> blio;
    char *cbuf = (char *) buffer;
    PaError ret = paNoError;
    VVDBUG(("WriteStream()\n"));

    while( frames > 0 ) {
       long avail = 0;
       long toWrite;

       do {
          avail = PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer );
/*
          printf( "Write Buffer is %%%g full: %ld of %ld.\n",
                  100 - 100 * (float)avail / (float) blio->outputRingBuffer.bufferSize,
                  avail, blio->outputRingBuffer.bufferSize );
*/
          if( avail == 0 ) {
#ifdef PA_MAC_BLIO_MUTEX
             /*block while full*/
             ret = UNIX_ERR( pthread_mutex_lock( &blio->outputMutex ) );
             if( ret )
                return ret;
             while( blio->isOutputFull ) {
                ret = UNIX_ERR( pthread_cond_wait( &blio->outputCond, &blio->outputMutex ) );
                if( ret )
                   return ret;
             }
             ret = UNIX_ERR( pthread_mutex_unlock( &blio->outputMutex ) );
             if( ret )
                return ret;
#else
             Pa_Sleep( PA_MAC_BLIO_BUSY_WAIT_SLEEP_INTERVAL );
#endif
          }
       } while( avail == 0 );

       toWrite = MIN( avail, frames * blio->outputSampleSizeActual * blio->outChan );
       toWrite -= toWrite % blio->outputSampleSizeActual * blio->outChan ;
       PaUtil_WriteRingBuffer( &blio->outputRingBuffer, (void *)cbuf, toWrite );
       cbuf += toWrite;
       frames -= toWrite / ( blio->outputSampleSizeActual * blio->outChan );

#ifdef PA_MAC_BLIO_MUTEX
       if( toWrite == avail ) {
          /* we just filled up the buffer, so we need to mark it as filled. */
          ret = blioSetIsOutputFull( blio, true );
          if( ret )
             return ret;
          /* of course, in the meantime, we may have emptied the buffer, so
             so check for that, too, to avoid a race condition. */
          if( PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer ) ) {
             blioSetIsOutputFull( blio, false );
             if( ret )
                return ret;
          }
       }
#endif
    }

    /*   Report either paNoError or paOutputUnderflowed. */
    /*   may also want to report other errors, but this is non-standard. */
    ret = blio->statusFlags & paOutputUnderflow;

    /* report underflow only once: */
    if( ret ) {
      OSAtomicAnd32( (uint32_t)(~paOutputUnderflow), &blio->statusFlags );
      ret = paOutputUnderflowed;
    }

    return ret;
}
コード例 #15
0
/*
 * this is the BlioCallback function. It expects to recieve a PaMacBlio Object
 * pointer as userData.
 *
 */
int BlioCallback( const void *input, void *output, unsigned long frameCount,
	const PaStreamCallbackTimeInfo* timeInfo,
        PaStreamCallbackFlags statusFlags,
        void *userData )
{
   PaMacBlio *blio = (PaMacBlio*)userData;
   long avail;
   long toRead;
   long toWrite;
   long read;
   long written;

   /* set flags returned by OS: */
   OSAtomicOr32( statusFlags, &blio->statusFlags ) ;

   /* --- Handle Input Buffer --- */
   if( blio->inChan ) {
      avail = PaUtil_GetRingBufferWriteAvailable( &blio->inputRingBuffer );

      /* check for underflow */
      if( avail < frameCount * blio->inputSampleSizeActual * blio->inChan )
      {
         OSAtomicOr32( paInputOverflow, &blio->statusFlags );
      }
      toRead = MIN( avail, frameCount * blio->inputSampleSizeActual * blio->inChan );

      /* copy the data */
      /*printf( "reading %d\n", toRead );*/
      read = PaUtil_WriteRingBuffer( &blio->inputRingBuffer, input, toRead );
      assert( toRead == read );
#ifdef PA_MAC__BLIO_MUTEX
      /* Priority inversion. See notes below. */
      blioSetIsInputEmpty( blio, false );
#endif
   }


   /* --- Handle Output Buffer --- */
   if( blio->outChan ) {
      avail = PaUtil_GetRingBufferReadAvailable( &blio->outputRingBuffer );

      /* check for underflow */
      if( avail < frameCount * blio->outputSampleSizeActual * blio->outChan )
         OSAtomicOr32( paOutputUnderflow, &blio->statusFlags );

      toWrite = MIN( avail, frameCount * blio->outputSampleSizeActual * blio->outChan );

      if( toWrite != frameCount * blio->outputSampleSizeActual * blio->outChan )
         bzero( ((char *)output)+toWrite,
                frameCount * blio->outputSampleSizeActual * blio->outChan - toWrite );
      /* copy the data */
      /*printf( "writing %d\n", toWrite );*/
      written = PaUtil_ReadRingBuffer( &blio->outputRingBuffer, output, toWrite );
      assert( toWrite == written );
#ifdef PA_MAC__BLIO_MUTEX
      /* We have a priority inversion here. However, we will only have to
         wait if this was true and is now false, which means we've got
         some room in the buffer.
         Hopefully problems will be minimized. */
      blioSetIsOutputFull( blio, false );
#endif
   }

   return paContinue;
}
コード例 #16
0
ファイル: pa_mac_core_blocking.c プロジェクト: Dagarman/mame
/*
 * this is the BlioCallback function. It expects to recieve a PaMacBlio Object
 * pointer as userData.
 *
 */
int BlioCallback( const void *input, void *output, unsigned long frameCount,
	const PaStreamCallbackTimeInfo* timeInfo,
        PaStreamCallbackFlags statusFlags,
        void *userData )
{
   PaMacBlio *blio = (PaMacBlio*)userData;
   ring_buffer_size_t framesAvailable;
   ring_buffer_size_t framesToTransfer;
   ring_buffer_size_t framesTransferred;

   /* set flags returned by OS: */
   OSAtomicOr32( statusFlags, &blio->statusFlags ) ;

   /* --- Handle Input Buffer --- */
   if( blio->inChan ) {
      framesAvailable = PaUtil_GetRingBufferWriteAvailable( &blio->inputRingBuffer );

      /* check for underflow */
      if( framesAvailable < frameCount )
      {
          OSAtomicOr32( paInputOverflow, &blio->statusFlags );
          framesToTransfer = framesAvailable;
      }
      else
      {
          framesToTransfer = (ring_buffer_size_t)frameCount;
      }

      /* Copy the data from the audio input to the application ring buffer. */
      /*printf( "reading %d\n", toRead );*/
      framesTransferred = PaUtil_WriteRingBuffer( &blio->inputRingBuffer, input, framesToTransfer );
      assert( framesToTransfer == framesTransferred );
#ifdef PA_MAC__BLIO_MUTEX
      /* Priority inversion. See notes below. */
      blioSetIsInputEmpty( blio, false );
#endif
   }


   /* --- Handle Output Buffer --- */
   if( blio->outChan ) {
      framesAvailable = PaUtil_GetRingBufferReadAvailable( &blio->outputRingBuffer );

      /* check for underflow */
      if( framesAvailable < frameCount )
      {
          /* zero out the end of the output buffer that we do not have data for */
          framesToTransfer = framesAvailable;

          size_t bytesPerFrame = blio->outputSampleSizeActual * blio->outChan;
          size_t offsetInBytes = framesToTransfer * bytesPerFrame;
          size_t countInBytes = (frameCount - framesToTransfer) * bytesPerFrame;
          bzero( ((char *)output) + offsetInBytes, countInBytes );

          OSAtomicOr32( paOutputUnderflow, &blio->statusFlags );
          framesToTransfer = framesAvailable;
      }
      else
      {
          framesToTransfer = (ring_buffer_size_t)frameCount;
      }

      /* copy the data */
      /*printf( "writing %d\n", toWrite );*/
      framesTransferred = PaUtil_ReadRingBuffer( &blio->outputRingBuffer, output, framesToTransfer );
      assert( framesToTransfer == framesTransferred );
#ifdef PA_MAC__BLIO_MUTEX
      /* We have a priority inversion here. However, we will only have to
         wait if this was true and is now false, which means we've got
         some room in the buffer.
         Hopefully problems will be minimized. */
      blioSetIsOutputFull( blio, false );
#endif
   }

   return paContinue;
}
コード例 #17
0
ファイル: pa_mac_core_blocking.c プロジェクト: Dagarman/mame
PaError WriteStream( PaStream* stream,
                            const void *buffer,
                            unsigned long framesRequested )
{
    PaMacCoreStream *macStream = (PaMacCoreStream*)stream;
    PaMacBlio *blio = &macStream->blio;
    char *cbuf = (char *) buffer;
    PaError ret = paNoError;
    VVDBUG(("WriteStream()\n"));

    while( framesRequested > 0 && macStream->state != STOPPING ) {
        ring_buffer_size_t framesAvailable;
        ring_buffer_size_t framesToTransfer;
        ring_buffer_size_t framesTransferred;

       do {
          framesAvailable = PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer );
/*
          printf( "Write Buffer is %%%g full: %ld of %ld.\n",
                  100 - 100 * (float)avail / (float) blio->outputRingBuffer.bufferSize,
                  framesAvailable, blio->outputRingBuffer.bufferSize );
*/
          if( framesAvailable == 0 ) {
#ifdef PA_MAC_BLIO_MUTEX
             /*block while full*/
             ret = UNIX_ERR( pthread_mutex_lock( &blio->outputMutex ) );
             if( ret )
                return ret;
             while( blio->isOutputFull ) {
                ret = UNIX_ERR( pthread_cond_wait( &blio->outputCond, &blio->outputMutex ) );
                if( ret )
                   return ret;
             }
             ret = UNIX_ERR( pthread_mutex_unlock( &blio->outputMutex ) );
             if( ret )
                return ret;
#else
             Pa_Sleep( PA_MAC_BLIO_BUSY_WAIT_SLEEP_INTERVAL );
#endif
          }
       } while( framesAvailable == 0 && macStream->state != STOPPING );

       if( macStream->state == STOPPING )
       {
           break;
       }

       framesToTransfer = MIN( framesAvailable, framesRequested );
       framesTransferred = PaUtil_WriteRingBuffer( &blio->outputRingBuffer, (void *)cbuf, framesToTransfer );
       cbuf += framesTransferred * blio->outputSampleSizeActual * blio->outChan;
       framesRequested -= framesTransferred;

#ifdef PA_MAC_BLIO_MUTEX
       if( framesToTransfer == framesAvailable ) {
          /* we just filled up the buffer, so we need to mark it as filled. */
          ret = blioSetIsOutputFull( blio, true );
          if( ret )
             return ret;
          /* of course, in the meantime, we may have emptied the buffer, so
             so check for that, too, to avoid a race condition. */
          if( PaUtil_GetRingBufferWriteAvailable( &blio->outputRingBuffer ) ) {
             blioSetIsOutputFull( blio, false );
              /* FIXME remove or review this code, does not fix race, ret not set! */
             if( ret )
                return ret;
          }
       }
#endif
    }

    if ( macStream->state == STOPPING )
    {
        ret = paInternalError;
    }
    else if (ret == paNoError )
    {
        /*   Test for underflow. */
        ret = blio->statusFlags & paOutputUnderflow;

        /* report underflow only once: */
        if( ret )
        {
            OSAtomicAnd32( (uint32_t)(~paOutputUnderflow), &blio->statusFlags );
            ret = paOutputUnderflowed;
        }
    }

    return ret;
}