當前位置: 首頁>>代碼示例>>C++>>正文


C++ AudioQueueEnqueueBuffer函數代碼示例

本文整理匯總了C++中AudioQueueEnqueueBuffer函數的典型用法代碼示例。如果您正苦於以下問題:C++ AudioQueueEnqueueBuffer函數的具體用法?C++ AudioQueueEnqueueBuffer怎麽用?C++ AudioQueueEnqueueBuffer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了AudioQueueEnqueueBuffer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: record_handler

static void record_handler(void *userData, AudioQueueRef inQ,
			   AudioQueueBufferRef inQB,
			   const AudioTimeStamp *inStartTime,
			   UInt32 inNumPackets,
			   const AudioStreamPacketDescription *inPacketDesc)
{
	struct ausrc_st *st = userData;
	unsigned int ptime;
	ausrc_read_h *rh;
	void *arg;
	(void)inStartTime;
	(void)inNumPackets;
	(void)inPacketDesc;

	pthread_mutex_lock(&st->mutex);
	ptime = st->ptime;
	rh  = st->rh;
	arg = st->arg;
	pthread_mutex_unlock(&st->mutex);

	if (!rh)
		return;

	rh(inQB->mAudioData, inQB->mAudioDataByteSize/2, arg);

	AudioQueueEnqueueBuffer(inQ, inQB, 0, NULL);

	/* Force a sleep here, coreaudio's timing is too fast */
#if !TARGET_OS_IPHONE
#define ENCODE_TIME 1000
	usleep((ptime * 1000) - ENCODE_TIME);
#endif
}
開發者ID:AmesianX,項目名稱:baresip,代碼行數:33,代碼來源:recorder.c

示例2: AudioQueueEnqueueBuffer

bool Device::add(audio::Buffer &buf)
{
# ifdef NNT_MACH
    
    int suc = 0;
    for (core::vector<AudioQueueBufferRef>::iterator each = buf.handle().begin();
         each != buf.handle().end();
         ++each)
    {
        OSStatus sta = AudioQueueEnqueueBuffer(buf.queue, *each, 0, NULL);
        if (sta)
        {
            trace_msg("failed to add audio buffer");
        }
        else
        {
            ++suc;
        }
    }
    
    // if success, the buffer will freed when dispose the queue.
    buf.need_release = suc == 0;
    
    return suc != 0;
    
# endif
    return false;
}
開發者ID:imace,項目名稱:nnt,代碼行數:28,代碼來源:MicDevice.cpp

示例3: auAudioOutputCallback

void  auAudioOutputCallback(void *SELF, AudioQueueRef queue, AudioQueueBufferRef buffer)
{
  Audio* self = (Audio*) SELF;
  int resultFrames = self->audioCallback(SELF, (auSample_t*)buffer->mAudioData, (buffer->mAudioDataBytesCapacity / self->dataFormat.mBytesPerFrame), self->dataFormat.mChannelsPerFrame);
  buffer->mAudioDataByteSize = resultFrames * self->dataFormat.mBytesPerFrame;//buffer->mAudioDataBytesCapacity;
  AudioQueueEnqueueBuffer(queue, buffer, 0, NULL);
}
開發者ID:masinde70,項目名稱:Everything,代碼行數:7,代碼來源:AudioSuperclass.c

示例4: auPlay

/*auStart-------------------------------------------------*/
BOOL auPlay(Audio* self)
{ 
  if(!self->isPlaying)
    {

#ifdef __APPLE__
      int i;
      for(i=0; i<AU_NUM_AUDIO_BUFFERS; i++)
        {
          if(self->isOutput)
            auAudioOutputCallback(self, self->queue, self->buffers[i]);
          else
            AudioQueueEnqueueBuffer(self->queue, self->buffers[i],0, NULL);
        }
      OSStatus error = AudioQueueStart(self->queue, NULL);
      if(error) fprintf(stderr, "Audio.c: unable to start queue\n");

#elif defined __linux__
      int error = pthread_create(&(self->thread), NULL, auAudioCallback, self);
      if(error != 0) perror("Audio.c: error creating Audio thread");

#endif
      else self->isPlaying = YES;
    }
    
  return self->isPlaying;
}
開發者ID:masinde70,項目名稱:Everything,代碼行數:28,代碼來源:AudioSuperclass.c

示例5: MyAQInputCallback

// Audio Queue callback function, called when an input buffer has been filled.
static void MyAQInputCallback(void *inUserData, AudioQueueRef inQueue,
							  AudioQueueBufferRef inBuffer,
							  const AudioTimeStamp *inStartTime,
							  UInt32 inNumPackets,
							  const AudioStreamPacketDescription *inPacketDesc)
{
	MyRecorder *recorder = (MyRecorder *)inUserData;
	
	// if inNumPackets is greater then zero, our buffer contains audio data
	// in the format we specified (AAC)
	if (inNumPackets > 0)
	{
		// write packets to file
		CheckError(AudioFileWritePackets(recorder->recordFile, FALSE, inBuffer->mAudioDataByteSize,
										 inPacketDesc, recorder->recordPacket, &inNumPackets, 
										 inBuffer->mAudioData), "AudioFileWritePackets failed");
		// increment packet index
		recorder->recordPacket += inNumPackets;
	}
	
	// if we're not stopping, re-enqueue the buffer so that it gets filled again
	if (recorder->running)
		CheckError(AudioQueueEnqueueBuffer(inQueue, inBuffer,
										   0, NULL), "AudioQueueEnqueueBuffer failed");
}
開發者ID:JasonMcClinsey,項目名稱:Learning-Core-Audio-Book-Code-Sample,代碼行數:26,代碼來源:main.c

示例6: bzero

void CAudioQueueManager::_HandleOutputBuffer(AudioQueueBufferRef outBuffer) {
	if (!_isRunning || _soundQBuffer.SoundCount() == 0) {
		outBuffer->mAudioDataByteSize = outBuffer->mAudioDataBytesCapacity;
        bzero(outBuffer->mAudioData, outBuffer->mAudioDataBytesCapacity);
	} else {
		
		int neededFrames = _framesPerBuffer;
		unsigned char* buf = (unsigned char*)outBuffer->mAudioData;
		int bytesInBuffer = 0;

		for ( ; _soundQBuffer.SoundCount() && neededFrames; neededFrames--) {
			short* buffer = _soundQBuffer.DequeueSoundBuffer();
			memcpy(buf, buffer, _bytesPerQueueBuffer);
			_soundQBuffer.EnqueueFreeBuffer(buffer);
			OSAtomicAdd32(-_sampleFrameCount, &_samplesInQueue);
			buf += _bytesPerQueueBuffer;
			bytesInBuffer += _bytesPerQueueBuffer;
		}
		
		outBuffer->mAudioDataByteSize = bytesInBuffer;
#if defined(DEBUG_SOUND)
		if (outBuffer->mAudioDataByteSize == 0)
			printf("audio buffer underrun.");
		else if (outBuffer->mAudioDataByteSize < outBuffer->mAudioDataBytesCapacity) 
			printf("audio buffer less than capacity %u < %u.", (unsigned int)outBuffer->mAudioDataByteSize, (unsigned int)outBuffer->mAudioDataBytesCapacity);
#endif
	}
	
	OSStatus res = AudioQueueEnqueueBuffer(_queue, outBuffer, 0, NULL);
	if (res != 0)
		throw "Unable to enqueue buffer";
}
開發者ID:mdbergmann,項目名稱:iAmiga,代碼行數:32,代碼來源:AudioQueueManager.cpp

示例7: upipe_osx_audioqueue_sink_input_audio

/** @internal @This handles audio input.
 *
 * @param upipe description structure of the pipe
 * @param uref uref structure
 * @param upump_p reference to upump structure
 */
static void upipe_osx_audioqueue_sink_input_audio(struct upipe *upipe,
        struct uref *uref, struct upump **upump_p)
{
    struct upipe_osx_audioqueue_sink *osx_audioqueue =
        upipe_osx_audioqueue_sink_from_upipe(upipe);
    struct AudioQueueBuffer *qbuf;
    size_t size = 0;

    if (unlikely(!ubase_check(uref_block_size(uref, &size)))) {
        upipe_warn(upipe, "could not get block size");
        uref_free(uref);
        return;
    }

    /* TODO block ? */
#if 0
    upump_mgr_use(upump->mgr);
    upump_mgr_sink_block(upump->mgr);
#endif

    /* allocate queue buf, extract block, enqueue
     * Audioqueue has no support for "external" buffers */
    AudioQueueAllocateBuffer(osx_audioqueue->queue, size, &qbuf);
    uref_block_extract(uref, 0, -1, qbuf->mAudioData);
    qbuf->mAudioDataByteSize = size;
    qbuf->mUserData = (*upump_p)->mgr;
    AudioQueueEnqueueBuffer(osx_audioqueue->queue, qbuf, 0, NULL);

    uref_free(uref);
}
開發者ID:cmassiot,項目名稱:upipe,代碼行數:36,代碼來源:upipe_osx_audioqueue_sink.c

示例8: sizeof

void AudioPluginOSX::AudioCallback(void * arg, AudioQueueRef queue, AudioQueueBufferRef buffer)
{

	AudioPluginOSX * plugin = static_cast<AudioPluginOSX *>(arg);

	u32 num_samples     = buffer->mAudioDataBytesCapacity / sizeof(Sample);
	u32 samples_written = plugin->mAudioBuffer.Drain(static_cast<Sample *>(buffer->mAudioData), num_samples);

	u32 remaining_samples = plugin->mAudioBuffer.GetNumBufferedSamples();
	plugin->mBufferLenMs = (1000 * remaining_samples) / kOutputFrequency;

	float ms = (float)samples_written * 1000.f / (float)kOutputFrequency;
	DPF_AUDIO("Playing %d samples @%dHz - %.2fms - bufferlen now %d\n",
			samples_written, kOutputFrequency, ms, plugin->mBufferLenMs);

	if (samples_written == 0)
	{
		// Would be nice to sleep here until we have something to play,
		// but AudioQueue doesn't seem to like that.
		// Leave the buffer untouched, and requeue for now.
		DPF_AUDIO("********************* Audio buffer is empty ***********************\n");
	}
	else
	{
		buffer->mAudioDataByteSize = samples_written * sizeof(Sample);
	}

	AudioQueueEnqueueBuffer(queue, buffer, 0, NULL);

	if (!plugin->mKeepRunning)
	{
		CFRunLoopStop(CFRunLoopGetCurrent());
	}

}
開發者ID:ThePhoenixRises,項目名稱:daedalus,代碼行數:35,代碼來源:AudioPluginOSX.cpp

示例9: AudioQueueCallback

void AudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) {
    audio_output_t * p_aout = (audio_output_t *)inUserData;
    block_t *   p_buffer = NULL;

    if (p_aout) {
        struct aout_sys_t * p_sys = p_aout->sys;
        aout_packet_t * packet = &p_sys->packet;

        if (packet)
        {
            vlc_mutex_lock( &packet->lock );
            p_buffer = aout_FifoPop2( &packet->fifo );
            vlc_mutex_unlock( &packet->lock );
        }
    }

    if ( p_buffer != NULL ) {
        memcpy( inBuffer->mAudioData, p_buffer->p_buffer, p_buffer->i_buffer );
        inBuffer->mAudioDataByteSize = p_buffer->i_buffer;
        block_Release( p_buffer );
    } else {
        memset( inBuffer->mAudioData, 0, inBuffer->mAudioDataBytesCapacity );
        inBuffer->mAudioDataByteSize = inBuffer->mAudioDataBytesCapacity;
    }
    AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL);
}
開發者ID:RodrigoNieves,項目名稱:vlc,代碼行數:26,代碼來源:audioqueue.c

示例10: MyAQOutputCallback

static void MyAQOutputCallback(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer) 
{
	MyPlayer *aqp = (MyPlayer*)inUserData;
	if (aqp->isDone) return;
	
	// read audio data from file into supplied buffer
	UInt32 numBytes;
	UInt32 nPackets = aqp->numPacketsToRead;	
	CheckError(AudioFileReadPackets(aqp->playbackFile,
									false,
									&numBytes,
									aqp->packetDescs,
									aqp->packetPosition,
									&nPackets,
									inCompleteAQBuffer->mAudioData),
			   "AudioFileReadPackets failed");
	
	// enqueue buffer into the Audio Queue
	// if nPackets == 0 it means we are EOF (all data has been read from file)
	if (nPackets > 0)
	{
		inCompleteAQBuffer->mAudioDataByteSize = numBytes;		
		AudioQueueEnqueueBuffer(inAQ,
								inCompleteAQBuffer,
								(aqp->packetDescs ? nPackets : 0),
								aqp->packetDescs);
		aqp->packetPosition += nPackets;
	}
	else
	{
		CheckError(AudioQueueStop(inAQ, false), "AudioQueueStop failed");
		aqp->isDone = true;
	}
}
開發者ID:Contexter,項目名稱:learning-core-audio-xcode4-projects,代碼行數:34,代碼來源:main.c

示例11: printf

void WavPlayer::aqBufferCallback(void *in, AudioQueueRef inQ, AudioQueueBufferRef outQB)
{
    AQCallbackStruct *aqc;
    unsigned char *coreAudioBuffer;

    aqc = (AQCallbackStruct *) in;
    coreAudioBuffer = (unsigned char*) outQB->mAudioData;

    printf("Sync: %u / %u\n", (unsigned int)aqc->PlayPtr, (unsigned int)aqc->SampleLen);

    if(aqc->FrameCount > 0)
    {
        outQB->mAudioDataByteSize = aqc->DataFormat.mBytesPerFrame * aqc->FrameCount;
        for(int i = 0; i < aqc->FrameCount * aqc->DataFormat.mBytesPerFrame; i++)
        {
            if(aqc->PlayPtr > aqc->SampleLen)
            {
                aqc->PlayPtr = 0;
                i = 0;
            }
            coreAudioBuffer[i] = aqc->PCMBuffer[aqc->PlayPtr];
            aqc->PlayPtr++;
        }
        AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
    }
}
開發者ID:SabastianMugazambi,項目名稱:Stellar,代碼行數:26,代碼來源:OSX_WavPlayer.cpp

示例12: MyInputBufferHandler

// ____________________________________________________________________________________
// AudioQueue callback function, called when an input buffers has been filled.
static void MyInputBufferHandler(	void *                          inUserData,
									AudioQueueRef                   inAQ,
									AudioQueueBufferRef             inBuffer,
									const AudioTimeStamp *          inStartTime,
									UInt32							inNumPackets,
									const AudioStreamPacketDescription *inPacketDesc)
{
	MyRecorder *aqr = (MyRecorder *)inUserData;

	try {
		if (aqr->verbose) {
			printf("buf data %p, 0x%x bytes, 0x%x packets\n", inBuffer->mAudioData,
				(int)inBuffer->mAudioDataByteSize, (int)inNumPackets);
		}
		
		if (inNumPackets > 0) {
			// write packets to file
			XThrowIfError(AudioFileWritePackets(aqr->recordFile, FALSE, inBuffer->mAudioDataByteSize,
				inPacketDesc, aqr->recordPacket, &inNumPackets, inBuffer->mAudioData),
				"AudioFileWritePackets failed");
			aqr->recordPacket += inNumPackets;
		}

		// if we're not stopping, re-enqueue the buffe so that it gets filled again
		if (aqr->running)
			XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL), "AudioQueueEnqueueBuffer failed");
	} 
	catch (CAXException e) {
		char buf[256];
		fprintf(stderr, "MyInputBufferHandler: %s (%s)\n", e.mOperation, e.FormatError(buf));
	}	
}
開發者ID:AdamDiment,項目名稱:CocoaSampleCode,代碼行數:34,代碼來源:aqrecord.cpp

示例13: AudioQueueFlush

    void AudioOutputDeviceCoreAudio::HandleOutputBuffer (
        void                 *aqData,
        AudioQueueRef        inAQ,
        AudioQueueBufferRef  inBuffer
    ) {
        AQPlayerState* pAqData = (AQPlayerState*) aqData;
        if (atomic_read(&(pAqData->mIsRunning)) == 0) {
            AudioQueueFlush(pAqData->mQueue);
            AudioQueueStop (pAqData->mQueue, true);
            return;
        }

        if(atomic_read(&(pAqData->pDevice->restartQueue))) return;

        uint bufferSize = pAqData->pDevice->uiBufferSize;

        // let all connected engines render 'fragmentSize' sample points
        pAqData->pDevice->RenderAudio(bufferSize);

        Float32* pDataBuf = (Float32*)(inBuffer->mAudioData);

        uint uiCoreAudioChannels = pAqData->pDevice->uiCoreAudioChannels;
        for (int c = 0; c < uiCoreAudioChannels; c++) {
            float* in  = pAqData->pDevice->Channels[c]->Buffer();
            for (int i = 0, o = c; i < bufferSize; i++ , o += uiCoreAudioChannels) {
                pDataBuf[o] = in[i];
            }
        }

        inBuffer->mAudioDataByteSize = (uiCoreAudioChannels * 4) * bufferSize;

        OSStatus res = AudioQueueEnqueueBuffer(pAqData->mQueue, inBuffer, 0, NULL);
        if(res) std::cerr << "AudioQueueEnqueueBuffer: Error " << res << std::endl;
    }
開發者ID:svn2github,項目名稱:linuxsampler,代碼行數:34,代碼來源:AudioOutputDeviceCoreAudio.cpp

示例14: AudioEnginePropertyListenerProc

void AudioEnginePropertyListenerProc (void *inUserData, AudioQueueRef inAQ, AudioQueuePropertyID inID) {
    //We are only interested in the property kAudioQueueProperty_IsRunning
    if (inID != kAudioQueueProperty_IsRunning) return;

	struct myAQStruct *myInfo = (struct myAQStruct *)inUserData;

	/* Get the current status of the AQ, running or stopped */ 
    UInt32 isQueueRunning = false;
    UInt32 size = sizeof(isQueueRunning);
    AudioQueueGetProperty(myInfo->mQueue, kAudioQueueProperty_IsRunning, &isQueueRunning, &size);

	/* The callback event is the start of the queue */
    if (isQueueRunning) {
		/* reset current packet counter */
        myInfo->mCurrentPacket = 0;

        for (int i = 0; i < 3; i++) {
			/*
			 * For the first time allocate buffers for this AQ.
			 * Buffers are reused in turns until the AQ stops 
			 */
            AudioQueueAllocateBuffer(myInfo->mQueue, bufferSizeInSamples * 4, &myInfo->mBuffers[i]);

            UInt32 bytesRead = bufferSizeInSamples * 4;
            UInt32 packetsRead = bufferSizeInSamples;

			/*
			 * Read data from audio source into the buffer of AQ
			 * supplied in this callback event. Buffers are used in turns
			 * to hide the latency
			 */
            AudioFileReadPacketData(
					myInfo->mAudioFile,
					false, /* isUseCache, set to false */
					&bytesRead,
					NULL,
					myInfo->mCurrentPacket,
					&packetsRead,
					myInfo->mBuffers[i]->mAudioData);
			/* in case the buffer size is smaller than bytes requestd to read */ 
            myInfo->mBuffers[i]->mAudioDataByteSize = bytesRead;
            myInfo->mCurrentPacket += packetsRead;

            AudioQueueEnqueueBuffer(myInfo->mQueue, myInfo->mBuffers[i], 0, NULL);
        }
    } else {
		/* The callback event is the state of AQ changed to not running */
        if (myInfo->mAudioFile != NULL) {
			AudioQueueStop(myInfo->mQueue, false);
            AudioFileClose(myInfo->mAudioFile);
            myInfo->mAudioFile = NULL;

            for (int i = 0; i < 3; i++) {
                AudioQueueFreeBuffer(myInfo->mQueue, myInfo->mBuffers[i]);
                myInfo->mBuffers[i] = NULL;
            }
			CFRunLoopStop(CFRunLoopGetCurrent());
        }
    }
}
開發者ID:styxyang,項目名稱:codelib,代碼行數:60,代碼來源:audio.c

示例15: AQBufferCallback

void AQBufferCallback(void *in,
                      AudioQueueRef inQ,
                      AudioQueueBufferRef outQB) {
    AQCallbackStruct *aqc;
    short *coreAudioBuffer;
    short sample;
    int i;
    
    aqc = (AQCallbackStruct *) in;
    coreAudioBuffer = (short*) outQB->mAudioData;
    
    printf("Sync: %ld / %ld\n", aqc->playPtr, aqc->sampleLen);
    if (aqc->playPtr >= aqc->sampleLen) {
        AudioQueueDispose(aqc->queue, true);
        return;
    }
    
    if (aqc->frameCount > 0) {
        outQB->mAudioDataByteSize = 4 * aqc->frameCount;
        for(i=0; i<aqc->frameCount*2; i+=2) {
            if (aqc->playPtr > aqc->sampleLen)
                sample = 0;
            else
                sample = (aqc->pcmBuffer[aqc->playPtr]);
            coreAudioBuffer[i] =   sample;
            coreAudioBuffer[i+1] = sample;
            aqc->playPtr++;
        }
        AudioQueueEnqueueBuffer(inQ, outQB, 0, NULL);
    }
}
開發者ID:zichuanwang,項目名稱:db_client,代碼行數:31,代碼來源:pcmplayer.cpp


注:本文中的AudioQueueEnqueueBuffer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。