?? lame.c
字號:
n_out=Min(gfp->framesize,nsamples); n_in = n_out; memcpy( (char *) &mfbuf[ch][gfc->mf_size],(char *)in_buffer[ch],sizeof(short int)*n_out); } in_buffer[ch] += n_in; } nsamples -= n_in; gfc->mf_size += n_out; assert(gfc->mf_size<=MFSIZE); gfc->mf_samples_to_encode += n_out; if (gfc->mf_size >= mf_needed) { /* encode the frame. */ ret = lame_encode_frame(gfp,mfbuf[0],mfbuf[1],mp3buf,mp3buf_size); if (ret < 0) return ret; mp3buf += ret; mp3size += ret; /* shift out old samples */ gfc->mf_size -= gfp->framesize; gfc->mf_samples_to_encode -= gfp->framesize; for (ch=0; ch<gfc->stereo; ch++) for (i=0; i<gfc->mf_size; i++) mfbuf[ch][i]=mfbuf[ch][i+gfp->framesize]; } } assert(nsamples==0); return mp3size;}int lame_encode_buffer_interleaved(lame_global_flags *gfp, short int buffer[], int nsamples, char *mp3buf, int mp3buf_size){ int mp3size=0,ret=0,i,ch,mf_needed; lame_internal_flags *gfc=gfp->internal_flags; short int *mfbuf[2]; if (!gfc->lame_init_params_init) return -3; mfbuf[0]=gfc->mfbuf[0]; mfbuf[1]=gfc->mfbuf[1]; /* some sanity checks */ assert(ENCDELAY>=MDCTDELAY); assert(BLKSIZE-FFTOFFSET >= 0); mf_needed = BLKSIZE+gfp->framesize-FFTOFFSET; assert(MFSIZE>=mf_needed); if (gfp->num_channels == 1) { return lame_encode_buffer(gfp,buffer, NULL ,nsamples,mp3buf,mp3buf_size); } if (gfc->resample_ratio!=1) { short int *buffer_l; short int *buffer_r; buffer_l=malloc(sizeof(short int)*nsamples); buffer_r=malloc(sizeof(short int)*nsamples); if (buffer_l == NULL || buffer_r == NULL) { return -2; } for (i=0; i<nsamples; i++) { buffer_l[i]=buffer[2*i]; buffer_r[i]=buffer[2*i+1]; } ret = lame_encode_buffer(gfp,buffer_l,buffer_r,nsamples,mp3buf,mp3buf_size); free(buffer_l); free(buffer_r); return ret; } if (gfp->num_channels==2 && gfc->stereo==1) { /* downsample to mono */ for (i=0; i<nsamples; ++i) { buffer[2*i]=((int)buffer[2*i]+(int)buffer[2*i+1])/2; buffer[2*i+1]=0; } } while (nsamples > 0) { int n_out; /* copy in new samples */ n_out = Min(gfp->framesize,nsamples); for (i=0; i<n_out; ++i) { mfbuf[0][gfc->mf_size+i]=buffer[2*i]; mfbuf[1][gfc->mf_size+i]=buffer[2*i+1]; } buffer += 2*n_out; nsamples -= n_out; gfc->mf_size += n_out; assert(gfc->mf_size<=MFSIZE); gfc->mf_samples_to_encode += n_out; if (gfc->mf_size >= mf_needed) { /* encode the frame */ ret = lame_encode_frame(gfp,mfbuf[0],mfbuf[1],mp3buf,mp3buf_size); if (ret < 0) { /* fatel error: mp3buffer was too small */ return ret; } mp3buf += ret; mp3size += ret; /* shift out old samples */ gfc->mf_size -= gfp->framesize; gfc->mf_samples_to_encode -= gfp->framesize; for (ch=0; ch<gfc->stereo; ch++) for (i=0; i<gfc->mf_size; i++) mfbuf[ch][i]=mfbuf[ch][i+gfp->framesize]; } } assert(nsamples==0); return mp3size;}/* old LAME interface. use lame_encode_buffer instead */int lame_encode(lame_global_flags *gfp, short int in_buffer[2][1152],char *mp3buf,int size){ int imp3; lame_internal_flags *gfc=gfp->internal_flags; if (!gfc->lame_init_params_init) return -3; imp3= lame_encode_buffer(gfp,in_buffer[0],in_buffer[1],gfp->framesize,mp3buf,size); return imp3;}/*****************************************************************//* flush internal mp3 buffers, *//*****************************************************************/int lame_encode_finish(lame_global_flags *gfp,char *mp3buffer, int mp3buffer_size){ int imp3=0,mp3count,mp3buffer_size_remaining; short int buffer[2][1152]; lame_internal_flags *gfc=gfp->internal_flags; memset((char *)buffer,0,sizeof(buffer)); mp3count = 0; while (gfc->mf_samples_to_encode > 0) { mp3buffer_size_remaining = mp3buffer_size - mp3count; /* if user specifed buffer size = 0, dont check size */ if (mp3buffer_size == 0) mp3buffer_size_remaining=0; /* send in a frame of 0 padding until all internal sample buffers flushed */ imp3=lame_encode_buffer(gfp,buffer[0],buffer[1],gfp->framesize,mp3buffer,mp3buffer_size_remaining); /* dont count the above padding: */ gfc->mf_samples_to_encode -= gfp->framesize; if (imp3 < 0) { /* some type of fatel error */ freegfc(gfc); return imp3; } mp3buffer += imp3; mp3count += imp3; } gfp->frameNum--; if (!gfp->gtkflag && !gfp->silent) { timestatus(gfp->out_samplerate,gfp->frameNum,gfp->totalframes,gfp->framesize); if (gfp->brhist_disp) { brhist_disp(gfp->totalframes); brhist_disp_total(gfp); } timestatus_finish(); } mp3buffer_size_remaining = mp3buffer_size - mp3count; /* if user specifed buffer size = 0, dont check size */ if (mp3buffer_size == 0) mp3buffer_size_remaining=0; if (gfp->ogg) {#ifdef HAVEVORBIS /* ogg related stuff */ imp3 = lame_encode_ogg_finish(gfp,mp3buffer,mp3buffer_size_remaining);#endif }else{ /* mp3 related stuff. bit buffer might still contain some data */ flush_bitstream(gfp); imp3= copy_buffer(mp3buffer,mp3buffer_size_remaining,&gfc->bs); } if (imp3 < 0) { freegfc(gfc); return imp3; } mp3count += imp3; freegfc(gfc); return mp3count;}/*****************************************************************//* write VBR Xing header, and ID3 tag, if asked for *//*****************************************************************/void lame_mp3_tags(lame_global_flags *gfp){ if (gfp->bWriteVbrTag) { /* Calculate relative quality of VBR stream * 0=best, 100=worst */ int nQuality=gfp->VBR_q*100/9; /* Write Xing header again */ PutVbrTag(gfp,gfp->outPath,nQuality); } /* write an ID3 tag */ if(gfp->id3tag_used) { id3_buildtag(&gfp->id3tag); id3_writetag(gfp->outPath, &gfp->id3tag); }}void lame_version(lame_global_flags *gfp,char *ostring) { strncpy(ostring,get_lame_version(),20);}/* initialize mp3 encoder */int lame_init(lame_global_flags *gfp){ lame_internal_flags *gfc; /* * Disable floating point exepctions */#ifdef __FreeBSD__# include <floatingpoint.h> { /* seet floating point mask to the Linux default */ fp_except_t mask; mask=fpgetmask(); /* if bit is set, we get SIGFPE on that error! */ fpsetmask(mask & ~(FP_X_INV|FP_X_DZ)); /* DEBUGF("FreeBSD mask is 0x%x\n",mask); */ }#endif#if defined(__riscos__) && !defined(ABORTFP) /* Disable FPE's under RISC OS */ /* if bit is set, we disable trapping that error! */ /* _FPE_IVO : invalid operation */ /* _FPE_DVZ : divide by zero */ /* _FPE_OFL : overflow */ /* _FPE_UFL : underflow */ /* _FPE_INX : inexact */ DisableFPETraps( _FPE_IVO | _FPE_DVZ | _FPE_OFL );#endif /* * Debugging stuff * The default is to ignore FPE's, unless compiled with -DABORTFP * so add code below to ENABLE FPE's. */#if defined(ABORTFP) #if defined(_MSC_VER) { #include <float.h> unsigned int mask; mask=_controlfp( 0, 0 ); mask&=~(_EM_OVERFLOW|_EM_UNDERFLOW|_EM_ZERODIVIDE|_EM_INVALID); mask=_controlfp( mask, _MCW_EM ); }#elif defined(__CYGWIN__)# define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))# define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))# define _EM_INEXACT 0x00000001 /* inexact (precision) */# define _EM_UNDERFLOW 0x00000002 /* underflow */# define _EM_OVERFLOW 0x00000004 /* overflow */# define _EM_ZERODIVIDE 0x00000008 /* zero divide */# define _EM_INVALID 0x00000010 /* invalid */ { unsigned int mask; _FPU_GETCW(mask); /* Set the FPU control word to abort on most FPEs */ mask &= ~(_EM_UNDERFLOW | _EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID); _FPU_SETCW(mask); }# elif (defined(__linux__) || defined(__FreeBSD__)) {# include <fpu_control.h># ifndef _FPU_GETCW# define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))# endif# ifndef _FPU_SETCW# define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))# endif unsigned int mask; _FPU_GETCW(mask); /* Set the Linux mask to abort on most FPE's */ /* if bit is set, we _mask_ SIGFPE on that error! */ /* mask &= ~( _FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM );*/ mask &= ~( _FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM ); _FPU_SETCW(mask); }#endif#endif /* ABORTFP */ memset(gfp,0,sizeof(lame_global_flags)); if (NULL==(gfp->internal_flags = malloc(sizeof(lame_internal_flags)))) return -1; gfc=(lame_internal_flags *) gfp->internal_flags; memset(gfc,0,sizeof(lame_internal_flags)); /* Global flags. set defaults here */ gfp->mode = MPG_MD_JOINT_STEREO; gfp->mode_fixed=0; gfp->force_ms=0; gfp->brate=0; gfp->copyright=0; gfp->original=1; gfp->extension=0; gfp->error_protection=0; gfp->emphasis=0; gfp->in_samplerate=1000*44.1; gfp->out_samplerate=0; gfp->num_channels=2; gfp->num_samples=MAX_U_32_NUM; gfp->allow_diff_short=0; gfp->ATHonly=0; gfp->noATH=0; gfp->bWriteVbrTag=1; gfp->cwlimit=0; gfp->disable_reservoir=0; gfp->experimentalX = 0; gfp->experimentalY = 0; gfp->experimentalZ = 0; gfp->gtkflag=0; gfp->quality=5; gfp->input_format=sf_unknown; gfp->lowpassfreq=0; gfp->highpassfreq=0; gfp->lowpasswidth=-1; gfp->highpasswidth=-1; gfp->no_short_blocks=0; gfp->padding_type=2; gfp->swapbytes=0; gfp->silent=1; gfp->VBR=vbr_off; gfp->VBR_q=4; gfp->VBR_mean_bitrate_kbps=128; gfp->VBR_min_bitrate_kbps=0; gfp->VBR_max_bitrate_kbps=0; gfp->VBR_hard_min=0; gfc->pcmbitwidth = 16; gfc->resample_ratio=1; gfc->lowpass_band=32; gfc->highpass_band=-1; gfc->VBR_min_bitrate=1; gfc->VBR_max_bitrate=13; gfc->OldValue[0]=180; gfc->OldValue[1]=180; gfc->CurrentStep=4; gfc->masking_lower=1; return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -