1
0
mirror of https://github.com/danog/libtgvoip.git synced 2024-12-04 02:27:46 +01:00
libtgvoip/os/darwin/AudioInputAudioUnit.cpp
Grishka 333c4a1101 Added working audio i/o for OS X
Added simple audio resampler
Replaced prebuilt static libs with their sources & added that to all project files (closes #5)
2017-04-09 19:14:33 +03:00

58 lines
1.5 KiB
C++

//
// 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
CAudioInputAudioUnit::CAudioInputAudioUnit(){
remainingDataSize=0;
isRecording=false;
this->io=CAudioUnitIO::Get();
io->AttachInput(this);
}
CAudioInputAudioUnit::~CAudioInputAudioUnit(){
io->DetachInput();
CAudioUnitIO::Release();
}
void CAudioInputAudioUnit::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){
io->Configure(sampleRate, bitsPerSample, channels);
}
void CAudioInputAudioUnit::Start(){
isRecording=true;
io->EnableInput(true);
}
void CAudioInputAudioUnit::Stop(){
isRecording=false;
io->EnableInput(false);
}
void CAudioInputAudioUnit::HandleBufferCallback(AudioBufferList *ioData){
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);
}
}
}
}