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.

122 lines
3.5KB

  1. /*
  2. opensl_io.c:
  3. Android OpenSL input/output module header
  4. Copyright (c) 2012, Victor Lazzarini
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. * Neither the name of the <organization> nor the
  14. names of its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  20. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef OPENSL_IO
  28. #define OPENSL_IO
  29. #include <SLES/OpenSLES.h>
  30. #include <SLES/OpenSLES_Android.h>
  31. #include <pthread.h>
  32. #include <stdlib.h>
  33. typedef struct threadLock_{
  34. pthread_mutex_t m;
  35. pthread_cond_t c;
  36. unsigned char s;
  37. } threadLock;
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. typedef struct opensl_stream {
  42. // engine interfaces
  43. SLObjectItf engineObject;
  44. SLEngineItf engineEngine;
  45. // output mix interfaces
  46. SLObjectItf outputMixObject;
  47. // buffer queue player interfaces
  48. SLObjectItf bqPlayerObject;
  49. SLPlayItf bqPlayerPlay;
  50. SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
  51. SLEffectSendItf bqPlayerEffectSend;
  52. // recorder interfaces
  53. SLObjectItf recorderObject;
  54. SLRecordItf recorderRecord;
  55. SLAndroidSimpleBufferQueueItf recorderBufferQueue;
  56. // buffer indexes
  57. int currentInputIndex;
  58. int currentOutputIndex;
  59. // current buffer half (0, 1)
  60. int currentOutputBuffer;
  61. int currentInputBuffer;
  62. // buffers
  63. short *outputBuffer[2];
  64. short *inputBuffer[2];
  65. // size of buffers
  66. int outBufSamples;
  67. int inBufSamples;
  68. // locks
  69. void* inlock;
  70. void* outlock;
  71. double time;
  72. int inchannels;
  73. int outchannels;
  74. int sr;
  75. } OPENSL_STREAM;
  76. /*
  77. Open the audio device with a given sampling rate (sr), input and output channels and IO buffer size
  78. in frames. Returns a handle to the OpenSL stream
  79. */
  80. OPENSL_STREAM* android_OpenAudioDevice(int sr, int inchannels, int outchannels, int bufferframes);
  81. /*
  82. Close the audio device
  83. */
  84. void android_CloseAudioDevice(OPENSL_STREAM *p);
  85. /*
  86. Read a buffer from the OpenSL stream *p, of size samples. Returns the number of samples read.
  87. */
  88. int android_AudioIn(OPENSL_STREAM *p, float *buffer,int size);
  89. /*
  90. Write a buffer to the OpenSL stream *p, of size samples. Returns the number of samples written.
  91. */
  92. int android_AudioOut(OPENSL_STREAM *p, float *buffer,int size);
  93. /*
  94. Get the current IO block time in seconds
  95. */
  96. double android_GetTimestamp(OPENSL_STREAM *p);
  97. #ifdef __cplusplus
  98. };
  99. #endif
  100. #endif // #ifndef OPENSL_IO