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 "OpenALIncl.hpp"
11 #include "../Common/SoundStream.hpp"
14 /// This class represents a stream whose data is obtained from an OpenAL capture device.
16 {
17  public:
19  /// The constructor. Throws an exception of type std::runtime_error on failure.
20  /// @param DeviceName The name of the OpenAL device (as obtained from the ALC_CAPTURE_DEVICE_SPECIFIER list) that is used for capturing.
21  /// @param Format The data format in which the samples are captured, kept and returned). Must be AL_FORMAT_MONO16 or AL_FORMAT_STEREO16.
22  /// @param SampleFrq The frequency the device is sampled with.
23  CaptureStreamT(const std::string& DeviceName, ALenum Format=AL_FORMAT_STEREO16, unsigned int SampleFrq=44100);
25  /// The destructor.
28  // SoundStreamT implementation.
29  int Read(unsigned char* Buffer, unsigned int Size);
30  bool Rewind();
31  unsigned int GetChannels();
32  unsigned int GetRate();
35  private:
37  unsigned int GetNumCaptureSamples() const; ///< Returns the number of currently available samples in the OpenAL capture buffer. This is just a wrapper around alcGetIntegerv(m_CaptureDevice, ALC_CAPTURE_SAMPLES, ...).
38  void ReduceSamplesTo(unsigned int NumLeft); ///< Reduces the number of samples in the OpenAL capture buffer so that no more than NumLeft samples are left.
39  void PrintDebug() const; ///< Prints some debug output to the standard output stream.
41  const ALenum m_FORMAT; ///< The OpenAL data format that we use for both capturing and output.
42  const unsigned int m_SAMPLE_FRQ; ///< The frequency in Hz with which the capture device is sampled. Defaults to 44100 Hz.
43  const unsigned int m_MAX_CAPTURE_BUFFER_SAMPLES; ///< The size of the ring buffer that OpenAL is to use for capturing, given in number of samples. We always try to keep this buffer about half filled in order to avoid buffer over- or underflow.
44  ALCdevice* m_CaptureDevice; ///< The OpenGL device from which we capture input to provide the PCM data for the buffers.
45  bool m_IsCapturing; ///< True while we're actually capturing (between calls to alcCaptureStart() and alcCaptureStop()).
46  unsigned int m_ZeroSamples; ///< The number of "zero" samples that are currently filled in to cover for buffer underflow.
47 };
49 #endif
unsigned int GetChannels()
Returns the number of channels in the current stream.
Definition: CaptureStream.cpp:175
int Read(unsigned char *Buffer, unsigned int Size)
Reads an amount of bytes from the stream and writes them into the buffer.
Definition: CaptureStream.cpp:98
This class represents a stream whose data is obtained from an OpenAL capture device.
Definition: CaptureStream.hpp:15
unsigned int GetRate()
Get the sampling rate of this stream.
Definition: CaptureStream.cpp:181
Represents a 16 Bit encoded mono or stereo raw PCM data stream.
Definition: SoundStream.hpp:14
The destructor.
Definition: CaptureStream.cpp:53
bool Rewind()
Sets the stream back to the beginning.
Definition: CaptureStream.cpp:155
CaptureStreamT(const std::string &DeviceName, ALenum Format=AL_FORMAT_STEREO16, unsigned int SampleFrq=44100)
The constructor.
Definition: CaptureStream.cpp:31