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.

107 lines
3.1KB

  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. memset(fInChannel, 0, sizeof(float*) * MAX_CHANNELS);
  46. memset(fOutChannel, 0, sizeof(float*) * MAX_CHANNELS);
  47. for (int i = 0; i < fDevNumInChans; i++) {
  48. fInChannel[i] = new float[8192];
  49. }
  50. for (int i = 0; i < fDevNumOutChans; i++) {
  51. fOutChannel[i] = new float[8192];
  52. }
  53. }
  54. virtual ~TiPhoneCoreAudioRenderer()
  55. {
  56. for (int i = 0; i < fDevNumInChans; i++) {
  57. delete[] fInChannel[i];
  58. }
  59. for (int i = 0; i < fDevNumOutChans; i++) {
  60. delete[] fOutChannel[i];
  61. }
  62. }
  63. int Open(int bufferSize, int sampleRate);
  64. int Close();
  65. int Start();
  66. int Stop();
  67. void SetAudioCallback(AudioCallback callback, void* arg)
  68. {
  69. fAudioCallback = callback;
  70. fCallbackArg = arg;
  71. }
  72. void PerformAudioCallback(int frames)
  73. {
  74. if (fAudioCallback)
  75. fAudioCallback(frames, fInChannel, fOutChannel, fCallbackArg);
  76. }
  77. };
  78. typedef TiPhoneCoreAudioRenderer * TiPhoneCoreAudioRendererPtr;
  79. #endif