Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

conv.cpp

Go to the documentation of this file.
00001 
00006 #include <sstream>
00007 #include <iomanip>
00008 #include <cctype>
00009 
00010 #include "conv.h"
00011 #include "mp3_format.h"
00012 
00013 std::string Conv::Frame2Time(int framenum)
00014 {
00015   int time = framenum * mp3::frametime; //Time in miliseconds
00016   std::stringstream stream;
00017   
00018   //Format the time (minutes:seconds.miliseconds)
00019   stream << (time / 60000) << ':' << std::setw(2) << std::setfill('0') 
00020           << (time % 60000 / 1000) << '.' << std::setw(3) << (time % 1000);
00021   return stream.str();
00022 }
00023 
00024 int Conv::Time2Frame(const char *ch)
00025 {
00026   int time = 0;
00027   
00028   while(*ch >= '0' && *ch <= '9') //First number
00029   {  
00030     time = time * 10 + *ch - '0';
00031     ch++;
00032   }
00033   
00034   if(*ch++ == ':') //If there is ':', first number was
00035   {                // minute, otherwise it was second
00036     int sec = 0;
00037     while(*ch >= '0' && *ch <= '9')
00038     {  
00039       sec = sec * 10 + *ch - '0';
00040       ch++;
00041     }
00042     time = 60 * time + sec;
00043   }
00044   
00045   time *= 1000;
00046   if(*ch++ == '.') //Miliseconds
00047   {  
00048     int milisec = 0;
00049     while(*ch >= '0' && *ch <= '9')
00050     {  
00051       milisec = milisec * 10 + *ch - '0';
00052       ch++;
00053     }
00054     time += milisec;
00055   }
00056   
00057   return time / mp3::frametime;  
00058 }    
00059 
00060 int Conv::dB2Gain(const char *gainstr)
00061 {
00062   double dB;
00063   
00064   //FIXME: What is a simple portable C++ way to convert a string to number?
00065   (std::stringstream(gainstr)) >> dB; //Brackets must be here to compile in GCC!
00066   
00067   return int(dB / 1.5 + 0.5); //1.5dB is one MP3 unit
00068 }

Generated on Wed Sep 6 00:17:57 2006 for Kraken by  doxygen 1.4.4