AudioStream 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSG_AUDIOSTREAM
  14. #define OSG_AUDIOSTREAM 1
  15. #include <osg/Image>
  16. #include <stdlib.h>
  17. namespace osg {
  18. /** Pure virtual AudioSink bass class that is used to connect the audio system with AudioStreams. */
  19. class OSG_EXPORT AudioSink : public osg::Object
  20. {
  21. public:
  22. AudioSink();
  23. virtual const char * libraryName() const { return "osg"; }
  24. virtual const char * className() const { return "AudioSinkInterface"; }
  25. virtual void play() = 0;
  26. virtual void pause() = 0;
  27. virtual void stop() = 0;
  28. virtual bool playing() const = 0;
  29. virtual double getDelay() const { return _delay; }
  30. virtual void setDelay(const double delay) { _delay = delay; }
  31. virtual void setVolume(float) {}
  32. virtual float getVolume() const { return 0.0f; }
  33. private:
  34. virtual Object* cloneType() const { return 0; }
  35. virtual Object* clone(const osg::CopyOp &) const { return 0; }
  36. double _delay;
  37. };
  38. /** Pure virtual AudioStream base class. Subclasses provide mechanism for reading/generating audio data*/
  39. class OSG_EXPORT AudioStream : public osg::Object
  40. {
  41. public:
  42. AudioStream();
  43. /** Copy constructor using CopyOp to manage deep vs shallow copy. */
  44. AudioStream(const AudioStream& audio,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  45. virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const AudioStream*>(obj)!=0; }
  46. virtual const char* libraryName() const { return "osg"; }
  47. virtual const char* className() const { return "AudioStream"; }
  48. virtual void setAudioSink(osg::AudioSink* audio_sink) = 0;
  49. virtual void consumeAudioBuffer(void * const buffer, const size_t size) = 0;
  50. virtual int audioFrequency() const = 0;
  51. virtual int audioNbChannels() const = 0;
  52. enum SampleFormat
  53. {
  54. SAMPLE_FORMAT_U8,
  55. SAMPLE_FORMAT_S16,
  56. SAMPLE_FORMAT_S24,
  57. SAMPLE_FORMAT_S32,
  58. SAMPLE_FORMAT_F32
  59. };
  60. virtual SampleFormat audioSampleFormat() const = 0;
  61. };
  62. } // namespace
  63. #endif