jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.7KB

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