int lame_main(lame_t gf, int argc, char **argv) { char inPath[PATH_MAX + 1]; char outPath[PATH_MAX + 1]; char nogapdir[PATH_MAX + 1]; /* support for "nogap" encoding of up to 200 .wav files */ #define MAX_NOGAP 200 int nogapout = 0; int max_nogap = MAX_NOGAP; char nogap_inPath_[MAX_NOGAP][PATH_MAX + 1]; char *nogap_inPath[MAX_NOGAP]; int ret; int i; FILE *outf; lame_set_msgf(gf, &frontend_msgf); lame_set_errorf(gf, &frontend_errorf); lame_set_debugf(gf, &frontend_debugf); if (argc <= 1) { usage(stderr, argv[0]); /* no command-line args, print usage, exit */ return 1; } memset(inPath, 0, sizeof(inPath)); memset(nogap_inPath_, 0, sizeof(nogap_inPath_)); for (i = 0; i < MAX_NOGAP; ++i) { nogap_inPath[i] = &nogap_inPath_[i][0]; } /* parse the command line arguments, setting various flags in the * struct 'gf'. If you want to parse your own arguments, * or call libmp3lame from a program which uses a GUI to set arguments, * skip this call and set the values of interest in the gf struct. * (see the file API and lame.h for documentation about these parameters) */ ret = parse_args(gf, argc, argv, inPath, outPath, nogap_inPath, &max_nogap); if (ret < 0) { return ret == -2 ? 0 : 1; } if (global_ui_config.update_interval < 0.) global_ui_config.update_interval = 2.; if (outPath[0] != '\0' && max_nogap > 0) { strncpy(nogapdir, outPath, PATH_MAX + 1); nogapout = 1; } /* initialize input file. This also sets samplerate and as much other data on the input file as available in the headers */ if (max_nogap > 0) { /* for nogap encoding of multiple input files, it is not possible to * specify the output file name, only an optional output directory. */ parse_nogap_filenames(nogapout, nogap_inPath[0], outPath, nogapdir); outf = init_files(gf, nogap_inPath[0], outPath); } else { outf = init_files(gf, inPath, outPath); } if (outf == NULL) { return -1; } /* turn off automatic writing of ID3 tag data into mp3 stream * we have to call it before 'lame_init_params', because that * function would spit out ID3v2 tag data. */ lame_set_write_id3tag_automatic(gf, 0); /* Now that all the options are set, lame needs to analyze them and * set some more internal options and check for problems */ ret = lame_init_params(gf); if (ret < 0) { if (ret == -1) { display_bitrates(stderr); } error_printf("fatal error during initialization\n"); return ret; } if (global_ui_config.silent > 0) { global_ui_config.brhist = 0; /* turn off VBR histogram */ } if (lame_get_decode_only(gf)) { /* decode an mp3 file to a .wav */ ret = lame_decoder(gf, outf, inPath, outPath); } else if (max_nogap == 0) { /* encode a single input file */ ret = lame_encoder(gf, outf, 0, inPath, outPath); } else { /* encode multiple input files using nogap option */ for (i = 0; i < max_nogap; ++i) { int use_flush_nogap = (i != (max_nogap - 1)); if (i > 0) { parse_nogap_filenames(nogapout, nogap_inPath[i], outPath, nogapdir); /* note: if init_files changes anything, like samplerate, num_channels, etc, we are screwed */ outf = init_files(gf, nogap_inPath[i], outPath); /* reinitialize bitstream for next encoding. this is normally done * by lame_init_params(), but we cannot call that routine twice */ lame_init_bitstream(gf); } lame_set_nogap_total(gf, max_nogap); lame_set_nogap_currentindex(gf, i); ret = lame_encoder(gf, outf, use_flush_nogap, nogap_inPath[i], outPath); } } return ret; }
int main(int argc, char **argv) { int ret; lame_global_flags *gf; char outPath[PATH_MAX + 1]; char nogapdir[PATH_MAX + 1]; char inPath[PATH_MAX + 1]; /* support for "nogap" encoding of up to 200 .wav files */ #define MAX_NOGAP 200 int nogapout = 0; int max_nogap = MAX_NOGAP; char *nogap_inPath[MAX_NOGAP]; int i; FILE *outf; #if macintosh argc = ccommand(&argv); #endif #if defined(_WIN32) /* set affinity back to all CPUs. Fix for EAC/lame on SMP systems from "Todd Richmond" <*****@*****.**> */ typedef BOOL (WINAPI *SPAMFunc)(HANDLE, DWORD); SPAMFunc func; SYSTEM_INFO si; if ((func = (SPAMFunc)GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "SetProcessAffinityMask")) != NULL) { GetSystemInfo(&si); func(GetCurrentProcess(), si.dwActiveProcessorMask); } #endif #ifdef __EMX__ /* This gives wildcard expansion on Non-POSIX shells with OS/2 */ _wildcard(&argc, &argv); #endif for (i = 0; i < max_nogap; ++i) { nogap_inPath[i] = malloc(PATH_MAX + 1); } memset(inPath, 0, sizeof(inPath)); /* initialize libmp3lame */ input_format = sf_unknown; if (NULL == (gf = lame_init())) { fprintf(stderr, "fatal error during initialization\n"); return 1; } if (argc <= 1) { usage(stderr, argv[0]); /* no command-line args, print usage, exit */ return 1; } /* parse the command line arguments, setting various flags in the * struct 'gf'. If you want to parse your own arguments, * or call libmp3lame from a program which uses a GUI to set arguments, * skip this call and set the values of interest in the gf struct. * (see the file API and lame.h for documentation about these parameters) */ parse_args_from_string(gf, getenv("LAMEOPT"), inPath, outPath); ret = parse_args(gf, argc, argv, inPath, outPath, nogap_inPath, &max_nogap); if (ret < 0) return ret == -2 ? 0 : 1; if (update_interval < 0.) update_interval = 2.; if (outPath[0] != '\0' && max_nogap>0) { strncpy(nogapdir, outPath, PATH_MAX + 1); nogapout = 1; } /* initialize input file. This also sets samplerate and as much other data on the input file as available in the headers */ if (max_nogap > 0) { /* for nogap encoding of multiple input files, it is not possible to * specify the output file name, only an optional output directory. */ parse_nogap_filenames(nogapout,nogap_inPath[0],outPath,nogapdir); outf = init_files(gf, nogap_inPath[0], outPath); } else { outf = init_files(gf, inPath, outPath); } if (outf == NULL) { return -1; } /* Now that all the options are set, lame needs to analyze them and * set some more internal options and check for problems */ i = lame_init_params(gf); if (i < 0) { if (i == -1) { display_bitrates(stderr); } fprintf(stderr, "fatal error during initialization\n"); return i; } if (silent > 0 #ifndef RH_HIST || lame_get_VBR(gf) == vbr_off #endif ) { brhist = 0; /* turn off VBR histogram */ } if (lame_get_decode_only(gf)) { /* decode an mp3 file to a .wav */ if (mp3_delay_set) lame_decoder(gf, outf, mp3_delay, inPath, outPath); else lame_decoder(gf, outf, 0, inPath, outPath); } else { if (max_nogap > 0) { /* * encode multiple input files using nogap option */ for (i = 0; i < max_nogap; ++i) { int use_flush_nogap = (i != (max_nogap - 1)); if (i > 0) { parse_nogap_filenames(nogapout,nogap_inPath[i],outPath,nogapdir); /* note: if init_files changes anything, like samplerate, num_channels, etc, we are screwed */ outf = init_files(gf, nogap_inPath[i], outPath); } brhist_init_package(gf); lame_set_nogap_total(gf, max_nogap); lame_set_nogap_currentindex(gf, i); ret = lame_encoder(gf, outf, use_flush_nogap, nogap_inPath[i], outPath); if (silent<=0) print_lame_tag_leading_info(gf); lame_mp3_tags_fid(gf, outf); /* add VBR tags to mp3 file */ if (silent<=0) print_trailing_info(gf); fclose(outf); /* close the output file */ close_infile(); /* close the input file */ /* reinitialize bitstream for next encoding. this is normally done * by lame_init_params(), but we cannot call that routine twice */ if (use_flush_nogap) lame_init_bitstream(gf); } lame_close(gf); } else { /* * encode a single input file */ brhist_init_package(gf); ret = lame_encoder(gf, outf, 0, inPath, outPath); if (silent<=0) print_lame_tag_leading_info(gf); lame_mp3_tags_fid(gf, outf); /* add VBR tags to mp3 file */ if (silent<=0) print_trailing_info(gf); fclose(outf); /* close the output file */ close_infile(); /* close the input file */ lame_close(gf); } } return ret; }
int lame_main(lame_t gf, int argc, char **argv) { unsigned char mp3buffer[LAME_MAXMP3BUFFER]; char inPath[PATH_MAX + 1]; char outPath[PATH_MAX + 1]; int Buffer[2][1152]; int maxx = 0, tmpx = 0; int ret; int wavsamples; int mp3bytes; FILE *outf; char ip[16]; unsigned int port = 5004; unsigned int ttl = 2; char dummy; if (argc <= 2) { console_printf("Encode (via LAME) to mp3 with RTP streaming of the output\n" "\n" " mp3rtp ip[:port[:ttl]] [lame encoding options] infile outfile\n" "\n" " examples:\n" " arecord -b 16 -s 22050 -w | ./mp3rtp 224.17.23.42:5004:2 -b 56 - /dev/null\n" " arecord -b 16 -s 44100 -w | ./mp3rtp 10.1.1.42 -V2 -b128 -B256 - my_mp3file.mp3\n" "\n"); return 1; } switch (sscanf(argv[1], "%11[.0-9]:%u:%u%c", ip, &port, &ttl, &dummy)) { case 1: case 2: case 3: break; default: error_printf("Illegal destination selector '%s', must be ip[:port[:ttl]]\n", argv[1]); return -1; } rtp_initialization(); if (rtp_socket(ip, port, ttl)) { rtp_deinitialization(); error_printf("fatal error during initialization\n"); return 1; } lame_set_errorf(gf, &frontend_errorf); lame_set_debugf(gf, &frontend_debugf); lame_set_msgf(gf, &frontend_msgf); /* Remove the argumets that are rtp related, and then * parse the command line arguments, setting various flags in the * struct pointed to by 'gf'. If you want to parse your own arguments, * or call libmp3lame from a program which uses a GUI to set arguments, * skip this call and set the values of interest in the gf struct. * (see lame.h for documentation about these parameters) */ { int i; int argc_mod = argc-1; /* leaving out exactly one argument */ char** argv_mod = calloc(argc_mod, sizeof(char*)); argv_mod[0] = argv[0]; for (i = 2; i < argc; ++i) { /* leaving out argument number 1, parsed above */ argv_mod[i-1] = argv[i]; } parse_args(gf, argc_mod, argv_mod, inPath, outPath, NULL, NULL); free(argv_mod); } /* open the output file. Filename parsed into gf.inPath */ if (0 == strcmp(outPath, "-")) { lame_set_stream_binary_mode(outf = stdout); } else { if ((outf = lame_fopen(outPath, "wb+")) == NULL) { rtp_deinitialization(); error_printf("Could not create \"%s\".\n", outPath); return 1; } } /* open the wav/aiff/raw pcm or mp3 input file. This call will * open the file with name gf.inFile, try to parse the headers and * set gf.samplerate, gf.num_channels, gf.num_samples. * if you want to do your own file input, skip this call and set * these values yourself. */ if (init_infile(gf, inPath) < 0) { rtp_deinitialization(); fclose(outf); error_printf("Can't init infile '%s'\n", inPath); return 1; } /* Now that all the options are set, lame needs to analyze them and * set some more options */ ret = lame_init_params(gf); if (ret < 0) { if (ret == -1) display_bitrates(stderr); rtp_deinitialization(); fclose(outf); close_infile(); error_printf("fatal error during initialization\n"); return -1; } lame_print_config(gf); /* print useful information about options being used */ if (global_ui_config.update_interval < 0.) global_ui_config.update_interval = 2.; /* encode until we hit EOF */ while ((wavsamples = get_audio(gf, Buffer)) > 0) { /* read in 'wavsamples' samples */ levelmessage(maxvalue(Buffer), &maxx, &tmpx); mp3bytes = lame_encode_buffer_int(gf, /* encode the frame */ Buffer[0], Buffer[1], wavsamples, mp3buffer, sizeof(mp3buffer)); rtp_output(mp3buffer, mp3bytes); /* write MP3 output to RTP port */ fwrite(mp3buffer, 1, mp3bytes, outf); /* write the MP3 output to file */ } mp3bytes = lame_encode_flush(gf, /* may return one or more mp3 frame */ mp3buffer, sizeof(mp3buffer)); rtp_output(mp3buffer, mp3bytes); /* write MP3 output to RTP port */ fwrite(mp3buffer, 1, mp3bytes, outf); /* write the MP3 output to file */ lame_mp3_tags_fid(gf, outf); /* add VBR tags to mp3 file */ rtp_deinitialization(); fclose(outf); close_infile(); /* close the sound input file */ return 0; }
/******************************************************************** * initialize internal params based on data in gf * (globalflags struct filled in by calling program) * ********************************************************************/ void lame_init_params(lame_global_flags *gfp) { int i; FLOAT compression_ratio; memset(&bs, 0, sizeof(Bit_stream_struc)); memset(&l3_side,0x00,sizeof(III_side_info_t)); gfp->frameNum=0; InitFormatBitStream(); if (gfp->num_channels==1) { gfp->mode = MPG_MD_MONO; } gfp->stereo=2; if (gfp->mode == MPG_MD_MONO) gfp->stereo=1; #ifdef BRHIST if (gfp->silent) { disp_brhist=0; /* turn of VBR historgram */ } if (!gfp->VBR) { disp_brhist=0; /* turn of VBR historgram */ } #endif /* set the output sampling rate, and resample options if necessary samplerate = input sample rate resamplerate = ouput sample rate */ if (gfp->out_samplerate==0) { /* user did not specify output sample rate */ gfp->out_samplerate=gfp->in_samplerate; /* default */ /* if resamplerate is not valid, find a valid value */ if (gfp->out_samplerate>=48000) gfp->out_samplerate=48000; else if (gfp->out_samplerate>=44100) gfp->out_samplerate=44100; else if (gfp->out_samplerate>=32000) gfp->out_samplerate=32000; else if (gfp->out_samplerate>=24000) gfp->out_samplerate=24000; else if (gfp->out_samplerate>=22050) gfp->out_samplerate=22050; else gfp->out_samplerate=16000; if (gfp->brate>0) { /* check if user specified bitrate requires downsampling */ compression_ratio = gfp->out_samplerate*16*gfp->stereo/(1000.0*gfp->brate); if (!gfp->VBR && compression_ratio > 13 ) { /* automatic downsample, if possible */ gfp->out_samplerate = (10*1000.0*gfp->brate)/(16*gfp->stereo); if (gfp->out_samplerate<=16000) gfp->out_samplerate=16000; else if (gfp->out_samplerate<=22050) gfp->out_samplerate=22050; else if (gfp->out_samplerate<=24000) gfp->out_samplerate=24000; else if (gfp->out_samplerate<=32000) gfp->out_samplerate=32000; else if (gfp->out_samplerate<=44100) gfp->out_samplerate=44100; else gfp->out_samplerate=48000; } } } gfp->mode_gr = (gfp->out_samplerate <= 24000) ? 1 : 2; /* mode_gr = 2 */ gfp->encoder_delay = ENCDELAY; gfp->framesize = gfp->mode_gr*576; if (gfp->brate==0) { /* user didn't specify a bitrate, use default */ gfp->brate=128; if (gfp->mode_gr==1) gfp->brate=64; } gfp->resample_ratio=1; if (gfp->out_samplerate != gfp->in_samplerate) gfp->resample_ratio = (FLOAT)gfp->in_samplerate/(FLOAT)gfp->out_samplerate; /* estimate total frames. must be done after setting sampling rate so * we know the framesize. */ gfp->totalframes=0; gfp->totalframes = 2+ gfp->num_samples/(gfp->resample_ratio*gfp->framesize); /* 44.1kHz at 56kbs/channel: compression factor of 12.6 44.1kHz at 64kbs/channel: compression factor of 11.025 44.1kHz at 80kbs/channel: compression factor of 8.82 22.05kHz at 24kbs: 14.7 22.05kHz at 32kbs: 11.025 22.05kHz at 40kbs: 8.82 16kHz at 16kbs: 16.0 16kHz at 24kbs: 10.7 compression_ratio 11 .70? 12 sox resample .66 14.7 sox resample .45 */ if (gfp->brate >= 320) gfp->VBR=0; /* dont bother with VBR at 320kbs */ compression_ratio = gfp->out_samplerate*16*gfp->stereo/(1000.0*gfp->brate); /* for VBR, take a guess at the compression_ratio */ /* VBR_q compression like 0 4.4 320kbs 1 5.4 256kbs 3 7.4 192kbs 4 8.8 160kbs 6 10.4 128kbs */ if (gfp->VBR && compression_ratio>11) { compression_ratio = 4.4 + gfp->VBR_q; } /* At higher quality (lower compression) use STEREO instead of JSTEREO. * (unless the user explicitly specified a mode ) */ if ( (!gfp->mode_fixed) && (gfp->mode !=MPG_MD_MONO)) { if (compression_ratio < 9 ) { gfp->mode = MPG_MD_STEREO; } } /****************************************************************/ /* if a filter has not been enabled, see if we should add one: */ /****************************************************************/ if (gfp->lowpassfreq == 0) { /* If the user has not selected their own filter, add a lowpass * filter based on the compression ratio. Formula based on 44.1 /160 4.4x 44.1 /128 5.5x keep all bands 44.1 /96kbs 7.3x keep band 28 44.1 /80kbs 8.8x keep band 25 44.1khz/64kbs 11x keep band 21 22? 16khz/24kbs 10.7x keep band 21 22kHz/32kbs 11x keep band ? 22kHz/24kbs 14.7x keep band 16 16 16 16x keep band 14 */ /* Should we use some lowpass filters? */ int band = 1+floor(.5 + 14-18*log(compression_ratio/16.0)); if (band < 31) { gfp->lowpass1 = band/31.0; gfp->lowpass2 = band/31.0; } } /****************************************************************/ /* apply user driven filters*/ /****************************************************************/ if ( gfp->highpassfreq > 0 ) { gfp->highpass1 = 2.0*gfp->highpassfreq/gfp->out_samplerate; /* will always be >=0 */ if ( gfp->highpasswidth >= 0 ) { gfp->highpass2 = 2.0*(gfp->highpassfreq+gfp->highpasswidth)/gfp->out_samplerate; } else { /* 15% above on default */ /* gfp->highpass2 = 1.15*2.0*gfp->highpassfreq/gfp->out_samplerate; */ gfp->highpass2 = 1.00*2.0*gfp->highpassfreq/gfp->out_samplerate; } gfp->highpass1 = Min( 1, gfp->highpass1 ); gfp->highpass2 = Min( 1, gfp->highpass2 ); } if ( gfp->lowpassfreq > 0 ) { gfp->lowpass2 = 2.0*gfp->lowpassfreq/gfp->out_samplerate; /* will always be >=0 */ if ( gfp->lowpasswidth >= 0 ) { gfp->lowpass1 = 2.0*(gfp->lowpassfreq-gfp->lowpasswidth)/gfp->out_samplerate; if ( gfp->lowpass1 < 0 ) { /* has to be >= 0 */ gfp->lowpass1 = 0; } } else { /* 15% below on default */ /* gfp->lowpass1 = 0.85*2.0*gfp->lowpassfreq/gfp->out_samplerate; */ gfp->lowpass1 = 1.00*2.0*gfp->lowpassfreq/gfp->out_samplerate; } gfp->lowpass1 = Min( 1, gfp->lowpass1 ); gfp->lowpass2 = Min( 1, gfp->lowpass2 ); } /***************************************************************/ /* compute info needed for polyphase filter */ /***************************************************************/ if (gfp->filter_type==0) { int band,maxband,minband; FLOAT8 amp,freq; if (gfp->lowpass1 > 0) { minband=999; maxband=-1; for (band=0; band <=31 ; ++band) { freq = band/31.0; amp = 1; /* this band and above will be zeroed: */ if (freq >= gfp->lowpass2) { gfp->lowpass_band= Min(gfp->lowpass_band,band); amp=0; } if (gfp->lowpass1 < freq && freq < gfp->lowpass2) { minband = Min(minband,band); maxband = Max(maxband,band); amp = cos((PI/2)*(gfp->lowpass1-freq)/(gfp->lowpass2-gfp->lowpass1)); } /* printf("lowpass band=%i amp=%f \n",band,amp);*/ } /* compute the *actual* transition band implemented by the polyphase filter */ if (minband==999) gfp->lowpass1 = (gfp->lowpass_band-.75)/31.0; else gfp->lowpass1 = (minband-.75)/31.0; gfp->lowpass2 = gfp->lowpass_band/31.0; } /* make sure highpass filter is within 90% of whan the effective highpass * frequency will be */ if (gfp->highpass2 > 0) if (gfp->highpass2 < .9*(.75/31.0) ) { gfp->highpass1=0; gfp->highpass2=0; fprintf(stderr,"Warning: highpass filter disabled. highpass frequency to small\n"); } if (gfp->highpass2 > 0) { minband=999; maxband=-1; for (band=0; band <=31; ++band) { freq = band/31.0; amp = 1; /* this band and below will be zereod */ if (freq <= gfp->highpass1) { gfp->highpass_band = Max(gfp->highpass_band,band); amp=0; } if (gfp->highpass1 < freq && freq < gfp->highpass2) { minband = Min(minband,band); maxband = Max(maxband,band); amp = cos((PI/2)*(gfp->highpass2-freq)/(gfp->highpass2-gfp->highpass1)); } /* printf("highpass band=%i amp=%f \n",band,amp);*/ } /* compute the *actual* transition band implemented by the polyphase filter */ gfp->highpass1 = gfp->highpass_band/31.0; if (maxband==-1) gfp->highpass2 = (gfp->highpass_band+.75)/31.0; else gfp->highpass2 = (maxband+.75)/31.0; } /* printf("lowpass band with amp=0: %i \n",gfp->lowpass_band); printf("highpass band with amp=0: %i \n",gfp->highpass_band); */ } /***************************************************************/ /* compute info needed for FIR filter */ /***************************************************************/ if (gfp->filter_type==1) { } gfp->mode_ext=MPG_MD_LR_LR; gfp->stereo = (gfp->mode == MPG_MD_MONO) ? 1 : 2; gfp->samplerate_index = SmpFrqIndex((long)gfp->out_samplerate, &gfp->version); if( gfp->samplerate_index < 0) { display_bitrates(stderr); exit(1); } if( (gfp->bitrate_index = BitrateIndex(gfp->brate, gfp->version,gfp->out_samplerate)) < 0) { display_bitrates(stderr); exit(1); } /* choose a min/max bitrate for VBR */ if (gfp->VBR) { /* if the user didn't specify VBR_max_bitrate: */ if (0==gfp->VBR_max_bitrate_kbps) { /* default max bitrate is 256kbs */ /* we do not normally allow 320bps frams with VBR, unless: */ gfp->VBR_max_bitrate=13; /* default: allow 256kbs */ if (gfp->VBR_min_bitrate_kbps>=256) gfp->VBR_max_bitrate=14; if (gfp->VBR_q == 0) gfp->VBR_max_bitrate=14; /* allow 320kbs */ if (gfp->VBR_q >= 4) gfp->VBR_max_bitrate=12; /* max = 224kbs */ if (gfp->VBR_q >= 8) gfp->VBR_max_bitrate=9; /* low quality, max = 128kbs */ }else{ if( (gfp->VBR_max_bitrate = BitrateIndex(gfp->VBR_max_bitrate_kbps, gfp->version,gfp->out_samplerate)) < 0) { display_bitrates(stderr); exit(1); } } if (0==gfp->VBR_min_bitrate_kbps) { gfp->VBR_min_bitrate=1; /* 32 kbps */ }else{ if( (gfp->VBR_min_bitrate = BitrateIndex(gfp->VBR_min_bitrate_kbps, gfp->version,gfp->out_samplerate)) < 0) { display_bitrates(stderr); exit(1); } } } if (gfp->VBR) gfp->quality=Min(gfp->quality,2); /* always use quality <=2 with VBR */ /* dont allow forced mid/side stereo for mono output */ if (gfp->mode == MPG_MD_MONO) gfp->force_ms=0; /* Do not write VBR tag if VBR flag is not specified */ if (gfp->VBR==0) gfp->bWriteVbrTag=0; /* some file options not allowed if output is: not specified or stdout */ if (gfp->outPath!=NULL && gfp->outPath[0]=='-' ) { gfp->bWriteVbrTag=0; /* turn off VBR tag */ } if (gfp->outPath==NULL || gfp->outPath[0]=='-' ) { id3tag.used=0; /* turn of id3 tagging */ } if (gfp->gtkflag) { gfp->bWriteVbrTag=0; /* disable Xing VBR tag */ } init_bit_stream_w(&bs); /* set internal feature flags. USER should not access these since * some combinations will produce strange results */ /* no psymodel, no noise shaping */ if (gfp->quality==9) { gfp->filter_type=0; gfp->psymodel=0; gfp->quantization=0; gfp->noise_shaping=0; gfp->noise_shaping_stop=0; gfp->use_best_huffman=0; } if (gfp->quality==8) gfp->quality=7; /* use psymodel (for short block and m/s switching), but no noise shapping */ if (gfp->quality==7) { gfp->filter_type=0; gfp->psymodel=1; gfp->quantization=0; gfp->noise_shaping=0; gfp->noise_shaping_stop=0; gfp->use_best_huffman=0; } if (gfp->quality==6) gfp->quality=5; if (gfp->quality==5) { /* the default */ gfp->filter_type=0; gfp->psymodel=1; gfp->quantization=0; gfp->noise_shaping=1; gfp->noise_shaping_stop=0; gfp->use_best_huffman=0; } if (gfp->quality==4) gfp->quality=2; if (gfp->quality==3) gfp->quality=2; if (gfp->quality==2) { gfp->filter_type=0; gfp->psymodel=1; gfp->quantization=1; gfp->noise_shaping=1; gfp->noise_shaping_stop=0; gfp->use_best_huffman=1; } if (gfp->quality==1) { gfp->filter_type=0; gfp->psymodel=1; gfp->quantization=1; gfp->noise_shaping=1; gfp->noise_shaping_stop=1; gfp->use_best_huffman=1; } if (gfp->quality==0) { /* 0..1 quality */ gfp->filter_type=1; /* not yet coded */ gfp->psymodel=1; gfp->quantization=1; gfp->noise_shaping=3; /* not yet coded */ gfp->noise_shaping_stop=2; /* not yet coded */ gfp->use_best_huffman=2; /* not yet coded */ exit(-99); } for (i = 0; i < SBMAX_l + 1; i++) { scalefac_band.l[i] = sfBandIndex[gfp->samplerate_index + (gfp->version * 3)].l[i]; } for (i = 0; i < SBMAX_s + 1; i++) { scalefac_band.s[i] = sfBandIndex[gfp->samplerate_index + (gfp->version * 3)].s[i]; } if (gfp->bWriteVbrTag) { /* Write initial VBR Header to bitstream */ InitVbrTag(&bs,1-gfp->version,gfp->mode,gfp->samplerate_index); } #ifdef HAVEGTK gtkflag=gfp->gtkflag; #endif #ifdef BRHIST if (gfp->VBR) { if (disp_brhist) brhist_init(gfp,1, 14); } else disp_brhist = 0; #endif return; }