cRawDecoder.cpp

00001 // Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
00002 // This file is part of the "cAudio Engine"
00003 // For conditions of distribution and use, see copyright notice in cAudio.h
00004 
00005 #include "../Headers/cRawDecoder.h"
00006 
00007 namespace cAudio{
00008 
00009         cRawDecoder::cRawDecoder(IDataSource* stream,  unsigned int frequency, AudioFormats format) : IAudioDecoder(stream), Frequency(frequency), Format(format)
00010     {
00011 
00012     }
00013 
00014     cRawDecoder::~cRawDecoder()
00015     {
00016 
00017     }
00018 
00019     AudioFormats cRawDecoder::getFormat()
00020     {
00021         return Format;
00022     }
00023 
00024     int cRawDecoder::getFrequency()
00025     {
00026         return Frequency;
00027     }
00028 
00029     bool cRawDecoder::isSeekingSupported()
00030     {
00031         return true;
00032     }
00033 
00034         bool cRawDecoder::isValid()
00035         {
00036                 return true;
00037         }
00038 
00039     int cRawDecoder::readAudioData(void* output, int amount)
00040     {
00041         return Stream->read(output,amount);
00042     }
00043 
00044     bool cRawDecoder::setPosition(int position, bool relative)
00045     {
00046         Stream->seek(position,relative);
00047         return true;
00048     }
00049 
00050     bool cRawDecoder::seek(float seconds,bool relative)
00051     {
00052                 int SampleSize = 1;
00053                 if(Format == EAF_8BIT_MONO)
00054                         SampleSize = 1;
00055                 else if(Format == EAF_8BIT_STEREO)
00056                         SampleSize = 2;
00057                 else if(Format == EAF_16BIT_MONO)
00058                         SampleSize = 2;
00059                 else
00060                         SampleSize = 4;
00061 
00062         int amountToSeek = seconds * (float)Frequency * (float)SampleSize;
00063         return setPosition(amountToSeek, relative);
00064     }
00065 
00066         float cRawDecoder::getTotalTime()
00067         {
00068                 int SampleSize = 0;
00069                 if(Format == EAF_8BIT_MONO)
00070                         SampleSize = 1;
00071                 else if(Format == EAF_8BIT_STEREO)
00072                         SampleSize = 2;
00073                 else if(Format == EAF_16BIT_MONO)
00074                         SampleSize = 2;
00075                 else
00076                         SampleSize = 4;
00077                 return (float)Stream->getSize() / ((float)Frequency * (float)SampleSize);
00078         }
00079 
00080         int cRawDecoder::getTotalSize()
00081         {
00082                 return Stream->getSize();
00083         }
00084 
00085         int cRawDecoder::getCompressedSize()
00086         {
00087                 return Stream->getSize();
00088         }
00089 
00090         float cRawDecoder::getCurrentTime()
00091         {
00092                 int SampleSize = 0;
00093                 if(Format == EAF_8BIT_MONO)
00094                         SampleSize = 1;
00095                 else if(Format == EAF_8BIT_STEREO)
00096                         SampleSize = 2;
00097                 else if(Format == EAF_16BIT_MONO)
00098                         SampleSize = 2;
00099                 else
00100                         SampleSize = 4;
00101 
00102                 return (float)Stream->getCurrentPos() / ((float)Frequency * (float)SampleSize);
00103         }
00104 
00105         int cRawDecoder::getCurrentPosition()
00106         {
00107                 return Stream->getCurrentPos();
00108         }
00109 
00110         int cRawDecoder::getCurrentCompressedPosition()
00111         {
00112                 return Stream->getCurrentPos();
00113         }
00114 }
 All Classes Namespaces Functions Variables Enumerations

Generated on Sat Feb 20 22:55:09 2010 for cAudio by  doxygen 1.6.2