Cafu Engine
OggVorbisStream.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_OGG_VORBIS_STREAM_HPP_INCLUDED
8 #define CAFU_OGG_VORBIS_STREAM_HPP_INCLUDED
9 
10 #include "SoundStream.hpp"
11 
12 #if defined(_WIN32) && defined(_MSC_VER)
13 // Turn off warning 4244 for vorbisfile.h: 'Argument': Konvertierung von 'ogg_int64_t' in 'long', moeglicher Datenverlust.
14 #pragma warning(disable:4244)
15 #endif
16 #define OV_EXCLUDE_STATIC_CALLBACKS
17 #include "vorbis/vorbisfile.h"
18 #if defined(_WIN32) && defined(_MSC_VER)
19 #pragma warning(error:4244)
20 #endif
21 
22 
23 namespace cf { namespace FileSys { class InFileI; } }
24 
25 
26 /// Represents an Ogg Vorbis stream.
27 /// Audio data is decompressed and readable as 16 bit enconded mono or stereo raw PCM data.
28 /// This class uses libogg and libvorbis provided by Xiph.org to read PCM data from an Ogg
29 /// Vorbis file.
31 {
32  public:
33 
34  /// The constructor. Throws an exception of type std::runtime_error on failure.
35  /// Creates an audio data stream from an Ogg Vorbis file.
36  /// @param FileName The path to the file from which the stream should be created.
37  OggVorbisStreamT(const std::string& FileName);
38 
39  /// Destructor.
41 
42  // SoundStreamT implementation.
43  int Read(unsigned char* Buffer, unsigned int Size);
44  bool Rewind();
45  unsigned int GetChannels();
46  unsigned int GetRate();
47 
48 
49  private:
50 
51  OggVorbis_File StreamHandle; ///< Handle to the vorbis file structure.
52  cf::FileSys::InFileI* StreamFile; ///< The file handle from which the vorbis data is streamed.
53  vorbis_info* StreamInfo; ///< Information about the current bitstream read from the ogg vorbis file.
54 
55  int BitStream; ///< Number of the current bitstream.
56 };
57 
58 #endif
Represents an Ogg Vorbis stream.
Definition: OggVorbisStream.hpp:30
unsigned int GetChannels()
Returns the number of channels in the current stream.
Definition: OggVorbisStream.cpp:160
Definition: File.hpp:55
int Read(unsigned char *Buffer, unsigned int Size)
Reads an amount of bytes from the stream and writes them into the buffer.
Definition: OggVorbisStream.cpp:104
bool Rewind()
Sets the stream back to the beginning.
Definition: OggVorbisStream.cpp:146
unsigned int GetRate()
Get the sampling rate of this stream.
Definition: OggVorbisStream.cpp:168
~OggVorbisStreamT()
Destructor.
Definition: OggVorbisStream.cpp:96
Represents a 16 Bit encoded mono or stereo raw PCM data stream.
Definition: SoundStream.hpp:14
OggVorbisStreamT(const std::string &FileName)
The constructor.
Definition: OggVorbisStream.cpp:61