Cafu Engine
1 /*
2 Cafu Engine,
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
10 #include "Buffer.hpp"
13 class SoundStreamT;
16 /// A StreamingBufferT is a BufferT specialization for audio data from a device or file whose contents is not kept in memory all at once.
17 /// Instead, the audio data is streamed from the resource and piecewise queued on the OpenAL source.
18 /// StreamingBufferT instances cannot be shared, each instance can only be used on a single mixer track.
19 class StreamingBufferT : public BufferT
20 {
21  public:
23  /// The constructor. Throws an exception of type std::runtime_error on failure.
24  /// @param ResName The name of the audio resource that this buffer is created from. ResName can be a file name or the name of an OpenAL capture device (as obtained from the ALC_CAPTURE_DEVICE_SPECIFIER list).
25  /// @param ForceMono Whether the data from the resource should be reduced to a single channel before use (mono output).
26  StreamingBufferT(const std::string& ResName, bool ForceMono);
28  /// The destructor.
31  // BufferT implementation.
32  unsigned int GetChannels() const;
33  bool CanShare() const;
34  void Update();
35  bool AttachToMixerTrack(MixerTrackT* MixerTrack);
36  bool DetachFromMixerTrack(MixerTrackT* MixerTrack);
39  private:
41  /// Fills the given buffers with new stream data and queues them on the mixer track (the OpenAL source).
42  /// If the stream has no more data, only the required buffers are processed and the m_EndReached flag is set.
43  unsigned int FillAndQueue(const ArrayT<ALuint>& Buffers);
45  SoundStreamT* m_Stream; ///< The stream that provides the PCM data for the buffers.
46  ArrayT<ALuint> m_Buffers; ///< The buffers that are queued on the source and played alternately with current data from the stream.
47 };
49 #endif
StreamingBufferT(const std::string &ResName, bool ForceMono)
The constructor.
Definition: StreamingBuffer.cpp:15
A mixer track represents/encapsulates/abstracs an OpenAL sound source.
Definition: MixerTrack.hpp:22
The destructor.
Definition: StreamingBuffer.cpp:25
A BufferT encapsulates an audio resource such as a file or a capture device.
Definition: Buffer.hpp:22
unsigned int GetChannels() const
Returns the number of audio channels in this buffer (1 is mono, 2 is stereo).
Definition: StreamingBuffer.cpp:36
bool DetachFromMixerTrack(MixerTrackT *MixerTrack)
Detaches the buffer from a mixer track.
Definition: StreamingBuffer.cpp:146
Represents a 16 Bit encoded mono or stereo raw PCM data stream.
Definition: SoundStream.hpp:14
bool CanShare() const
Returns whether this buffer can be attached to multiple mixer tracks (resource sharing).
Definition: StreamingBuffer.cpp:42
A StreamingBufferT is a BufferT specialization for audio data from a device or file whose contents is...
Definition: StreamingBuffer.hpp:19
bool AttachToMixerTrack(MixerTrackT *MixerTrack)
Attaches the buffer to a mixer track, so the mixer track can play this buffer.
Definition: StreamingBuffer.cpp:131
void Update()
Updates the buffer.
Definition: StreamingBuffer.cpp:90