1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-12 09:09:38 +01:00
libtgvoip/os/darwin/AudioInputAudioUnit.cpp

61 lines
1.5 KiB
C++
Raw Normal View History

2017-02-02 17:24:40 +01:00
//
// libtgvoip is free and unencumbered public domain software.
// For more information, see http://unlicense.org or the UNLICENSE file
// you should have received with this source code distribution.
//
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "AudioUnitIO.h"
#include "AudioInputAudioUnit.h"
#include "../../logging.h"
#define BUFFER_SIZE 960
using namespace tgvoip;
using namespace tgvoip::audio;
AudioInputAudioUnit::AudioInputAudioUnit(){
2017-02-02 17:24:40 +01:00
remainingDataSize=0;
isRecording=false;
this->io=AudioUnitIO::Get();
2017-02-02 17:24:40 +01:00
io->AttachInput(this);
}
AudioInputAudioUnit::~AudioInputAudioUnit(){
2017-02-02 17:24:40 +01:00
io->DetachInput();
AudioUnitIO::Release();
2017-02-02 17:24:40 +01:00
}
void AudioInputAudioUnit::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){
2017-02-02 17:24:40 +01:00
io->Configure(sampleRate, bitsPerSample, channels);
}
void AudioInputAudioUnit::Start(){
2017-02-02 17:24:40 +01:00
isRecording=true;
io->EnableInput(true);
}
void AudioInputAudioUnit::Stop(){
2017-02-02 17:24:40 +01:00
isRecording=false;
io->EnableInput(false);
}
void AudioInputAudioUnit::HandleBufferCallback(AudioBufferList *ioData){
2017-02-02 17:24:40 +01:00
int i;
for(i=0;i<ioData->mNumberBuffers;i++){
AudioBuffer buf=ioData->mBuffers[i];
assert(remainingDataSize+buf.mDataByteSize<10240);
memcpy(remainingData+remainingDataSize, buf.mData, buf.mDataByteSize);
remainingDataSize+=buf.mDataByteSize;
while(remainingDataSize>=BUFFER_SIZE*2){
InvokeCallback((unsigned char*)remainingData, BUFFER_SIZE*2);
remainingDataSize-=BUFFER_SIZE*2;
if(remainingDataSize>0){
memmove(remainingData, remainingData+(BUFFER_SIZE*2), remainingDataSize);
}
}
}
}