The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

624 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. const char* const openSLTypeName = "Android OpenSL";
  19. bool isOpenSLAvailable()
  20. {
  21. DynamicLibrary library;
  22. return library.open ("libOpenSLES.so");
  23. }
  24. const unsigned short openSLRates[] = { 8000, 16000, 32000, 44100, 48000 };
  25. const unsigned short openSLBufferSizes[] = { 256, 512, 768, 1024, 1280, 1600 }; // must all be multiples of the block size
  26. //==============================================================================
  27. class OpenSLAudioIODevice : public AudioIODevice,
  28. public Thread
  29. {
  30. public:
  31. OpenSLAudioIODevice (const String& deviceName)
  32. : AudioIODevice (deviceName, openSLTypeName),
  33. Thread ("OpenSL"),
  34. callback (nullptr), sampleRate (0), deviceOpen (false),
  35. inputBuffer (2, 2), outputBuffer (2, 2)
  36. {
  37. // OpenSL has piss-poor support for determining latency, so the only way I can find to
  38. // get a number for this is by asking the AudioTrack/AudioRecord classes..
  39. AndroidAudioIODevice javaDevice (String::empty);
  40. // this is a total guess about how to calculate the latency, but seems to vaguely agree
  41. // with the devices I've tested.. YMMV
  42. inputLatency = ((javaDevice.minBufferSizeIn * 2) / 3);
  43. outputLatency = ((javaDevice.minBufferSizeOut * 2) / 3);
  44. const int longestLatency = jmax (inputLatency, outputLatency);
  45. const int totalLatency = inputLatency + outputLatency;
  46. inputLatency = ((longestLatency * inputLatency) / totalLatency) & ~15;
  47. outputLatency = ((longestLatency * outputLatency) / totalLatency) & ~15;
  48. }
  49. ~OpenSLAudioIODevice()
  50. {
  51. close();
  52. }
  53. bool openedOk() const { return engine.outputMixObject != nullptr; }
  54. StringArray getOutputChannelNames()
  55. {
  56. StringArray s;
  57. s.add ("Left");
  58. s.add ("Right");
  59. return s;
  60. }
  61. StringArray getInputChannelNames()
  62. {
  63. StringArray s;
  64. s.add ("Audio Input");
  65. return s;
  66. }
  67. int getNumSampleRates() { return numElementsInArray (openSLRates); }
  68. double getSampleRate (int index)
  69. {
  70. jassert (index >= 0 && index < getNumSampleRates());
  71. return (int) openSLRates [index];
  72. }
  73. int getDefaultBufferSize() { return 1024; }
  74. int getNumBufferSizesAvailable() { return numElementsInArray (openSLBufferSizes); }
  75. int getBufferSizeSamples (int index)
  76. {
  77. jassert (index >= 0 && index < getNumBufferSizesAvailable());
  78. return (int) openSLBufferSizes [index];
  79. }
  80. String open (const BigInteger& inputChannels,
  81. const BigInteger& outputChannels,
  82. double requestedSampleRate,
  83. int bufferSize)
  84. {
  85. close();
  86. lastError = String::empty;
  87. sampleRate = (int) requestedSampleRate;
  88. int preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  89. activeOutputChans = outputChannels;
  90. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  91. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  92. activeInputChans = inputChannels;
  93. activeInputChans.setRange (1, activeInputChans.getHighestBit(), false);
  94. numInputChannels = activeInputChans.countNumberOfSetBits();
  95. actualBufferSize = preferredBufferSize;
  96. inputBuffer.setSize (jmax (1, numInputChannels), actualBufferSize);
  97. outputBuffer.setSize (jmax (1, numOutputChannels), actualBufferSize);
  98. outputBuffer.clear();
  99. recorder = engine.createRecorder (numInputChannels, sampleRate);
  100. player = engine.createPlayer (numOutputChannels, sampleRate);
  101. startThread (8);
  102. deviceOpen = true;
  103. return lastError;
  104. }
  105. void close()
  106. {
  107. stop();
  108. stopThread (6000);
  109. deviceOpen = false;
  110. recorder = nullptr;
  111. player = nullptr;
  112. }
  113. int getOutputLatencyInSamples() { return outputLatency; }
  114. int getInputLatencyInSamples() { return inputLatency; }
  115. bool isOpen() { return deviceOpen; }
  116. int getCurrentBufferSizeSamples() { return actualBufferSize; }
  117. int getCurrentBitDepth() { return 16; }
  118. double getCurrentSampleRate() { return sampleRate; }
  119. BigInteger getActiveOutputChannels() const { return activeOutputChans; }
  120. BigInteger getActiveInputChannels() const { return activeInputChans; }
  121. String getLastError() { return lastError; }
  122. bool isPlaying() { return callback != nullptr; }
  123. void start (AudioIODeviceCallback* newCallback)
  124. {
  125. stop();
  126. if (deviceOpen && callback != newCallback)
  127. {
  128. if (newCallback != nullptr)
  129. newCallback->audioDeviceAboutToStart (this);
  130. setCallback (newCallback);
  131. }
  132. }
  133. void stop()
  134. {
  135. if (AudioIODeviceCallback* const oldCallback = setCallback (nullptr))
  136. oldCallback->audioDeviceStopped();
  137. }
  138. void run()
  139. {
  140. if (recorder != nullptr) recorder->start();
  141. if (player != nullptr) player->start();
  142. while (! threadShouldExit())
  143. {
  144. if (player != nullptr) player->writeBuffer (outputBuffer, *this);
  145. if (recorder != nullptr) recorder->readNextBlock (inputBuffer, *this);
  146. const ScopedLock sl (callbackLock);
  147. if (callback != nullptr)
  148. {
  149. callback->audioDeviceIOCallback (numInputChannels > 0 ? (const float**) inputBuffer.getArrayOfChannels() : nullptr,
  150. numInputChannels,
  151. numOutputChannels > 0 ? outputBuffer.getArrayOfChannels() : nullptr,
  152. numOutputChannels,
  153. actualBufferSize);
  154. }
  155. else
  156. {
  157. outputBuffer.clear();
  158. }
  159. }
  160. }
  161. private:
  162. //==================================================================================================
  163. CriticalSection callbackLock;
  164. AudioIODeviceCallback* callback;
  165. int actualBufferSize, sampleRate;
  166. int inputLatency, outputLatency;
  167. bool deviceOpen;
  168. String lastError;
  169. BigInteger activeOutputChans, activeInputChans;
  170. int numInputChannels, numOutputChannels;
  171. AudioSampleBuffer inputBuffer, outputBuffer;
  172. struct Player;
  173. struct Recorder;
  174. AudioIODeviceCallback* setCallback (AudioIODeviceCallback* const newCallback)
  175. {
  176. const ScopedLock sl (callbackLock);
  177. AudioIODeviceCallback* const oldCallback = callback;
  178. callback = newCallback;
  179. return oldCallback;
  180. }
  181. //==================================================================================================
  182. struct Engine
  183. {
  184. Engine()
  185. : engineObject (nullptr), engineInterface (nullptr), outputMixObject (nullptr)
  186. {
  187. if (library.open ("libOpenSLES.so"))
  188. {
  189. typedef SLresult (*CreateEngineFunc) (SLObjectItf*, SLuint32, const SLEngineOption*, SLuint32, const SLInterfaceID*, const SLboolean*);
  190. if (CreateEngineFunc createEngine = (CreateEngineFunc) library.getFunction ("slCreateEngine"))
  191. {
  192. check (createEngine (&engineObject, 0, nullptr, 0, nullptr, nullptr));
  193. SLInterfaceID* SL_IID_ENGINE = (SLInterfaceID*) library.getFunction ("SL_IID_ENGINE");
  194. SL_IID_ANDROIDSIMPLEBUFFERQUEUE = (SLInterfaceID*) library.getFunction ("SL_IID_ANDROIDSIMPLEBUFFERQUEUE");
  195. SL_IID_PLAY = (SLInterfaceID*) library.getFunction ("SL_IID_PLAY");
  196. SL_IID_RECORD = (SLInterfaceID*) library.getFunction ("SL_IID_RECORD");
  197. check ((*engineObject)->Realize (engineObject, SL_BOOLEAN_FALSE));
  198. check ((*engineObject)->GetInterface (engineObject, *SL_IID_ENGINE, &engineInterface));
  199. check ((*engineInterface)->CreateOutputMix (engineInterface, &outputMixObject, 0, nullptr, nullptr));
  200. check ((*outputMixObject)->Realize (outputMixObject, SL_BOOLEAN_FALSE));
  201. }
  202. }
  203. }
  204. ~Engine()
  205. {
  206. if (outputMixObject != nullptr) (*outputMixObject)->Destroy (outputMixObject);
  207. if (engineObject != nullptr) (*engineObject)->Destroy (engineObject);
  208. }
  209. Player* createPlayer (const int numChannels, const int sampleRate)
  210. {
  211. if (numChannels <= 0)
  212. return nullptr;
  213. ScopedPointer<Player> player (new Player (numChannels, sampleRate, *this));
  214. return player->openedOk() ? player.release() : nullptr;
  215. }
  216. Recorder* createRecorder (const int numChannels, const int sampleRate)
  217. {
  218. if (numChannels <= 0)
  219. return nullptr;
  220. ScopedPointer<Recorder> recorder (new Recorder (numChannels, sampleRate, *this));
  221. return recorder->openedOk() ? recorder.release() : nullptr;
  222. }
  223. SLObjectItf engineObject;
  224. SLEngineItf engineInterface;
  225. SLObjectItf outputMixObject;
  226. SLInterfaceID* SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
  227. SLInterfaceID* SL_IID_PLAY;
  228. SLInterfaceID* SL_IID_RECORD;
  229. private:
  230. DynamicLibrary library;
  231. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Engine)
  232. };
  233. //==================================================================================================
  234. struct BufferList
  235. {
  236. BufferList (const int numChannels_)
  237. : numChannels (numChannels_), bufferSpace (numChannels_ * numSamples * numBuffers), nextBlock (0)
  238. {
  239. }
  240. int16* waitForFreeBuffer (Thread& threadToCheck)
  241. {
  242. while (numBlocksOut.get() == numBuffers)
  243. {
  244. dataArrived.wait (1);
  245. if (threadToCheck.threadShouldExit())
  246. return nullptr;
  247. }
  248. return getNextBuffer();
  249. }
  250. int16* getNextBuffer()
  251. {
  252. if (++nextBlock == numBuffers)
  253. nextBlock = 0;
  254. return bufferSpace + nextBlock * numChannels * numSamples;
  255. }
  256. void bufferReturned() { --numBlocksOut; dataArrived.signal(); }
  257. void bufferSent() { ++numBlocksOut; dataArrived.signal(); }
  258. int getBufferSizeBytes() const { return numChannels * numSamples * sizeof (int16); }
  259. const int numChannels;
  260. enum { numSamples = 256, numBuffers = 16 };
  261. private:
  262. HeapBlock<int16> bufferSpace;
  263. int nextBlock;
  264. Atomic<int> numBlocksOut;
  265. WaitableEvent dataArrived;
  266. };
  267. //==================================================================================================
  268. struct Player
  269. {
  270. Player (int numChannels, int sampleRate, Engine& engine)
  271. : playerObject (nullptr), playerPlay (nullptr), playerBufferQueue (nullptr),
  272. bufferList (numChannels)
  273. {
  274. jassert (numChannels == 2);
  275. SLDataFormat_PCM pcmFormat =
  276. {
  277. SL_DATAFORMAT_PCM,
  278. numChannels,
  279. sampleRate * 1000, // (sample rate units are millihertz)
  280. SL_PCMSAMPLEFORMAT_FIXED_16,
  281. SL_PCMSAMPLEFORMAT_FIXED_16,
  282. SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT,
  283. SL_BYTEORDER_LITTLEENDIAN
  284. };
  285. SLDataLocator_AndroidSimpleBufferQueue bufferQueue = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, bufferList.numBuffers };
  286. SLDataSource audioSrc = { &bufferQueue, &pcmFormat };
  287. SLDataLocator_OutputMix outputMix = { SL_DATALOCATOR_OUTPUTMIX, engine.outputMixObject };
  288. SLDataSink audioSink = { &outputMix, nullptr };
  289. // (SL_IID_BUFFERQUEUE is not guaranteed to remain future-proof, so use SL_IID_ANDROIDSIMPLEBUFFERQUEUE)
  290. const SLInterfaceID interfaceIDs[] = { *engine.SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
  291. const SLboolean flags[] = { SL_BOOLEAN_TRUE };
  292. check ((*engine.engineInterface)->CreateAudioPlayer (engine.engineInterface, &playerObject, &audioSrc, &audioSink,
  293. 1, interfaceIDs, flags));
  294. check ((*playerObject)->Realize (playerObject, SL_BOOLEAN_FALSE));
  295. check ((*playerObject)->GetInterface (playerObject, *engine.SL_IID_PLAY, &playerPlay));
  296. check ((*playerObject)->GetInterface (playerObject, *engine.SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &playerBufferQueue));
  297. check ((*playerBufferQueue)->RegisterCallback (playerBufferQueue, staticCallback, this));
  298. }
  299. ~Player()
  300. {
  301. if (playerPlay != nullptr)
  302. check ((*playerPlay)->SetPlayState (playerPlay, SL_PLAYSTATE_STOPPED));
  303. if (playerBufferQueue != nullptr)
  304. check ((*playerBufferQueue)->Clear (playerBufferQueue));
  305. if (playerObject != nullptr)
  306. (*playerObject)->Destroy (playerObject);
  307. }
  308. bool openedOk() const noexcept { return playerBufferQueue != nullptr; }
  309. void start()
  310. {
  311. jassert (openedOk());
  312. check ((*playerPlay)->SetPlayState (playerPlay, SL_PLAYSTATE_PLAYING));
  313. }
  314. void writeBuffer (const AudioSampleBuffer& buffer, Thread& thread)
  315. {
  316. jassert (buffer.getNumChannels() == bufferList.numChannels);
  317. jassert (buffer.getNumSamples() < bufferList.numSamples * bufferList.numBuffers);
  318. int offset = 0;
  319. int numSamples = buffer.getNumSamples();
  320. while (numSamples > 0)
  321. {
  322. int16* const destBuffer = bufferList.waitForFreeBuffer (thread);
  323. if (destBuffer == nullptr)
  324. break;
  325. for (int i = 0; i < bufferList.numChannels; ++i)
  326. {
  327. typedef AudioData::Pointer <AudioData::Int16, AudioData::LittleEndian, AudioData::Interleaved, AudioData::NonConst> DstSampleType;
  328. typedef AudioData::Pointer <AudioData::Float32, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::Const> SrcSampleType;
  329. DstSampleType dstData (destBuffer + i, bufferList.numChannels);
  330. SrcSampleType srcData (buffer.getSampleData (i, offset));
  331. dstData.convertSamples (srcData, bufferList.numSamples);
  332. }
  333. check ((*playerBufferQueue)->Enqueue (playerBufferQueue, destBuffer, bufferList.getBufferSizeBytes()));
  334. bufferList.bufferSent();
  335. numSamples -= bufferList.numSamples;
  336. offset += bufferList.numSamples;
  337. }
  338. }
  339. private:
  340. SLObjectItf playerObject;
  341. SLPlayItf playerPlay;
  342. SLAndroidSimpleBufferQueueItf playerBufferQueue;
  343. BufferList bufferList;
  344. static void staticCallback (SLAndroidSimpleBufferQueueItf queue, void* context)
  345. {
  346. jassert (queue == static_cast <Player*> (context)->playerBufferQueue); (void) queue;
  347. static_cast <Player*> (context)->bufferList.bufferReturned();
  348. }
  349. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Player)
  350. };
  351. //==================================================================================================
  352. struct Recorder
  353. {
  354. Recorder (int numChannels, int sampleRate, Engine& engine)
  355. : recorderObject (nullptr), recorderRecord (nullptr), recorderBufferQueue (nullptr),
  356. bufferList (numChannels)
  357. {
  358. jassert (numChannels == 1); // STEREO doesn't always work!!
  359. SLDataFormat_PCM pcmFormat =
  360. {
  361. SL_DATAFORMAT_PCM,
  362. numChannels,
  363. sampleRate * 1000, // (sample rate units are millihertz)
  364. SL_PCMSAMPLEFORMAT_FIXED_16,
  365. SL_PCMSAMPLEFORMAT_FIXED_16,
  366. (numChannels == 1) ? SL_SPEAKER_FRONT_CENTER : (SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT),
  367. SL_BYTEORDER_LITTLEENDIAN
  368. };
  369. SLDataLocator_IODevice ioDevice = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT, SL_DEFAULTDEVICEID_AUDIOINPUT, nullptr };
  370. SLDataSource audioSrc = { &ioDevice, nullptr };
  371. SLDataLocator_AndroidSimpleBufferQueue bufferQueue = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, bufferList.numBuffers };
  372. SLDataSink audioSink = { &bufferQueue, &pcmFormat };
  373. const SLInterfaceID interfaceIDs[] = { *engine.SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
  374. const SLboolean flags[] = { SL_BOOLEAN_TRUE };
  375. if (check ((*engine.engineInterface)->CreateAudioRecorder (engine.engineInterface, &recorderObject, &audioSrc,
  376. &audioSink, 1, interfaceIDs, flags)))
  377. {
  378. if (check ((*recorderObject)->Realize (recorderObject, SL_BOOLEAN_FALSE)))
  379. {
  380. check ((*recorderObject)->GetInterface (recorderObject, *engine.SL_IID_RECORD, &recorderRecord));
  381. check ((*recorderObject)->GetInterface (recorderObject, *engine.SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &recorderBufferQueue));
  382. check ((*recorderBufferQueue)->RegisterCallback (recorderBufferQueue, staticCallback, this));
  383. check ((*recorderRecord)->SetRecordState (recorderRecord, SL_RECORDSTATE_STOPPED));
  384. for (int i = bufferList.numBuffers; --i >= 0;)
  385. {
  386. int16* const buffer = bufferList.getNextBuffer();
  387. jassert (buffer != nullptr);
  388. enqueueBuffer (buffer);
  389. }
  390. }
  391. }
  392. }
  393. ~Recorder()
  394. {
  395. if (recorderRecord != nullptr)
  396. check ((*recorderRecord)->SetRecordState (recorderRecord, SL_RECORDSTATE_STOPPED));
  397. if (recorderBufferQueue != nullptr)
  398. check ((*recorderBufferQueue)->Clear (recorderBufferQueue));
  399. if (recorderObject != nullptr)
  400. (*recorderObject)->Destroy (recorderObject);
  401. }
  402. bool openedOk() const noexcept { return recorderBufferQueue != nullptr; }
  403. void start()
  404. {
  405. jassert (openedOk());
  406. check ((*recorderRecord)->SetRecordState (recorderRecord, SL_RECORDSTATE_RECORDING));
  407. }
  408. void readNextBlock (AudioSampleBuffer& buffer, Thread& thread)
  409. {
  410. jassert (buffer.getNumChannels() == bufferList.numChannels);
  411. jassert (buffer.getNumSamples() < bufferList.numSamples * bufferList.numBuffers);
  412. jassert ((buffer.getNumSamples() % bufferList.numSamples) == 0);
  413. int offset = 0;
  414. int numSamples = buffer.getNumSamples();
  415. while (numSamples > 0)
  416. {
  417. int16* const srcBuffer = bufferList.waitForFreeBuffer (thread);
  418. if (srcBuffer == nullptr)
  419. break;
  420. for (int i = 0; i < bufferList.numChannels; ++i)
  421. {
  422. typedef AudioData::Pointer <AudioData::Float32, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::NonConst> DstSampleType;
  423. typedef AudioData::Pointer <AudioData::Int16, AudioData::LittleEndian, AudioData::Interleaved, AudioData::Const> SrcSampleType;
  424. DstSampleType dstData (buffer.getSampleData (i, offset));
  425. SrcSampleType srcData (srcBuffer + i, bufferList.numChannels);
  426. dstData.convertSamples (srcData, bufferList.numSamples);
  427. }
  428. enqueueBuffer (srcBuffer);
  429. numSamples -= bufferList.numSamples;
  430. offset += bufferList.numSamples;
  431. }
  432. }
  433. private:
  434. SLObjectItf recorderObject;
  435. SLRecordItf recorderRecord;
  436. SLAndroidSimpleBufferQueueItf recorderBufferQueue;
  437. BufferList bufferList;
  438. void enqueueBuffer (int16* buffer)
  439. {
  440. check ((*recorderBufferQueue)->Enqueue (recorderBufferQueue, buffer, bufferList.getBufferSizeBytes()));
  441. bufferList.bufferSent();
  442. }
  443. static void staticCallback (SLAndroidSimpleBufferQueueItf queue, void* context)
  444. {
  445. jassert (queue == static_cast <Recorder*> (context)->recorderBufferQueue); (void) queue;
  446. static_cast <Recorder*> (context)->bufferList.bufferReturned();
  447. }
  448. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Recorder)
  449. };
  450. //==============================================================================
  451. Engine engine;
  452. ScopedPointer<Player> player;
  453. ScopedPointer<Recorder> recorder;
  454. //==============================================================================
  455. static bool check (const SLresult result)
  456. {
  457. jassert (result == SL_RESULT_SUCCESS);
  458. return result == SL_RESULT_SUCCESS;
  459. }
  460. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenSLAudioIODevice)
  461. };
  462. //==============================================================================
  463. class OpenSLAudioDeviceType : public AudioIODeviceType
  464. {
  465. public:
  466. OpenSLAudioDeviceType() : AudioIODeviceType (openSLTypeName) {}
  467. //==============================================================================
  468. void scanForDevices() {}
  469. StringArray getDeviceNames (bool wantInputNames) const { return StringArray (openSLTypeName); }
  470. int getDefaultDeviceIndex (bool forInput) const { return 0; }
  471. int getIndexOfDevice (AudioIODevice* device, bool asInput) const { return device != nullptr ? 0 : -1; }
  472. bool hasSeparateInputsAndOutputs() const { return false; }
  473. AudioIODevice* createDevice (const String& outputDeviceName,
  474. const String& inputDeviceName)
  475. {
  476. ScopedPointer<OpenSLAudioIODevice> dev;
  477. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  478. {
  479. dev = new OpenSLAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  480. : inputDeviceName);
  481. if (! dev->openedOk())
  482. dev = nullptr;
  483. }
  484. return dev.release();
  485. }
  486. private:
  487. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OpenSLAudioDeviceType)
  488. };
  489. //==============================================================================
  490. AudioIODeviceType* AudioIODeviceType::createAudioIODeviceType_OpenSLES()
  491. {
  492. return isOpenSLAvailable() ? new OpenSLAudioDeviceType() : nullptr;
  493. }