Gorgon Game Engine
FLAC.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Containers/Wave.h"
4 
5 
6 namespace Gorgon { namespace Encoding {
7 
11  class FLAC {
12  public:
13  FLAC(int buffersize = 1024);
14 
15  ~FLAC();
16 
22  void Encode(const Containers::Wave &input, std::ostream &output, int bps = 16);
23 
29  void Encode(const Containers::Wave &input, const std::string &filename, int bps = 16) {
30  std::ofstream stream(filename, std::ios::binary);
31  Encode(input, stream, bps);
32  }
33 
38  void Encode(const Containers::Wave &input, std::vector<Byte> &output, int bps = 16);
39 
41  void Decode(std::istream &input, Containers::Wave &wave);
42 
44  void Decode(const std::vector<Byte> &input, Containers::Wave &wave);
45 
47  void Decode(const std::string &filename, Containers::Wave &wave) {
48  std::ifstream stream(filename, std::ios::binary);
49  if(!stream.is_open()) throw std::runtime_error("Cannot open file");
50  return Decode(stream, wave);
51  }
52 
53  private:
54  void *prepencode(const Containers::Wave &input, int bps);
55 
56  void encode(void *enc, const Containers::Wave &input, int bps);
57 
58  void *prepdecode();
59 
60 
61  int buffersize;
62  std::vector<int32_t> buffer;
63  std::streampos maxpos;
64  };
65 
66  class FlacStream {
67  public:
68  template <class I_>
69  FlacStream(const I_ &input, Containers::Wave &output);
70 
71  bool Eof() const;
72 
73  void Read();
74 
75  void Seek(std::size_t destination);
76 
77 
78  };
79 
80  extern FLAC Flac;
81 
82 } }
Gorgon::Encoding::FlacStream::FlacStream
FlacStream(const I_ &input, Containers::Wave &output)
Gorgon::Encoding::stream_encode_seek
FLAC__StreamEncoderSeekStatus stream_encode_seek(const FLAC__StreamEncoder *, FLAC__uint64 absolute_byte_offset, void *client_data)
Definition: FLAC.cpp:103
Gorgon::Encoding::decode_write
FLAC__StreamDecoderWriteStatus decode_write(const FLAC__StreamDecoder *, const FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data)
Definition: FLAC.cpp:201
Gorgon::Audio::StandardChannels
std::vector< Channel > StandardChannels(int channelcount)
Definition: Basic.h:39
Gorgon::Encoding::stream_encode_write
FLAC__StreamEncoderWriteStatus stream_encode_write(const FLAC__StreamEncoder *, const FLAC__byte buffer[], size_t bytes, unsigned, unsigned, void *client_data)
Definition: FLAC.cpp:92
Gorgon::Encoding::Flac
FLAC Flac
Definition: FLAC.cpp:419
Gorgon::Encoding::FLAC::~FLAC
~FLAC()
Definition: FLAC.cpp:288
Gorgon::Containers::Wave::Assume
void Assume(float *newdata, unsigned long size)
Assumes the ownership of the data.
Definition: Wave.h:299
Gorgon::Encoding::FLAC::Decode
void Decode(std::istream &input, Containers::Wave &wave)
Decodes given FLAC compressed data and fills a wave container.
Definition: FLAC.cpp:342
Gorgon::Encoding::stream_encode_tell
FLAC__StreamEncoderTellStatus stream_encode_tell(const FLAC__StreamEncoder *, FLAC__uint64 *absolute_byte_offset, void *client_data)
Definition: FLAC.cpp:117
Gorgon::Encoding::FLAC
Provides FLAC encoding support.
Definition: FLAC.h:11
Gorgon::Encoding::vector_encode_write
FLAC__StreamEncoderWriteStatus vector_encode_write(const FLAC__StreamEncoder *, const FLAC__byte buffer[], size_t bytes, unsigned, unsigned, void *client_data)
Definition: FLAC.cpp:127
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Encoding::FLAC::Decode
void Decode(const std::string &filename, Containers::Wave &wave)
Decodes given FLAC compressed file and fills a wave container.
Definition: FLAC.h:47
Gorgon::Containers::Wave::SetSampleRate
void SetSampleRate(unsigned rate)
Sets the number samples per second.
Definition: Wave.h:456
Gorgon::Encoding::FlacStream
Definition: FLAC.h:66
Gorgon::Encoding::FlacStream::Read
void Read()
Gorgon::Encoding::vector_encode_seek
FLAC__StreamEncoderSeekStatus vector_encode_seek(const FLAC__StreamEncoder *, FLAC__uint64 absolute_byte_offset, void *client_data)
Definition: FLAC.cpp:140
Gorgon::Containers::Wave::GetChannelCount
unsigned GetChannelCount() const
Returns the number of channels that this wave data has.
Definition: Wave.h:420
FLAC.h
Gorgon::Encoding::stream_decode_read
FLAC__StreamDecoderReadStatus stream_decode_read(const FLAC__StreamDecoder *, FLAC__byte buffer[], size_t *bytes, void *client_data)
Definition: FLAC.cpp:163
Gorgon::Encoding::FLAC::Encode
void Encode(const Containers::Wave &input, const std::string &filename, int bps=16)
Encodes the given wave data to FLAC compressed data.
Definition: FLAC.h:29
Gorgon::Encoding::decode_error
void decode_error(const FLAC__StreamDecoder *, FLAC__StreamDecoderErrorStatus, void *)
Definition: FLAC.cpp:230
Gorgon::Encoding::FlacStream::Eof
bool Eof() const
Gorgon::Encoding::FLAC::Encode
void Encode(const Containers::Wave &input, std::ostream &output, int bps=16)
Encodes the given wave data to FLAC compressed data.
Definition: FLAC.cpp:291
Gorgon::Encoding::vector_encode_tell
FLAC__StreamEncoderTellStatus vector_encode_tell(const FLAC__StreamEncoder *, FLAC__uint64 *absolute_byte_offset, void *client_data)
Definition: FLAC.cpp:153
Gorgon::Encoding::vector_decode_read
FLAC__StreamDecoderReadStatus vector_decode_read(const FLAC__StreamDecoder *, FLAC__byte buffer[], size_t *bytes, void *client_data)
Definition: FLAC.cpp:179
Gorgon::Containers::Wave
This class is a container for wave data.
Definition: Wave.h:17
Gorgon::Encoding::FlacStream::Seek
void Seek(std::size_t destination)
Gorgon::Encoding::FLAC::FLAC
FLAC(int buffersize=1024)
Definition: FLAC.cpp:284
Gorgon::Containers::Wave::GetSize
unsigned long GetSize() const
Returns the size of the wave.
Definition: Wave.h:405
Gorgon::Containers::Wave::GetSampleRate
unsigned GetSampleRate() const
Returns the number of samples per second.
Definition: Wave.h:451