cAudio  2.3.0
3d Audio Engine
cRawDecoder.cpp
1 // Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2 // This file is part of the "cAudio Engine"
3 // For conditions of distribution and use, see copyright notice in cAudio.h
4 
5 #include "cRawDecoder.h"
6 
7 namespace cAudio{
8 
9  cRawDecoder::cRawDecoder(IDataSource* stream, unsigned int frequency, AudioFormats format) : IAudioDecoder(stream), Frequency(frequency), Format(format)
10  {
11 
12  }
13 
14  cRawDecoder::~cRawDecoder()
15  {
16 
17  }
18 
20  {
21  return Format;
22  }
23 
25  {
26  return Frequency;
27  }
28 
30  {
31  return true;
32  }
33 
35  {
36  return true;
37  }
38 
39  int cRawDecoder::readAudioData(void* output, int amount)
40  {
41  return Stream->read(output,amount);
42  }
43 
44  bool cRawDecoder::setPosition(int position, bool relative)
45  {
46  Stream->seek(position,relative);
47  return true;
48  }
49 
50  bool cRawDecoder::seek(float seconds,bool relative)
51  {
52  int SampleSize = 1;
53  if(Format == EAF_8BIT_MONO)
54  SampleSize = 1;
55  else if(Format == EAF_8BIT_STEREO)
56  SampleSize = 2;
57  else if(Format == EAF_16BIT_MONO)
58  SampleSize = 2;
59  else
60  SampleSize = 4;
61 
62  int amountToSeek = seconds * (float)Frequency * (float)SampleSize;
63  return setPosition(amountToSeek, relative);
64  }
65 
67  {
68  int SampleSize = 0;
69  if(Format == EAF_8BIT_MONO)
70  SampleSize = 1;
71  else if(Format == EAF_8BIT_STEREO)
72  SampleSize = 2;
73  else if(Format == EAF_16BIT_MONO)
74  SampleSize = 2;
75  else
76  SampleSize = 4;
77  return (float)Stream->getSize() / ((float)Frequency * (float)SampleSize);
78  }
79 
81  {
82  return Stream->getSize();
83  }
84 
86  {
87  return Stream->getSize();
88  }
89 
91  {
92  int SampleSize = 0;
93  if(Format == EAF_8BIT_MONO)
94  SampleSize = 1;
95  else if(Format == EAF_8BIT_STEREO)
96  SampleSize = 2;
97  else if(Format == EAF_16BIT_MONO)
98  SampleSize = 2;
99  else
100  SampleSize = 4;
101 
102  return (float)Stream->getCurrentPos() / ((float)Frequency * (float)SampleSize);
103  }
104 
106  {
107  return Stream->getCurrentPos();
108  }
109 
111  {
112  return Stream->getCurrentPos();
113  }
114 
115  cAudioString cRawDecoder::getType() const
116  {
117  return cAudioString(_CTEXT("cRawDecoder"));
118  }
119 }
virtual int readAudioData(void *output, int amount)
Reads a section of data out of the audio stream.
Definition: cRawDecoder.cpp:39
virtual cAudioString getType() const
Returns the IAudioDecoderType.
virtual AudioFormats getFormat()
Returns the format of the audio data.
Definition: cRawDecoder.cpp:19
virtual int getCurrentCompressedPosition()
Returns the position in the compressed (original) audio stream before decoding.
virtual int getFrequency()
Returns the frequency (sample rate) of the audio data.
Definition: cRawDecoder.cpp:24
virtual int getTotalSize()
If available, returns the total decoded size of the audio stream. Returns a negative number if this c...
Definition: cRawDecoder.cpp:80
virtual float getCurrentTime()
If seeking is supported, will return the current position in the stream in seconds. Returns a negative number if the current time cannot be determined.
Definition: cRawDecoder.cpp:90
virtual int getCompressedSize()
Returns the compressed (original) size of the audio stream, before decoding.
Definition: cRawDecoder.cpp:85
virtual bool seek(float seconds, bool relative)
If seeking is supported, will seek the stream to seconds.
Definition: cRawDecoder.cpp:50
virtual bool isValid()
Returns whether the stream is valid for this codec.
Definition: cRawDecoder.cpp:34
virtual bool isSeekingSupported()
Returns whether seeking is supported.
Definition: cRawDecoder.cpp:29
virtual int getCurrentPosition()
If available, returns the current position in the decoded audio stream in bytes. Returns a negative n...
virtual bool setPosition(int position, bool relative)
Sets the position in the stream to read from.
Definition: cRawDecoder.cpp:44
virtual float getTotalTime()
If seeking is supported, will return the length of the audio steam in seconds. Returns a negative num...
Definition: cRawDecoder.cpp:66
AudioFormats
Enumeration of audio formats supported by the engine.
Definition: EAudioFormats.h:10
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:15