Created
May 21, 2016 18:05
-
-
Save LinusU/b1bfe4f0c63dd82332c38181686f5976 to your computer and use it in GitHub Desktop.
Minimal CoreAudio line in example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <CoreAudio/CoreAudio.h> | |
#include <AudioToolbox/AudioToolbox.h> | |
#include <iostream> | |
static const int kNumberBuffers = 3; | |
static const int kBufferByteSize = 8192; | |
void callback (void *userData, AudioQueueRef queue, AudioQueueBufferRef buffer, const AudioTimeStamp *startTime, UInt32 inumberPacketDescriptions, const AudioStreamPacketDescription *packetDescs) { | |
OSStatus status; | |
std::cout << buffer->mAudioDataBytesCapacity << std::endl; | |
status = AudioQueueEnqueueBuffer(queue, buffer, 0, nullptr); | |
if (status != 0) exit(5); | |
} | |
int main() { | |
OSStatus status; | |
AudioStreamBasicDescription desc; | |
desc.mSampleRate = 44100; | |
desc.mFormatID = kAudioFormatLinearPCM; | |
desc.mFormatFlags = kAudioFormatFlagIsSignedInteger; | |
desc.mBytesPerPacket = 0; | |
desc.mFramesPerPacket = 1; | |
desc.mBytesPerFrame = 0; | |
desc.mChannelsPerFrame = 2; | |
desc.mBitsPerChannel = 16; | |
desc.mReserved = 0; | |
AudioQueueRef queue; | |
status = AudioQueueNewInput(&desc, callback, nullptr, nullptr, nullptr, 0, &queue); | |
if (status != 0) return 1; | |
status = AudioQueueStart(queue, nullptr); | |
if (status != 0) return 2; | |
for (int i = 0; i < kNumberBuffers; ++i) { | |
AudioQueueBufferRef buffer; | |
status = AudioQueueAllocateBuffer(queue, kBufferByteSize, &buffer); | |
if (status != 0) return 3; | |
status = AudioQueueEnqueueBuffer(queue, buffer, 0, nullptr); | |
if (status != 0) return 4; | |
} | |
getchar(); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
line-in: | |
clang++ darwin.cc -framework AudioToolBox -framework CoreFoundation -o line-in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gives [aqme] 318: error -66680 finding/initializing AQDefaultInput