| 1 |
/* |
|---|
| 2 |
Copyright (C) 2009 Grame |
|---|
| 3 |
|
|---|
| 4 |
This program is free software; you can redistribute it and/or modify |
|---|
| 5 |
it under the terms of the GNU General Public License as published by |
|---|
| 6 |
the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 |
(at your option) any later version. |
|---|
| 8 |
|
|---|
| 9 |
This program is distributed in the hope that it will be useful, |
|---|
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
GNU General Public License for more details. |
|---|
| 13 |
|
|---|
| 14 |
You should have received a copy of the GNU General Public License |
|---|
| 15 |
along with this program; if not, write to the Free Software |
|---|
| 16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 17 |
|
|---|
| 18 |
*/ |
|---|
| 19 |
|
|---|
| 20 |
#ifndef __JackAudioQueueAdapter__ |
|---|
| 21 |
#define __JackAudioQueueAdapter__ |
|---|
| 22 |
|
|---|
| 23 |
//#include <AudioToolbox/AudioConverter.h> |
|---|
| 24 |
//#include <AudioToolbox/AudioQueue.h> |
|---|
| 25 |
|
|---|
| 26 |
#include <AudioToolbox/AudioToolbox.h> |
|---|
| 27 |
|
|---|
| 28 |
#include <jack/net.h> |
|---|
| 29 |
|
|---|
| 30 |
namespace Jack |
|---|
| 31 |
{ |
|---|
| 32 |
|
|---|
| 33 |
/*! |
|---|
| 34 |
\brief Audio adapter using AudioQueue API. |
|---|
| 35 |
*/ |
|---|
| 36 |
|
|---|
| 37 |
#define kNumberBuffers 3 |
|---|
| 38 |
#define kBufferDurationSeconds .5 |
|---|
| 39 |
|
|---|
| 40 |
class JackAudioQueueAdapter |
|---|
| 41 |
{ |
|---|
| 42 |
|
|---|
| 43 |
private: |
|---|
| 44 |
|
|---|
| 45 |
AudioQueueRef fCaptureQueue; |
|---|
| 46 |
AudioQueueBufferRef fCaptureQueueBuffers[kNumberBuffers]; |
|---|
| 47 |
|
|---|
| 48 |
AudioQueueRef fPlaybackQueue; |
|---|
| 49 |
AudioQueueBufferRef fPlaybackQueueBuffers[kNumberBuffers]; |
|---|
| 50 |
//AudioStreamPacketDescription fPlaybackPacketDescs; |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
jack_nframes_t fBufferSize; |
|---|
| 54 |
jack_nframes_t fSampleRate; |
|---|
| 55 |
|
|---|
| 56 |
int fCaptureChannels; |
|---|
| 57 |
int fPlaybackChannels; |
|---|
| 58 |
|
|---|
| 59 |
jack_adapter_t* fAdapter; |
|---|
| 60 |
|
|---|
| 61 |
static void CaptureCallback(void* inUserData, |
|---|
| 62 |
AudioQueueRef inAQ, |
|---|
| 63 |
AudioQueueBufferRef inBuffer, |
|---|
| 64 |
const AudioTimeStamp* inStartTime, |
|---|
| 65 |
UInt32 inNumPackets, |
|---|
| 66 |
const AudioStreamPacketDescription* inPacketDesc); |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
static void PlaybackCallback(void* inUserData, |
|---|
| 70 |
AudioQueueRef inAQ, |
|---|
| 71 |
AudioQueueBufferRef inCompleteAQBuffer); |
|---|
| 72 |
|
|---|
| 73 |
static void InterruptionListener(void* inClientData, UInt32 inInterruptionState); |
|---|
| 74 |
|
|---|
| 75 |
static void PropListener(void* inClientData, |
|---|
| 76 |
AudioSessionPropertyID inID, |
|---|
| 77 |
UInt32 inDataSize, |
|---|
| 78 |
const void* inData); |
|---|
| 79 |
|
|---|
| 80 |
public: |
|---|
| 81 |
|
|---|
| 82 |
JackAudioQueueAdapter(int inchan, int outchan, jack_nframes_t buffer_size, jack_nframes_t sample_rate, jack_adapter_t* adapter); |
|---|
| 83 |
~JackAudioQueueAdapter(); |
|---|
| 84 |
|
|---|
| 85 |
virtual int Open(); |
|---|
| 86 |
virtual int Close(); |
|---|
| 87 |
|
|---|
| 88 |
virtual int Start(); |
|---|
| 89 |
virtual int Stop(); |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
virtual int SetSampleRate(jack_nframes_t sample_rate); |
|---|
| 93 |
virtual int SetBufferSize(jack_nframes_t buffer_size); |
|---|
| 94 |
|
|---|
| 95 |
}; |
|---|
| 96 |
|
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
#endif |
|---|