Changeset 245
- Timestamp:
- 04/20/08 22:36:32
- Files:
-
- trunk/src/swft/swft_import_mp3.cpp (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/swft/swft_import_mp3.cpp
r232 r245 9 9 #define TMP_STRLEN 0xff 10 10 11 #define ERROR_NO_MP3 -1 12 #define ERROR_WRONG_SAMPLING_RATE -2 13 11 14 const int mp3SamplesPerFrame = 1152; 12 15 const int mp3Bitrates[] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}; … … 26 29 int getFrameSize( const unsigned char* data, int size, int pos ) { 27 30 if( pos + 2 >= size ) { 28 return -1;31 return ERROR_NO_MP3; 29 32 } 30 33 … … 37 40 //layer == 1 --> Layer 3 38 41 if( mpegVersion != 3 || layer != 1) { 39 return -1;42 return ERROR_NO_MP3; 40 43 } 41 44 … … 48 51 //this seems to be the only common sampling rate in flash and mp3 49 52 if( samplingRate != 0 ) { 50 return -1;53 return ERROR_WRONG_SAMPLING_RATE; 51 54 } 52 55 … … 62 65 int stereo; 63 66 bool validMP3; 67 bool wrongSamplingRate; 64 68 }; 65 69 … … 68 72 info.stereo = 0; 69 73 info.validMP3 = true; 74 info.wrongSamplingRate = false; 70 75 int pos = 0; 71 76 bool first = true; … … 85 90 info.frames++; 86 91 } else { 87 info.validMP3 = false; 92 if ( frameSize == ERROR_WRONG_SAMPLING_RATE ) { 93 info.wrongSamplingRate = true; 94 } else { 95 info.validMP3 = false; 96 } 88 97 return; 89 98 } 90 99 } 100 101 //no frames found -> no valid mp3 102 info.validMP3 = false; 91 103 } 92 104 … … 145 157 size = filestat.st_size; 146 158 147 // flash requires a initial latency value in front of the mp3 data159 // flash requires an initial latency value in front of the mp3 data 148 160 // TODO: check the meaning of this value and set it correctly 149 161 data = new unsigned char[size + 2]; … … 170 182 } 171 183 184 if( info.wrongSamplingRate ) { 185 fprintf(stderr,"WARNING: MP3 file %s has a wrong sampling rate (not 44.1kHz)\n", filename ); 186 goto fail; 187 } 188 172 189 xmlSetProp( node, (const xmlChar *)"format", (const xmlChar *)"2" ); //MP3 173 190 xmlSetProp( node, (const xmlChar *)"rate", (const xmlChar *)"3" ); 174 xmlSetProp( node, (const xmlChar *)"is16bit", (const xmlChar *)"1" ); //MP3 is al lways 16bit191 xmlSetProp( node, (const xmlChar *)"is16bit", (const xmlChar *)"1" ); //MP3 is always 16bit 175 192 snprintf(tmp,TMP_STRLEN,"%i", info.stereo); 176 193 xmlSetProp( node, (const xmlChar *)"stereo", (const xmlChar *)&tmp ); 177 snprintf(tmp,TMP_STRLEN,"%i", info.frames * 1152); // Each frame has 1152 samples.194 snprintf(tmp,TMP_STRLEN,"%i", info.frames * 1152); //each frame has 1152 samples 178 195 xmlSetProp( node, (const xmlChar *)"samples", (const xmlChar *)&tmp ); 179 196
