audio_stream.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*************************************************************************/
  2. /* audio_stream.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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_stream.h"
  30. int AudioStream::InternalAudioStream::get_channel_count() const {
  31. return owner->get_channel_count();
  32. }
  33. void AudioStream::InternalAudioStream::set_mix_rate(int p_rate) {
  34. owner->_mix_rate=p_rate;
  35. }
  36. bool AudioStream::InternalAudioStream::mix(int32_t *p_buffer,int p_frames) {
  37. return owner->mix(p_buffer,p_frames);
  38. }
  39. bool AudioStream::InternalAudioStream::can_update_mt() const {
  40. return owner->get_update_mode()==UPDATE_THREAD;
  41. }
  42. void AudioStream::InternalAudioStream::update() {
  43. owner->update();
  44. }
  45. AudioServer::AudioStream *AudioStream::get_audio_stream() {
  46. return internal_audio_stream;
  47. }
  48. void AudioStream::_bind_methods() {
  49. ObjectTypeDB::bind_method(_MD("play"),&AudioStream::play);
  50. ObjectTypeDB::bind_method(_MD("stop"),&AudioStream::stop);
  51. ObjectTypeDB::bind_method(_MD("is_playing"),&AudioStream::is_playing);
  52. ObjectTypeDB::bind_method(_MD("set_loop","enabled"),&AudioStream::set_loop);
  53. ObjectTypeDB::bind_method(_MD("has_loop"),&AudioStream::has_loop);
  54. ObjectTypeDB::bind_method(_MD("get_stream_name"),&AudioStream::get_stream_name);
  55. ObjectTypeDB::bind_method(_MD("get_loop_count"),&AudioStream::get_loop_count);
  56. ObjectTypeDB::bind_method(_MD("seek_pos","pos"),&AudioStream::seek_pos);
  57. ObjectTypeDB::bind_method(_MD("get_pos"),&AudioStream::get_pos);
  58. ObjectTypeDB::bind_method(_MD("get_length"),&AudioStream::get_length);
  59. ObjectTypeDB::bind_method(_MD("get_update_mode"),&AudioStream::get_update_mode);
  60. ObjectTypeDB::bind_method(_MD("update"),&AudioStream::update);
  61. BIND_CONSTANT( UPDATE_NONE );
  62. BIND_CONSTANT( UPDATE_IDLE );
  63. BIND_CONSTANT( UPDATE_THREAD );
  64. }
  65. AudioStream::AudioStream() {
  66. _mix_rate=44100;
  67. internal_audio_stream = memnew( InternalAudioStream );
  68. internal_audio_stream->owner=this;
  69. }
  70. AudioStream::~AudioStream() {
  71. memdelete(internal_audio_stream);
  72. }