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;
00016 std::stringstream stream;
00017
00018
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')
00029 {
00030 time = time * 10 + *ch - '0';
00031 ch++;
00032 }
00033
00034 if(*ch++ == ':')
00035 {
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++ == '.')
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
00065 (std::stringstream(gainstr)) >> dB;
00066
00067 return int(dB / 1.5 + 0.5);
00068 }