当前位置: 首页>>代码示例>>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;未经允许,请勿转载。