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.

104 lines
3.0KB

  1. /*
  2. Copyright (C) 2010 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 __TiPhoneCoreAudioRenderer__
  16. #define __TiPhoneCoreAudioRenderer__
  17. #include <AudioToolbox/AudioConverter.h>
  18. #include <AudioToolbox/AudioServices.h>
  19. #include <AudioUnit/AudioUnit.h>
  20. #define MAX_CHANNELS 256
  21. #define OPEN_ERR -1
  22. #define NO_ERR 0
  23. typedef void (*AudioCallback) (int frames, float** inputs, float** outputs, void* arg);
  24. class TiPhoneCoreAudioRenderer
  25. {
  26. private:
  27. AudioUnit fAUHAL;
  28. AudioCallback fAudioCallback;
  29. void* fCallbackArg;
  30. int fDevNumInChans;
  31. int fDevNumOutChans;
  32. float* fInChannel[MAX_CHANNELS];
  33. float* fOutChannel[MAX_CHANNELS];
  34. static OSStatus Render(void *inRefCon,
  35. AudioUnitRenderActionFlags *ioActionFlags,
  36. const AudioTimeStamp *inTimeStamp,
  37. UInt32 inBusNumber,
  38. UInt32 inNumberFrames,
  39. AudioBufferList *ioData);
  40. static void InterruptionListener(void *inClientData, UInt32 inInterruption);
  41. public:
  42. TiPhoneCoreAudioRenderer(int input, int output)
  43. :fDevNumInChans(input), fDevNumOutChans(output), fAudioCallback(NULL), fCallbackArg(NULL)
  44. {
  45. for (int i = 0; i < fDevNumInChans; i++) {
  46. fInChannel[i] = new float[8192];
  47. }
  48. for (int i = 0; i < fDevNumOutChans; i++) {
  49. fOutChannel[i] = new float[8192];
  50. }
  51. }
  52. virtual ~TiPhoneCoreAudioRenderer()
  53. {
  54. for (int i = 0; i < fDevNumInChans; i++) {
  55. delete[] fInChannel[i];
  56. }
  57. for (int i = 0; i < fDevNumOutChans; i++) {
  58. delete[] fOutChannel[i];
  59. }
  60. }
  61. int OpenDefault(int bufferSize, int sampleRate);
  62. int Close();
  63. int Start();
  64. int Stop();
  65. void SetAudioCallback(AudioCallback callback, void* arg)
  66. {
  67. fAudioCallback = callback;
  68. fCallbackArg = arg;
  69. }
  70. void PerformAudioCallback(int frames)
  71. {
  72. if (fAudioCallback)
  73. fAudioCallback(frames, fInChannel, fOutChannel, fCallbackArg);
  74. }
  75. };
  76. typedef TiPhoneCoreAudioRenderer * TiPhoneCoreAudioRendererPtr;
  77. #endif