00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00038 #include <math.h>
00039 #include <string.h>
00040
00041 #include "splt.h"
00042
00044 long splt_co_convert_to_hundreths(const char *s)
00045 {
00046 long minutes = 0, seconds = 0, hundredths = 0, i = 0;
00047
00048 for(i=0; i< strlen(s); i++)
00049 {
00050 if ((s[i]<0x30 || s[i] > 0x39) && (s[i]!=':'))
00051 {
00052 return -1;
00053 }
00054 }
00055
00056 if (sscanf(s, "%ld:%ld:%ld", &minutes, &seconds, &hundredths) < 2)
00057 {
00058 return -1;
00059 }
00060
00061 if ((minutes < 0) || (seconds < 0) || (hundredths < 0))
00062 {
00063 return -1;
00064 }
00065
00066 if ((seconds > 59) || (hundredths > 99))
00067 {
00068 return -1;
00069 }
00070
00071 if (s[strlen(s)-2]==':')
00072 {
00073 hundredths *= 10;
00074 }
00075
00076 long hun = hundredths;
00077 hun += (minutes * 60 + seconds) * 100;
00078
00079 return hun;
00080 }
00081
00083 float splt_co_convert_to_dB(double input)
00084 {
00085 float level;
00086 if (input <= 0.0)
00087 {
00088 level = -96.0;
00089 }
00090 else
00091 {
00092 level = 20 * log10(input);
00093 }
00094
00095 return level;
00096 }
00097
00099 double splt_co_convert_from_dB(float input)
00100 {
00101 double amp;
00102 if (input <- 96.0)
00103 {
00104 amp = 0.0;
00105 }
00106 else
00107 {
00108 amp = pow(10.0, input / 20.0);
00109 }
00110
00111 return amp;
00112 }
00113
00115 void splt_co_get_mins_secs_hundr(long split_hundr, long *mins, long *secs, long *hundr)
00116 {
00117 long h = split_hundr % 100;
00118 long split_hundr_without_h = split_hundr / 100;
00119 long m = split_hundr_without_h / 60;
00120 long s = split_hundr_without_h % 60;
00121 if (mins)
00122 {
00123 *mins = m;
00124 }
00125 if (secs)
00126 {
00127 *secs = s;
00128 }
00129 if (hundr)
00130 {
00131 *hundr = h;
00132 }
00133 }
00134
00136 long splt_co_time_to_long(double time)
00137 {
00138 return (long) (time * 100.0);
00139 }
00140
00142 long splt_co_time_to_long_ceil(double time)
00143 {
00144 return (long) ceil(time * 100);
00145 }
00146