audio_driver_nacl.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*************************************************************************/
  2. /* audio_driver_nacl.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "audio_driver_nacl.h"
  30. #include "ppapi/cpp/instance.h"
  31. extern pp::Instance* godot_instance;
  32. const char* AudioDriverNacl::get_name() const {
  33. return "Nacl";
  34. }
  35. void AudioDriverNacl::output_callback(void* samples, uint32_t buffer_size, void* data) {
  36. AudioDriverNacl* ad = (AudioDriverNacl*)data;
  37. int16_t* out = (int16_t*)samples;
  38. ad->lock();
  39. ad->audio_server_process(ad->sample_frame_count_, ad->samples_in);
  40. ad->unlock();
  41. for (int i=0; i<ad->sample_count; i++) {
  42. out[i] = ad->samples_in[i]>>16;
  43. };
  44. };
  45. Error AudioDriverNacl::init(){
  46. int frame_size = 4096;
  47. sample_frame_count_ = pp::AudioConfig::RecommendSampleFrameCount(godot_instance,PP_AUDIOSAMPLERATE_44100, frame_size);
  48. sample_count = sample_frame_count_ * 2;
  49. audio_ = pp::Audio(godot_instance,
  50. pp::AudioConfig(godot_instance,
  51. PP_AUDIOSAMPLERATE_44100,
  52. sample_frame_count_),
  53. &AudioDriverNacl::output_callback,
  54. this);
  55. samples_in = memnew_arr(int32_t, sample_frame_count_ * 2);
  56. return OK;
  57. }
  58. void AudioDriverNacl::start(){
  59. audio_.StartPlayback();
  60. }
  61. int AudioDriverNacl::get_mix_rate() const {
  62. return 44100;
  63. }
  64. AudioDriverSW::OutputFormat AudioDriverNacl::get_output_format() const{
  65. return OUTPUT_STEREO;
  66. }
  67. void AudioDriverNacl::lock(){
  68. }
  69. void AudioDriverNacl::unlock() {
  70. }
  71. void AudioDriverNacl::finish(){
  72. audio_.StopPlayback();
  73. }
  74. AudioDriverNacl::AudioDriverNacl() {
  75. }
  76. AudioDriverNacl::~AudioDriverNacl() {
  77. memdelete_arr(samples_in);
  78. }