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 
19  AudioFormats cRawDecoder::getFormat()
20  {
21  return Format;
22  }
23 
24  int cRawDecoder::getFrequency()
25  {
26  return Frequency;
27  }
28 
29  bool cRawDecoder::isSeekingSupported()
30  {
31  return true;
32  }
33 
34  bool cRawDecoder::isValid()
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 
66  float cRawDecoder::getTotalTime()
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 
80  int cRawDecoder::getTotalSize()
81  {
82  return Stream->getSize();
83  }
84 
85  int cRawDecoder::getCompressedSize()
86  {
87  return Stream->getSize();
88  }
89 
90  float cRawDecoder::getCurrentTime()
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 
105  int cRawDecoder::getCurrentPosition()
106  {
107  return Stream->getCurrentPos();
108  }
109 
110  int cRawDecoder::getCurrentCompressedPosition()
111  {
112  return Stream->getCurrentPos();
113  }
114 
115  cAudioString cRawDecoder::getType() const
116  {
117  return cAudioString(_CTEXT("cRawDecoder"));
118  }
119 }
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:16
AudioFormats
Enumeration of audio formats supported by the engine.
Definition: EAudioFormats.h:11