/libs/ObjectAL/OpenAL/ALWrapper.m

http://github.com/kstenerud/ObjectAL-for-iPhone · Objective C · 1397 lines · 1167 code · 169 blank · 61 comment · 37 complexity · 05f1ece03adfe2f6f2e70e2022ca598a MD5 · raw file

  1. //
  2. // OpenAL.m
  3. // ObjectAL
  4. //
  5. // Created by Karl Stenerud on 15/12/09.
  6. //
  7. // Copyright 2009 Karl Stenerud
  8. //
  9. // Licensed under the Apache License, Version 2.0 (the "License");
  10. // you may not use this file except in compliance with the License.
  11. // You may obtain a copy of the License at
  12. //
  13. // http://www.apache.org/licenses/LICENSE-2.0
  14. //
  15. // Unless required by applicable law or agreed to in writing, software
  16. // distributed under the License is distributed on an "AS IS" BASIS,
  17. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. // See the License for the specific language governing permissions and
  19. // limitations under the License.
  20. //
  21. // Note: You are NOT required to make the license available from within your
  22. // iOS application. Including it in your project is sufficient.
  23. //
  24. // Attribution is not required, but appreciated :)
  25. //
  26. #import "ALWrapper.h"
  27. #import "ObjectALMacros.h"
  28. #import "OALNotifications.h"
  29. /** Check the result of an AL call, logging an error if necessary.
  30. *
  31. * @return TRUE if the call was successful.
  32. */
  33. #define CHECK_AL_CALL() checkIfSuccessful(__PRETTY_FUNCTION__)
  34. /** Check the result of an ALC call, logging an error if necessary.
  35. *
  36. * @param DEVICE The device involved in the ALC call.
  37. * @return TRUE if the call was successful.
  38. */
  39. #define CHECK_ALC_CALL(DEVICE) checkIfSuccessfulWithDevice(__PRETTY_FUNCTION__, (DEVICE))
  40. /**
  41. * Private interface to ALWrapper.
  42. */
  43. @interface ALWrapper (Private)
  44. /** Decode an OpenAL supplied NULL-separated string list into an NSArray.
  45. *
  46. * @param source the string list as supplied by OpenAL.
  47. * @return the string list in an NSArray of NSString.
  48. */
  49. + (NSArray*) decodeNullSeparatedStringList:(const ALCchar*) source;
  50. /** Decode an OpenAL supplied space-separated string list into an NSArray.
  51. *
  52. * @param source the string list as supplied by OpenAL.
  53. * @return the string list in an NSArray of NSString.
  54. */
  55. + (NSArray*) decodeSpaceSeparatedStringList:(const ALCchar*) source;
  56. /** Check the OpenAL error status and log an error message if necessary.
  57. *
  58. * @param contextInfo Contextual information to add when logging an error.
  59. * @return TRUE if the operation was successful (no error).
  60. */
  61. BOOL checkIfSuccessful(const char* contextInfo);
  62. /** Check the OpenAL error status and log an error message if necessary.
  63. *
  64. * @param contextInfo Contextual information to add when logging an error.
  65. * @param device The device to check for errors on.
  66. * @return TRUE if the operation was successful (no error).
  67. */
  68. BOOL checkIfSuccessfulWithDevice(const char* contextInfo, ALCdevice* device);
  69. @end
  70. #pragma mark -
  71. @implementation ALWrapper
  72. typedef ALdouble AL_APIENTRY (*alcMacOSXGetMixerOutputRateProcPtr)();
  73. typedef ALvoid AL_APIENTRY (*alcMacOSXMixerOutputRateProcPtr) (const ALdouble value);
  74. typedef ALvoid AL_APIENTRY (*alBufferDataStaticProcPtr) (const ALint bid,
  75. ALenum format,
  76. const ALvoid* data,
  77. ALsizei size,
  78. ALsizei freq);
  79. static alcMacOSXGetMixerOutputRateProcPtr alcGetMacOSXMixerOutputRate = NULL;
  80. static alcMacOSXMixerOutputRateProcPtr alcMacOSXMixerOutputRate = NULL;
  81. static alBufferDataStaticProcPtr alBufferDataStatic = NULL;
  82. #pragma mark -
  83. #pragma mark Error Handling
  84. BOOL checkIfSuccessful(const char* contextInfo)
  85. {
  86. ALenum error = alGetError();
  87. if(AL_NO_ERROR != error)
  88. {
  89. OAL_LOG_ERROR_CONTEXT(contextInfo, @"%s (error code 0x%08x)", alGetString(error), error);
  90. [[NSNotificationCenter defaultCenter] postNotificationName:OALAudioErrorNotification object:[ALWrapper class]];
  91. return NO;
  92. }
  93. return YES;
  94. }
  95. BOOL checkIfSuccessfulWithDevice(const char* contextInfo, ALCdevice* device)
  96. {
  97. ALenum error = alcGetError(device);
  98. if(ALC_NO_ERROR != error)
  99. {
  100. OAL_LOG_ERROR_CONTEXT(contextInfo, @"%s (error code 0x%08x)", alcGetString(device, error), error);
  101. [[NSNotificationCenter defaultCenter] postNotificationName:OALAudioErrorNotification object:[ALWrapper class]];
  102. return NO;
  103. }
  104. return YES;
  105. }
  106. #pragma mark Internal Utility
  107. + (NSArray*) decodeNullSeparatedStringList:(const ALCchar*) source
  108. {
  109. NSMutableArray* array = [NSMutableArray arrayWithCapacity:10];
  110. NSString* lastString = nil;
  111. for(const ALCchar* nextString = source; 0 != *nextString; nextString += [lastString length] + 1)
  112. {
  113. lastString = [NSString stringWithFormat:@"%s", nextString];
  114. }
  115. return array;
  116. }
  117. + (NSArray*) decodeSpaceSeparatedStringList:(const ALCchar*) source
  118. {
  119. NSMutableArray* array = [NSMutableArray arrayWithCapacity:10];
  120. ALCchar buffer[200];
  121. ALCchar* bufferPtr = buffer;
  122. const ALCchar* sourcePtr = source;
  123. for(;;)
  124. {
  125. *bufferPtr = *sourcePtr;
  126. if(' ' == *bufferPtr || bufferPtr >= buffer + 199)
  127. {
  128. *bufferPtr = 0;
  129. }
  130. if(0 == *bufferPtr)
  131. {
  132. [array addObject:[NSString stringWithFormat:@"%s", buffer]];
  133. bufferPtr = buffer;
  134. }
  135. else
  136. {
  137. bufferPtr++;
  138. }
  139. if(0 == *sourcePtr)
  140. {
  141. break;
  142. }
  143. sourcePtr++;
  144. }
  145. return array;
  146. }
  147. #pragma mark -
  148. #pragma mark OpenAL Management
  149. + (bool) enable:(ALenum) capability
  150. {
  151. bool result;
  152. @synchronized(self)
  153. {
  154. alEnable(capability);
  155. result = CHECK_AL_CALL();
  156. }
  157. return result;
  158. }
  159. + (bool) disable:(ALenum) capability
  160. {
  161. bool result;
  162. @synchronized(self)
  163. {
  164. alDisable(capability);
  165. result = CHECK_AL_CALL();
  166. }
  167. return result;
  168. }
  169. + (bool) isEnabled:(ALenum) capability
  170. {
  171. ALboolean result;
  172. @synchronized(self)
  173. {
  174. result = alIsEnabled(capability);
  175. CHECK_AL_CALL();
  176. }
  177. return result;
  178. }
  179. #pragma mark OpenAL Extensions
  180. + (bool) isExtensionPresent:(NSString*) extensionName
  181. {
  182. ALboolean result;
  183. @synchronized(self)
  184. {
  185. result = alIsExtensionPresent([extensionName UTF8String]);
  186. CHECK_AL_CALL();
  187. }
  188. return result;
  189. }
  190. + (void*) getProcAddress:(NSString*) functionName
  191. {
  192. void* result;
  193. @synchronized(self)
  194. {
  195. result = alGetProcAddress([functionName UTF8String]);
  196. CHECK_AL_CALL();
  197. }
  198. return result;
  199. }
  200. + (ALenum) getEnumValue:(NSString*) enumName
  201. {
  202. ALenum result;
  203. @synchronized(self)
  204. {
  205. result = alGetEnumValue([enumName UTF8String]);
  206. CHECK_AL_CALL();
  207. }
  208. return result;
  209. }
  210. #pragma mark -
  211. #pragma mark Device Management
  212. + (ALCdevice*) openDevice:(NSString*) deviceName
  213. {
  214. ALCdevice* device;
  215. @synchronized(self)
  216. {
  217. device = alcOpenDevice([deviceName UTF8String]);
  218. if(NULL == device)
  219. {
  220. OAL_LOG_ERROR(@"Could not open device %@", deviceName);
  221. }
  222. }
  223. return device;
  224. }
  225. + (bool) closeDevice:(ALCdevice*) device
  226. {
  227. bool result;
  228. @synchronized(self)
  229. {
  230. alcCloseDevice(device);
  231. result = CHECK_ALC_CALL(device);
  232. }
  233. return result;
  234. }
  235. #pragma mark Device Extensions
  236. + (bool) isExtensionPresent:(ALCdevice*) device name:(NSString*) extensionName
  237. {
  238. bool result;
  239. @synchronized(self)
  240. {
  241. result = alcIsExtensionPresent(device, [extensionName UTF8String]);
  242. CHECK_ALC_CALL(device);
  243. }
  244. return result;
  245. }
  246. + (void*) getProcAddress:(ALCdevice*) device name:(NSString*) functionName
  247. {
  248. void* result;
  249. @synchronized(self)
  250. {
  251. result = alcGetProcAddress(device, [functionName UTF8String]);
  252. CHECK_ALC_CALL(device);
  253. }
  254. return result;
  255. }
  256. + (ALenum) getEnumValue:(ALCdevice*) device name:(NSString*) enumName
  257. {
  258. ALenum result;
  259. @synchronized(self)
  260. {
  261. result = alcGetEnumValue(device, [enumName UTF8String]);
  262. CHECK_ALC_CALL(device);
  263. }
  264. return result;
  265. }
  266. #pragma mark Device Properties
  267. + (NSString*) getString:(ALCdevice*) device attribute:(ALenum) attribute
  268. {
  269. const ALCchar* result;
  270. @synchronized(self)
  271. {
  272. result = alcGetString(device, attribute);
  273. CHECK_ALC_CALL(device);
  274. }
  275. return [NSString stringWithFormat:@"%s", result];
  276. }
  277. + (NSArray*) getNullSeparatedStringList:(ALCdevice*) device attribute:(ALenum) attribute
  278. {
  279. const ALCchar* result;
  280. @synchronized(self)
  281. {
  282. result = alcGetString(device, attribute);
  283. CHECK_ALC_CALL(device);
  284. }
  285. return [self decodeNullSeparatedStringList:result];
  286. }
  287. + (NSArray*) getSpaceSeparatedStringList:(ALCdevice*) device attribute:(ALenum) attribute
  288. {
  289. const ALCchar* result;
  290. @synchronized(self)
  291. {
  292. result = alcGetString(device, attribute);
  293. CHECK_ALC_CALL(device);
  294. }
  295. return [self decodeSpaceSeparatedStringList:result];
  296. }
  297. + (ALint) getInteger:(ALCdevice*) device attribute:(ALenum) attribute
  298. {
  299. ALint result = 0;
  300. [self getIntegerv:device attribute:attribute size:1 data:&result];
  301. return result;
  302. }
  303. + (bool) getIntegerv:(ALCdevice*) device attribute:(ALenum) attribute size:(ALsizei) size data:(ALCint*) data
  304. {
  305. bool result;
  306. @synchronized(self)
  307. {
  308. alcGetIntegerv(device, attribute, size, data);
  309. result = CHECK_ALC_CALL(device);
  310. }
  311. return result;
  312. }
  313. #pragma mark Capture
  314. + (ALCdevice*) openCaptureDevice:(NSString*) deviceName frequency:(ALCuint) frequency format:(ALCenum) format bufferSize:(ALCsizei) bufferSize
  315. {
  316. ALCdevice* result;
  317. @synchronized(self)
  318. {
  319. result = alcCaptureOpenDevice([deviceName UTF8String], frequency, format, bufferSize);
  320. if(nil == result)
  321. {
  322. OAL_LOG_ERROR(@"Could not open capture device %@", deviceName);
  323. }
  324. }
  325. return result;
  326. }
  327. + (bool) closeCaptureDevice:(ALCdevice*) device
  328. {
  329. bool result;
  330. @synchronized(self)
  331. {
  332. alcCaptureCloseDevice(device);
  333. result = CHECK_ALC_CALL(device);
  334. }
  335. return result;
  336. }
  337. + (bool) startCapture:(ALCdevice*) device
  338. {
  339. bool result;
  340. @synchronized(self)
  341. {
  342. alcCaptureStop(device);
  343. result = CHECK_ALC_CALL(device);
  344. }
  345. return result;
  346. }
  347. + (bool) stopCapture:(ALCdevice*) device
  348. {
  349. bool result;
  350. @synchronized(self)
  351. {
  352. alcCaptureStop(device);
  353. result = CHECK_ALC_CALL(device);
  354. }
  355. return result;
  356. }
  357. + (bool) captureSamples:(ALCdevice*) device buffer:(ALCvoid*) buffer numSamples:(ALCsizei) numSamples
  358. {
  359. bool result;
  360. @synchronized(self)
  361. {
  362. alcCaptureSamples(device, buffer, numSamples);
  363. result = CHECK_ALC_CALL(device);
  364. }
  365. return result;
  366. }
  367. #pragma mark -
  368. #pragma mark Context Management
  369. + (ALCcontext*) createContext:(ALCdevice*) device attributes:(ALCint*) attributes
  370. {
  371. ALCcontext* result;
  372. @synchronized(self)
  373. {
  374. result = alcCreateContext(device, attributes);
  375. CHECK_ALC_CALL(device);
  376. }
  377. return result;
  378. }
  379. + (bool) makeContextCurrent:(ALCcontext*) context
  380. {
  381. return [self makeContextCurrent:context deviceReference:nil];
  382. }
  383. + (bool) makeContextCurrent:(ALCcontext*) context deviceReference:(ALCdevice*) deviceReference
  384. {
  385. @synchronized(self)
  386. {
  387. if(!alcMakeContextCurrent(context))
  388. {
  389. if(nil != deviceReference)
  390. {
  391. CHECK_ALC_CALL(deviceReference);
  392. }
  393. else
  394. {
  395. OAL_LOG_ERROR(@"Could not make context %d current. Pass in a device reference for better diagnostic info.", context);
  396. }
  397. return NO;
  398. }
  399. }
  400. return YES;
  401. }
  402. + (void) processContext:(ALCcontext*) context
  403. {
  404. @synchronized(self)
  405. {
  406. alcProcessContext(context);
  407. // No way to check for error from here
  408. }
  409. }
  410. + (void) suspendContext:(ALCcontext*) context
  411. {
  412. @synchronized(self)
  413. {
  414. alcSuspendContext(context);
  415. // No way to check for error from here
  416. }
  417. }
  418. + (void) destroyContext:(ALCcontext*) context
  419. {
  420. @synchronized(self)
  421. {
  422. alcDestroyContext(context);
  423. // No way to check for error from here
  424. }
  425. }
  426. + (ALCcontext*) getCurrentContext
  427. {
  428. ALCcontext* result;
  429. @synchronized(self)
  430. {
  431. result = alcGetCurrentContext();
  432. }
  433. return result;
  434. }
  435. + (ALCdevice*) getContextsDevice:(ALCcontext*) context
  436. {
  437. return [self getContextsDevice:context deviceReference:nil];
  438. }
  439. + (ALCdevice*) getContextsDevice:(ALCcontext*) context deviceReference:(ALCdevice*) deviceReference
  440. {
  441. ALCdevice* result;
  442. @synchronized(self)
  443. {
  444. if(nil == (result = alcGetContextsDevice(context)))
  445. {
  446. if(nil != deviceReference)
  447. {
  448. CHECK_ALC_CALL(deviceReference);
  449. }
  450. else
  451. {
  452. OAL_LOG_ERROR(@"Could not get device for context %d. Pass in a device reference for better diagnostic info.", context);
  453. }
  454. }
  455. }
  456. return result;
  457. }
  458. #pragma mark Context Properties
  459. + (bool) getBoolean:(ALenum) parameter
  460. {
  461. ALboolean result;
  462. @synchronized(self)
  463. {
  464. result = alGetBoolean(parameter);
  465. CHECK_AL_CALL();
  466. }
  467. return result;
  468. }
  469. + (ALdouble) getDouble:(ALenum) parameter
  470. {
  471. ALdouble result;
  472. @synchronized(self)
  473. {
  474. result = alGetDouble(parameter);
  475. CHECK_AL_CALL();
  476. }
  477. return result;
  478. }
  479. + (ALfloat) getFloat:(ALenum) parameter
  480. {
  481. ALfloat result;
  482. @synchronized(self)
  483. {
  484. result = alGetFloat(parameter);
  485. CHECK_AL_CALL();
  486. }
  487. return result;
  488. }
  489. + (ALint) getInteger:(ALenum) parameter
  490. {
  491. ALint result;
  492. @synchronized(self)
  493. {
  494. result = alGetInteger(parameter);
  495. CHECK_AL_CALL();
  496. }
  497. return result;
  498. }
  499. + (NSString*) getString:(ALenum) parameter
  500. {
  501. const ALchar* result;
  502. @synchronized(self)
  503. {
  504. result = alGetString(parameter);
  505. CHECK_AL_CALL();
  506. }
  507. return [NSString stringWithFormat:@"%s", result];
  508. }
  509. + (NSArray*) getNullSeparatedStringList:(ALenum) parameter
  510. {
  511. const ALchar* result;
  512. @synchronized(self)
  513. {
  514. result = alGetString(parameter);
  515. CHECK_AL_CALL();
  516. }
  517. return [self decodeNullSeparatedStringList:result];
  518. }
  519. + (NSArray*) getSpaceSeparatedStringList:(ALenum) parameter
  520. {
  521. const ALchar* result;
  522. @synchronized(self)
  523. {
  524. result = alGetString(parameter);
  525. CHECK_AL_CALL();
  526. }
  527. return [self decodeSpaceSeparatedStringList:result];
  528. }
  529. + (bool) getBooleanv:(ALenum) parameter values:(ALboolean*) values
  530. {
  531. bool result;
  532. @synchronized(self)
  533. {
  534. alGetBooleanv(parameter, values);
  535. result = CHECK_AL_CALL();
  536. }
  537. return result;
  538. }
  539. + (bool) getDoublev:(ALenum) parameter values:(ALdouble*) values
  540. {
  541. bool result;
  542. @synchronized(self)
  543. {
  544. alGetDoublev(parameter, values);
  545. result = CHECK_AL_CALL();
  546. }
  547. return result;
  548. }
  549. + (bool) getFloatv:(ALenum) parameter values:(ALfloat*) values
  550. {
  551. bool result;
  552. @synchronized(self)
  553. {
  554. alGetFloatv(parameter, values);
  555. result = CHECK_AL_CALL();
  556. }
  557. return result;
  558. }
  559. + (bool) getIntegerv:(ALenum) parameter values:(ALint*) values
  560. {
  561. bool result;
  562. @synchronized(self)
  563. {
  564. alGetIntegerv(parameter, values);
  565. result = CHECK_AL_CALL();
  566. }
  567. return result;
  568. }
  569. + (bool) distanceModel:(ALenum) value
  570. {
  571. bool result;
  572. @synchronized(self)
  573. {
  574. alDistanceModel(value);
  575. result = CHECK_AL_CALL();
  576. }
  577. return result;
  578. }
  579. + (bool) dopplerFactor:(ALfloat) value
  580. {
  581. bool result;
  582. @synchronized(self)
  583. {
  584. alDopplerFactor(value);
  585. result = CHECK_AL_CALL();
  586. }
  587. return result;
  588. }
  589. + (bool) speedOfSound:(ALfloat) value
  590. {
  591. bool result;
  592. @synchronized(self)
  593. {
  594. alSpeedOfSound(value);
  595. result = CHECK_AL_CALL();
  596. }
  597. return result;
  598. }
  599. #pragma mark -
  600. #pragma mark Listener Properties
  601. + (bool) listenerf:(ALenum) parameter value:(ALfloat) value
  602. {
  603. bool result;
  604. @synchronized(self)
  605. {
  606. alListenerf(parameter, value);
  607. result = CHECK_AL_CALL();
  608. }
  609. return result;
  610. }
  611. + (bool) listener3f:(ALenum) parameter v1:(ALfloat) v1 v2:(ALfloat) v2 v3:(ALfloat) v3
  612. {
  613. bool result;
  614. @synchronized(self)
  615. {
  616. alListener3f(parameter, v1, v2, v3);
  617. result = CHECK_AL_CALL();
  618. }
  619. return result;
  620. }
  621. + (bool) listenerfv:(ALenum) parameter values:(ALfloat*) values
  622. {
  623. bool result;
  624. @synchronized(self)
  625. {
  626. alListenerfv(parameter, values);
  627. result = CHECK_AL_CALL();
  628. }
  629. return result;
  630. }
  631. + (bool) listeneri:(ALenum) parameter value:(ALint) value
  632. {
  633. bool result;
  634. @synchronized(self)
  635. {
  636. alListeneri(parameter, value);
  637. result = CHECK_AL_CALL();
  638. }
  639. return result;
  640. }
  641. + (bool) listener3i:(ALenum) parameter v1:(ALint) v1 v2:(ALint) v2 v3:(ALint) v3
  642. {
  643. bool result;
  644. @synchronized(self)
  645. {
  646. alListener3i(parameter, v1, v2, v3);
  647. result = CHECK_AL_CALL();
  648. }
  649. return result;
  650. }
  651. + (bool) listeneriv:(ALenum) parameter values:(ALint*) values
  652. {
  653. bool result;
  654. @synchronized(self)
  655. {
  656. alListeneriv(parameter, values);
  657. result = CHECK_AL_CALL();
  658. }
  659. return result;
  660. }
  661. + (ALfloat) getListenerf:(ALenum) parameter
  662. {
  663. ALfloat value;
  664. @synchronized(self)
  665. {
  666. alGetListenerf(parameter, &value);
  667. CHECK_AL_CALL();
  668. }
  669. return value;
  670. }
  671. + (bool) getListener3f:(ALenum) parameter v1:(ALfloat*) v1 v2:(ALfloat*) v2 v3:(ALfloat*) v3
  672. {
  673. bool result;
  674. @synchronized(self)
  675. {
  676. alGetListener3f(parameter, v1, v2, v3);
  677. result = CHECK_AL_CALL();
  678. }
  679. return result;
  680. }
  681. + (bool) getListenerfv:(ALenum) parameter values:(ALfloat*) values
  682. {
  683. bool result;
  684. @synchronized(self)
  685. {
  686. alGetListenerfv(parameter, values);
  687. result = CHECK_AL_CALL();
  688. }
  689. return result;
  690. }
  691. + (ALint) getListeneri:(ALenum) parameter
  692. {
  693. ALint value;
  694. @synchronized(self)
  695. {
  696. alGetListeneri(parameter, &value);
  697. CHECK_AL_CALL();
  698. }
  699. return value;
  700. }
  701. + (bool) getListener3i:(ALenum) parameter v1:(ALint*) v1 v2:(ALint*) v2 v3:(ALint*) v3
  702. {
  703. bool result;
  704. @synchronized(self)
  705. {
  706. alGetListener3i(parameter, v1, v2, v3);
  707. result = CHECK_AL_CALL();
  708. }
  709. return result;
  710. }
  711. + (bool) getListeneriv:(ALenum) parameter values:(ALint*) values
  712. {
  713. bool result;
  714. @synchronized(self)
  715. {
  716. alGetListeneriv(parameter, values);
  717. result = CHECK_AL_CALL();
  718. }
  719. return result;
  720. }
  721. #pragma mark -
  722. #pragma mark Source Management
  723. + (bool) genSources:(ALuint*) sourceIds numSources:(ALsizei) numSources
  724. {
  725. bool result;
  726. @synchronized(self)
  727. {
  728. alGenSources(numSources, sourceIds);
  729. result = CHECK_AL_CALL();
  730. }
  731. return result;
  732. }
  733. + (ALuint) genSource
  734. {
  735. ALuint sourceId;
  736. @synchronized(self)
  737. {
  738. [self genSources:&sourceId numSources:1];
  739. sourceId = CHECK_AL_CALL() ? sourceId : (ALuint)AL_INVALID;
  740. }
  741. return sourceId;
  742. }
  743. + (bool) deleteSources:(ALuint*) sourceIds numSources:(ALsizei) numSources
  744. {
  745. bool result;
  746. @synchronized(self)
  747. {
  748. alDeleteSources(numSources, sourceIds);
  749. result = CHECK_AL_CALL();
  750. }
  751. return result;
  752. }
  753. + (bool) deleteSource:(ALuint) sourceId
  754. {
  755. bool result;
  756. @synchronized(self)
  757. {
  758. [self deleteSources:&sourceId numSources:1];
  759. result = CHECK_AL_CALL();
  760. }
  761. return result;
  762. }
  763. + (bool) isSource:(ALuint) sourceId
  764. {
  765. bool result;
  766. @synchronized(self)
  767. {
  768. result = alIsSource(sourceId);
  769. CHECK_AL_CALL();
  770. }
  771. return result;
  772. }
  773. #pragma mark Source Properties
  774. + (bool) sourcef:(ALuint) sourceId parameter:(ALenum) parameter value:(ALfloat) value
  775. {
  776. bool result;
  777. @synchronized(self)
  778. {
  779. alSourcef(sourceId, parameter, value);
  780. result = CHECK_AL_CALL();
  781. }
  782. return result;
  783. }
  784. + (bool) source3f:(ALuint) sourceId parameter:(ALenum) parameter v1:(ALfloat) v1 v2:(ALfloat) v2 v3:(ALfloat) v3
  785. {
  786. bool result;
  787. @synchronized(self)
  788. {
  789. alSource3f(sourceId, parameter, v1, v2, v3);
  790. result = CHECK_AL_CALL();
  791. }
  792. return result;
  793. }
  794. + (bool) sourcefv:(ALuint) sourceId parameter:(ALenum) parameter values:(ALfloat*) values
  795. {
  796. bool result;
  797. @synchronized(self)
  798. {
  799. alSourcefv(sourceId, parameter, values);
  800. result = CHECK_AL_CALL();
  801. }
  802. return result;
  803. }
  804. + (bool) sourcei:(ALuint) sourceId parameter:(ALenum) parameter value:(ALint) value
  805. {
  806. bool result;
  807. @synchronized(self)
  808. {
  809. alSourcei(sourceId, parameter, value);
  810. result = CHECK_AL_CALL();
  811. }
  812. return result;
  813. }
  814. + (bool) source3i:(ALuint) sourceId parameter:(ALenum) parameter v1:(ALint) v1 v2:(ALint) v2 v3:(ALint) v3
  815. {
  816. bool result;
  817. @synchronized(self)
  818. {
  819. alSource3i(sourceId, parameter, v1, v2, v3);
  820. result = CHECK_AL_CALL();
  821. }
  822. return result;
  823. }
  824. + (bool) sourceiv:(ALuint) sourceId parameter:(ALenum) parameter values:(ALint*) values
  825. {
  826. bool result;
  827. @synchronized(self)
  828. {
  829. alSourceiv(sourceId, parameter, values);
  830. result = CHECK_AL_CALL();
  831. }
  832. return result;
  833. }
  834. + (ALfloat) getSourcef:(ALuint) sourceId parameter:(ALenum) parameter
  835. {
  836. ALfloat value;
  837. @synchronized(self)
  838. {
  839. alGetSourcef(sourceId, parameter, &value);
  840. CHECK_AL_CALL();
  841. }
  842. return value;
  843. }
  844. + (bool) getSource3f:(ALuint) sourceId parameter:(ALenum) parameter v1:(ALfloat*) v1 v2:(ALfloat*) v2 v3:(ALfloat*) v3
  845. {
  846. bool result;
  847. @synchronized(self)
  848. {
  849. alGetSource3f(sourceId, parameter, v1, v2, v3);
  850. result = CHECK_AL_CALL();
  851. }
  852. return result;
  853. }
  854. + (bool) getSourcefv:(ALuint) sourceId parameter:(ALenum) parameter values:(ALfloat*) values
  855. {
  856. bool result;
  857. @synchronized(self)
  858. {
  859. alGetSourcefv(sourceId, parameter, values);
  860. result = CHECK_AL_CALL();
  861. }
  862. return result;
  863. }
  864. + (ALint) getSourcei:(ALuint) sourceId parameter:(ALenum) parameter
  865. {
  866. ALint value;
  867. @synchronized(self)
  868. {
  869. alGetSourcei(sourceId, parameter, &value);
  870. CHECK_AL_CALL();
  871. }
  872. return value;
  873. }
  874. + (bool) getSource3i:(ALuint) sourceId parameter:(ALenum) parameter v1:(ALint*) v1 v2:(ALint*) v2 v3:(ALint*) v3
  875. {
  876. bool result;
  877. @synchronized(self)
  878. {
  879. alGetSource3i(sourceId, parameter, v1, v2, v3);
  880. result = CHECK_AL_CALL();
  881. }
  882. return result;
  883. }
  884. + (bool) getSourceiv:(ALuint) sourceId parameter:(ALenum) parameter values:(ALint*) values
  885. {
  886. bool result;
  887. @synchronized(self)
  888. {
  889. alGetSourceiv(sourceId, parameter, values);
  890. result = CHECK_AL_CALL();
  891. }
  892. return result;
  893. }
  894. #pragma mark Source Playback
  895. + (bool) sourcePlay:(ALuint) sourceId
  896. {
  897. bool result;
  898. @synchronized(self)
  899. {
  900. alSourcePlay(sourceId);
  901. result = CHECK_AL_CALL();
  902. }
  903. return result;
  904. }
  905. + (bool) sourcePlayv:(ALuint*) sourceIds numSources:(ALsizei) numSources
  906. {
  907. bool result;
  908. @synchronized(self)
  909. {
  910. alSourcePlayv(numSources, sourceIds);
  911. result = CHECK_AL_CALL();
  912. }
  913. return result;
  914. }
  915. + (bool) sourcePause:(ALuint) sourceId
  916. {
  917. bool result;
  918. @synchronized(self)
  919. {
  920. alSourcePause(sourceId);
  921. result = CHECK_AL_CALL();
  922. }
  923. return result;
  924. }
  925. + (bool) sourcePausev:(ALuint*) sourceIds numSources:(ALsizei) numSources
  926. {
  927. bool result;
  928. @synchronized(self)
  929. {
  930. alSourcePausev(numSources, sourceIds);
  931. result = CHECK_AL_CALL();
  932. }
  933. return result;
  934. }
  935. + (bool) sourceStop:(ALuint) sourceId
  936. {
  937. bool result;
  938. @synchronized(self)
  939. {
  940. alSourceStop(sourceId);
  941. result = CHECK_AL_CALL();
  942. }
  943. return result;
  944. }
  945. + (bool) sourceStopv:(ALuint*) sourceIds numSources:(ALsizei) numSources
  946. {
  947. bool result;
  948. @synchronized(self)
  949. {
  950. alSourceStopv(numSources, sourceIds);
  951. result = CHECK_AL_CALL();
  952. }
  953. return result;
  954. }
  955. + (bool) sourceRewind:(ALuint) sourceId
  956. {
  957. bool result;
  958. @synchronized(self)
  959. {
  960. alSourceRewind(sourceId);
  961. result = CHECK_AL_CALL();
  962. }
  963. return result;
  964. }
  965. + (bool) sourceRewindv:(ALuint*) sourceIds numSources:(ALsizei) numSources
  966. {
  967. bool result;
  968. @synchronized(self)
  969. {
  970. alSourceRewindv(numSources, sourceIds);
  971. result = CHECK_AL_CALL();
  972. }
  973. return result;
  974. }
  975. + (bool) sourceQueueBuffers:(ALuint) sourceId numBuffers:(ALsizei) numBuffers bufferIds:(ALuint*) bufferIds
  976. {
  977. bool result;
  978. @synchronized(self)
  979. {
  980. alSourceQueueBuffers(sourceId, numBuffers, bufferIds);
  981. result = CHECK_AL_CALL();
  982. }
  983. return result;
  984. }
  985. + (bool) sourceUnqueueBuffers:(ALuint) sourceId numBuffers:(ALsizei) numBuffers bufferIds:(ALuint*) bufferIds
  986. {
  987. bool result;
  988. @synchronized(self)
  989. {
  990. alSourceUnqueueBuffers(sourceId, numBuffers, bufferIds);
  991. result = CHECK_AL_CALL();
  992. }
  993. return result;
  994. }
  995. #pragma mark -
  996. #pragma mark Buffer Management
  997. + (bool) genBuffers:(ALuint*) bufferIds numBuffers:(ALsizei) numBuffers
  998. {
  999. bool result;
  1000. @synchronized(self)
  1001. {
  1002. alGenBuffers(numBuffers, bufferIds);
  1003. result = CHECK_AL_CALL();
  1004. }
  1005. return result;
  1006. }
  1007. + (ALuint) genBuffer
  1008. {
  1009. ALuint bufferId;
  1010. @synchronized(self)
  1011. {
  1012. [self genBuffers:&bufferId numBuffers:1];
  1013. bufferId = CHECK_AL_CALL() ? bufferId : (ALuint)AL_INVALID;
  1014. }
  1015. return bufferId;
  1016. }
  1017. + (bool) deleteBuffers:(ALuint*) bufferIds numBuffers:(ALsizei) numBuffers
  1018. {
  1019. bool result;
  1020. @synchronized(self)
  1021. {
  1022. alDeleteBuffers(numBuffers, bufferIds);
  1023. result = CHECK_AL_CALL();
  1024. }
  1025. return result;
  1026. }
  1027. + (bool) deleteBuffer:(ALuint) bufferId
  1028. {
  1029. bool result;
  1030. @synchronized(self)
  1031. {
  1032. [self deleteBuffers:&bufferId numBuffers:1];
  1033. result = CHECK_AL_CALL();
  1034. }
  1035. return result;
  1036. }
  1037. + (bool) isBuffer:(ALuint) bufferId
  1038. {
  1039. bool result;
  1040. @synchronized(self)
  1041. {
  1042. result = alIsBuffer(bufferId);
  1043. CHECK_AL_CALL();
  1044. }
  1045. return result;
  1046. }
  1047. + (bool) bufferData:(ALuint) bufferId format:(ALenum) format data:(const ALvoid*) data size:(ALsizei) size frequency:(ALsizei) frequency
  1048. {
  1049. bool result;
  1050. @synchronized(self)
  1051. {
  1052. alBufferData(bufferId, format, data, size, frequency);
  1053. result = CHECK_AL_CALL();
  1054. }
  1055. return result;
  1056. }
  1057. #pragma mark Buffer Properties
  1058. + (bool) bufferf:(ALuint) bufferId parameter:(ALenum) parameter value:(ALfloat) value
  1059. {
  1060. bool result;
  1061. @synchronized(self)
  1062. {
  1063. alBufferf(bufferId, parameter, value);
  1064. result = CHECK_AL_CALL();
  1065. }
  1066. return result;
  1067. }
  1068. + (bool) buffer3f:(ALuint) bufferId parameter:(ALenum) parameter v1:(ALfloat) v1 v2:(ALfloat) v2 v3:(ALfloat) v3
  1069. {
  1070. bool result;
  1071. @synchronized(self)
  1072. {
  1073. alBuffer3f(bufferId, parameter, v1, v2, v3);
  1074. result = CHECK_AL_CALL();
  1075. }
  1076. return result;
  1077. }
  1078. + (bool) bufferfv:(ALuint) bufferId parameter:(ALenum) parameter values:(ALfloat*) values
  1079. {
  1080. bool result;
  1081. @synchronized(self)
  1082. {
  1083. alBufferfv(bufferId, parameter, values);
  1084. result = CHECK_AL_CALL();
  1085. }
  1086. return result;
  1087. }
  1088. + (bool) bufferi:(ALuint) bufferId parameter:(ALenum) parameter value:(ALint) value
  1089. {
  1090. bool result;
  1091. @synchronized(self)
  1092. {
  1093. alBufferi(bufferId, parameter, value);
  1094. result = CHECK_AL_CALL();
  1095. }
  1096. return result;
  1097. }
  1098. + (bool) buffer3i:(ALuint) bufferId parameter:(ALenum) parameter v1:(ALint) v1 v2:(ALint) v2 v3:(ALint) v3
  1099. {
  1100. bool result;
  1101. @synchronized(self)
  1102. {
  1103. alBuffer3i(bufferId, parameter, v1, v2, v3);
  1104. result = CHECK_AL_CALL();
  1105. }
  1106. return result;
  1107. }
  1108. + (bool) bufferiv:(ALuint) bufferId parameter:(ALenum) parameter values:(ALint*) values
  1109. {
  1110. bool result;
  1111. @synchronized(self)
  1112. {
  1113. alBufferiv(bufferId, parameter, values);
  1114. result = CHECK_AL_CALL();
  1115. }
  1116. return result;
  1117. }
  1118. + (ALfloat) getBufferf:(ALuint) bufferId parameter:(ALenum) parameter
  1119. {
  1120. ALfloat value;
  1121. @synchronized(self)
  1122. {
  1123. alGetBufferf(bufferId, parameter, &value);
  1124. CHECK_AL_CALL();
  1125. }
  1126. return value;
  1127. }
  1128. + (bool) getBuffer3f:(ALuint) bufferId parameter:(ALenum) parameter v1:(ALfloat*) v1 v2:(ALfloat*) v2 v3:(ALfloat*) v3
  1129. {
  1130. bool result;
  1131. @synchronized(self)
  1132. {
  1133. alGetBuffer3f(bufferId, parameter, v1, v2, v3);
  1134. result = CHECK_AL_CALL();
  1135. }
  1136. return result;
  1137. }
  1138. + (bool) getBufferfv:(ALuint) bufferId parameter:(ALenum) parameter values:(ALfloat*) values
  1139. {
  1140. bool result;
  1141. @synchronized(self)
  1142. {
  1143. alGetBufferfv(bufferId, parameter, values);
  1144. result = CHECK_AL_CALL();
  1145. }
  1146. return result;
  1147. }
  1148. + (ALint) getBufferi:(ALuint) bufferId parameter:(ALenum) parameter
  1149. {
  1150. ALint value;
  1151. @synchronized(self)
  1152. {
  1153. alGetBufferi(bufferId, parameter, &value);
  1154. CHECK_AL_CALL();
  1155. }
  1156. return value;
  1157. }
  1158. + (bool) getBuffer3i:(ALuint) bufferId parameter:(ALenum) parameter v1:(ALint*) v1 v2:(ALint*) v2 v3:(ALint*) v3
  1159. {
  1160. bool result;
  1161. @synchronized(self)
  1162. {
  1163. alGetBuffer3i(bufferId, parameter, v1, v2, v3);
  1164. result = CHECK_AL_CALL();
  1165. }
  1166. return result;
  1167. }
  1168. + (bool) getBufferiv:(ALuint) bufferId parameter:(ALenum) parameter values:(ALint*) values
  1169. {
  1170. bool result;
  1171. @synchronized(self)
  1172. {
  1173. alGetBufferiv(bufferId, parameter, values);
  1174. result = CHECK_AL_CALL();
  1175. }
  1176. return result;
  1177. }
  1178. #pragma mark -
  1179. #pragma mark Apple Extensions
  1180. + (ALdouble) getMixerOutputDataRate
  1181. {
  1182. if(NULL == alcGetMacOSXMixerOutputRate)
  1183. {
  1184. alcGetMacOSXMixerOutputRate = (alcMacOSXGetMixerOutputRateProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alcMacOSXGetMixerOutputRate");
  1185. if(NULL == alcGetMacOSXMixerOutputRate)
  1186. {
  1187. OAL_LOG_ERROR(@"Could not get proc pointer for \"alcMacOSXMixerOutputRate\".");
  1188. }
  1189. }
  1190. ALdouble result;
  1191. @synchronized(self)
  1192. {
  1193. result = alcGetMacOSXMixerOutputRate();
  1194. CHECK_AL_CALL();
  1195. }
  1196. return result;
  1197. }
  1198. + (void) setMixerOutputDataRate:(ALdouble) frequency
  1199. {
  1200. if(NULL == alcMacOSXMixerOutputRate)
  1201. {
  1202. alcMacOSXMixerOutputRate = (alcMacOSXMixerOutputRateProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alcMacOSXMixerOutputRate");
  1203. if(NULL == alcMacOSXMixerOutputRate)
  1204. {
  1205. OAL_LOG_ERROR(@"Could not get proc pointer for \"alcMacOSXMixerOutputRate\".");
  1206. }
  1207. }
  1208. alcMacOSXMixerOutputRate(frequency);
  1209. }
  1210. + (bool) bufferDataStatic:(ALuint) bufferId format:(ALenum) format data:(const ALvoid*) data size:(ALsizei) size frequency:(ALsizei) frequency
  1211. {
  1212. if(NULL == alBufferDataStatic)
  1213. {
  1214. alBufferDataStatic = (alBufferDataStaticProcPtr) alcGetProcAddress(NULL, (const ALCchar*) "alBufferDataStatic");
  1215. if(NULL == alBufferDataStatic)
  1216. {
  1217. OAL_LOG_ERROR(@"Could not get proc pointer for \"alBufferDataStatic\".");
  1218. }
  1219. }
  1220. bool result;
  1221. @synchronized(self)
  1222. {
  1223. alBufferDataStatic(bufferId, format, data, size, frequency);
  1224. result = CHECK_AL_CALL();
  1225. }
  1226. return result;
  1227. }
  1228. @end