int lame_encode_finish(lame_global_flags *gfp,char *mp3buffer, int mp3buffer_size) { int imp3,mp3count,mp3buffer_size_remaining; short int buffer[2][1152]; memset((char *)buffer,0,sizeof(buffer)); mp3count = 0; while (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; imp3=lame_encode(gfp,buffer,mp3buffer,mp3buffer_size_remaining); if (imp3 == -1) { /* fatel error: mp3buffer too small */ desalloc_buffer(&bs); /* Deallocate all buffers */ return -1; } mp3buffer += imp3; mp3count += imp3; mf_samples_to_encode -= gfp->framesize; } gfp->frameNum--; if (!gfp->gtkflag && !gfp->silent) { timestatus(gfp->out_samplerate,gfp->frameNum,gfp->totalframes,gfp->framesize); #ifdef BRHIST if (disp_brhist) { brhist_add_count(); brhist_disp(); brhist_disp_total(gfp); } #endif fprintf(stderr,"\n"); fflush(stderr); } III_FlushBitstream(); mp3buffer_size_remaining = mp3buffer_size - mp3count; /* if user specifed buffer size = 0, dont check size */ if (mp3buffer_size == 0) mp3buffer_size_remaining=0; imp3= copy_buffer(mp3buffer,mp3buffer_size_remaining,&bs); if (imp3 == -1) { /* fatel error: mp3buffer too small */ desalloc_buffer(&bs); /* Deallocate all buffers */ return -1; } mp3count += imp3; desalloc_buffer(&bs); /* Deallocate all buffers */ return mp3count; }
/*close the device containing the bit stream after a write process*/ void close_bit_stream_w (Bit_stream_struc * bs) { putbits (bs, 0, 7); empty_buffer (bs, bs->buf_byte_idx + 1); fclose (bs->pt); desalloc_buffer (bs); }
void close_bit_stream_r(Bit_stream_struc *bs) { fclose(bs->pt); desalloc_buffer(bs); }