StreamBuffer.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. ******************************************************************************/
  16. #pragma once
  17. /**
  18. * @file StreamBuffer.h
  19. * @ingroup util
  20. * The StreamBuffer class.
  21. */
  22. #include "ISound.h"
  23. #include "respec/Specification.h"
  24. AUD_NAMESPACE_BEGIN
  25. class Buffer;
  26. /**
  27. * This sound creates a buffer out of a reader. This way normally streamed
  28. * sound sources can be loaded into memory for buffered playback.
  29. */
  30. class AUD_API StreamBuffer : public ISound
  31. {
  32. private:
  33. /**
  34. * The buffer that holds the audio data.
  35. */
  36. std::shared_ptr<Buffer> m_buffer;
  37. /**
  38. * The specification of the samples.
  39. */
  40. Specs m_specs;
  41. // delete copy constructor and operator=
  42. StreamBuffer(const StreamBuffer&) = delete;
  43. StreamBuffer& operator=(const StreamBuffer&) = delete;
  44. public:
  45. /**
  46. * Creates the sound and reads the reader created by the sound supplied
  47. * to the buffer.
  48. * \param sound The sound that creates the reader for buffering.
  49. * \exception Exception Thrown if the reader cannot be created.
  50. */
  51. StreamBuffer(std::shared_ptr<ISound> sound);
  52. /**
  53. * Creates the sound from an preexisting buffer.
  54. * \param buffer The buffer to stream from.
  55. * \param specs The specification of the data in the buffer.
  56. * \exception Exception Thrown if the reader cannot be created.
  57. */
  58. StreamBuffer(std::shared_ptr<Buffer> buffer, Specs specs);
  59. /**
  60. * Returns the buffer to be streamed.
  61. * @return The buffer to stream.
  62. */
  63. std::shared_ptr<Buffer> getBuffer();
  64. /**
  65. * Returns the specification of the buffer.
  66. * @return The specification of the buffer.
  67. */
  68. Specs getSpecs();
  69. virtual std::shared_ptr<IReader> createReader();
  70. };
  71. AUD_NAMESPACE_END