Changeset 245

Show
Ignore:
Timestamp:
04/20/08 22:36:32
Author:
ralf
Message:

improved mp3 import errormessages

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/swft/swft_import_mp3.cpp

    r232 r245  
    99#define TMP_STRLEN 0xff 
    1010 
     11#define ERROR_NO_MP3              -1 
     12#define ERROR_WRONG_SAMPLING_RATE -2 
     13 
    1114const int mp3SamplesPerFrame = 1152; 
    1215const int mp3Bitrates[] = {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320}; 
     
    2629int getFrameSize( const unsigned char* data, int size, int pos ) { 
    2730        if( pos + 2 >= size ) { 
    28                 return -1
     31                return ERROR_NO_MP3
    2932        } 
    3033 
     
    3740        //layer == 1 --> Layer 3 
    3841        if( mpegVersion != 3 || layer != 1) { 
    39                 return -1
     42                return ERROR_NO_MP3
    4043        } 
    4144 
     
    4851        //this seems to be the only common sampling rate in flash and mp3 
    4952        if( samplingRate != 0 ) { 
    50                 return -1
     53                return ERROR_WRONG_SAMPLING_RATE
    5154        } 
    5255 
     
    6265        int stereo; 
    6366        bool validMP3; 
     67        bool wrongSamplingRate; 
    6468}; 
    6569 
     
    6872        info.stereo = 0; 
    6973        info.validMP3 = true; 
     74        info.wrongSamplingRate = false; 
    7075        int pos = 0; 
    7176        bool first = true; 
     
    8590                        info.frames++; 
    8691                } else { 
    87                         info.validMP3 = false; 
     92                        if ( frameSize == ERROR_WRONG_SAMPLING_RATE ) { 
     93                                info.wrongSamplingRate = true; 
     94                        } else { 
     95                                info.validMP3 = false; 
     96                        } 
    8897                        return; 
    8998                } 
    9099        } 
     100 
     101        //no frames found -> no valid mp3 
     102        info.validMP3 = false; 
    91103} 
    92104 
     
    145157        size = filestat.st_size; 
    146158         
    147         // flash requires a initial latency value in front of the mp3 data 
     159        // flash requires an initial latency value in front of the mp3 data 
    148160        // TODO: check the meaning of this value and set it correctly 
    149161        data = new unsigned char[size + 2]; 
     
    170182        } 
    171183 
     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 
    172189        xmlSetProp( node, (const xmlChar *)"format", (const xmlChar *)"2" ); //MP3 
    173190        xmlSetProp( node, (const xmlChar *)"rate", (const xmlChar *)"3" ); 
    174         xmlSetProp( node, (const xmlChar *)"is16bit", (const xmlChar *)"1" ); //MP3 is allways 16bit 
     191        xmlSetProp( node, (const xmlChar *)"is16bit", (const xmlChar *)"1" ); //MP3 is always 16bit 
    175192        snprintf(tmp,TMP_STRLEN,"%i", info.stereo); 
    176193        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 
    178195        xmlSetProp( node, (const xmlChar *)"samples", (const xmlChar *)&tmp ); 
    179196