Cafu Engine
MP3Stream.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_SOUNDSYS_MP3_STREAM_HPP_INCLUDED
8 #define CAFU_SOUNDSYS_MP3_STREAM_HPP_INCLUDED
9 
10 #include "SoundStream.hpp"
11 
12 
13 struct mpg123_handle_struct;
14 typedef struct mpg123_handle_struct mpg123_handle;
15 namespace cf { namespace FileSys { class InFileI; } }
16 
17 
18 /// Represents an MP3 stream.
19 /// Audio data is decompressed and readable as 16 bit enconded mono or stereo raw PCM data.
20 /// This class uses the mpg123 library to read PCM data from an MP3 file.
21 class MP3StreamT : public SoundStreamT
22 {
23  public:
24 
25  /// The constructor. Throws an exception of type std::runtime_error on failure.
26  /// Creates an audio data stream from an MP3 file.
27  /// @param FileName The path to the file from which the stream should be created.
28  MP3StreamT(const std::string& FileName);
29 
30  /// Destructor.
31  ~MP3StreamT();
32 
33  // SoundStream implementation.
34  int Read(unsigned char* Buffer, unsigned int Size);
35  bool Rewind();
36  unsigned int GetChannels();
37  unsigned int GetRate();
38 
39 
40  private:
41 
42  mpg123_handle* StreamHandle; ///< Handle to the mpg123 stream.
43  cf::FileSys::InFileI* StreamFile; ///< The file handle from which the mp3 data is streamed.
44 
45  long Rate; ///< Sampling rate of this stream in Hz.
46  int Channels; ///< Number of channels in this stream.
47 };
48 
49 #endif
MP3StreamT(const std::string &FileName)
The constructor.
Definition: MP3Stream.cpp:87
Definition: File.hpp:55
unsigned int GetChannels()
Returns the number of channels in the current stream.
Definition: MP3Stream.cpp:211
Represents an MP3 stream.
Definition: MP3Stream.hpp:21
unsigned int GetRate()
Get the sampling rate of this stream.
Definition: MP3Stream.cpp:217
int Read(unsigned char *Buffer, unsigned int Size)
Reads an amount of bytes from the stream and writes them into the buffer.
Definition: MP3Stream.cpp:167
Represents a 16 Bit encoded mono or stereo raw PCM data stream.
Definition: SoundStream.hpp:14
~MP3StreamT()
Destructor.
Definition: MP3Stream.cpp:149
bool Rewind()
Sets the stream back to the beginning.
Definition: MP3Stream.cpp:189