Example #1
0
/* DEPRECATED. same as lame_set_decode_on_the_fly() &&
   lame_set_findReplayGain() */
int
lame_set_ReplayGain_decode( lame_global_flags*  gfp,
                           int                 arg )
{
    if( lame_set_decode_on_the_fly(gfp, arg) < 0 ||
        lame_set_findReplayGain(gfp, arg) < 0)
	return -1;
    else 
        return 0;
}
Example #2
0
int mp3_encode(int fd_in, int fd_out) {

    lame_global_flags *gfp;
    uint32_t i, j, k, count;
    int16_t *b0 = 0, *b1 = 0;
    unsigned char *c;
    int ret;
	
	/* calculate data size*/
	k = (uint32_t) lseek(fd_in, 0, SEEK_CUR);
	i = (uint32_t) lseek(fd_in, 0, SEEK_END);
	lseek(fd_in, k, SEEK_SET);
	i -= k;
	k = 0;

	gfp = lame_init();
	lame_set_errorf(gfp,lame_error_handler);
	lame_set_debugf(gfp,lame_error_handler);
	lame_set_msgf(gfp,lame_error_handler);
	lame_set_num_channels(gfp,2);
	lame_set_in_samplerate(gfp,8000);
#if 0
	lame_set_brate(gfp,64); /* compress 1:4 */
	lame_set_mode(gfp,0);   /* mode = stereo */
	lame_set_quality(gfp,2);   /* 2=high  5 = medium  7=low */
#else
	lame_set_quality(gfp,5);   /* 2=high  5 = medium  7=low */
	lame_set_mode(gfp,3);   /* mode = mono */
	if(lame_get_VBR(gfp) == vbr_off) lame_set_VBR(gfp, vbr_default);
	lame_set_VBR_quality(gfp, 7.0);
	lame_set_findReplayGain(gfp, 0);
	lame_set_bWriteVbrTag(gfp, 1);
	lame_set_out_samplerate(gfp,11025);
	/*   lame_set_num_samples(gfp,i/2); */
#endif
	if(lame_init_params(gfp) < 0) {
	     log_err("encode: failed to init lame");
	     return 0;
	}

#define CHSZ (512*1024)
#define OCHSZ (5*(CHSZ/8)+7200)

	b0 = (int16_t *) malloc(OCHSZ);
	b1 = (int16_t *) malloc(CHSZ);
	if(!b0 || !b1) {
	     log_err("encode: out of memory");
	     if(b0) free(b0);
	     if(b1) free(b1);
             return 0;
	}

	do {
	    ret = 0; j = 0; count = 0;
	    for(c = (unsigned char*) b1; count < CHSZ; c += ret) {
		j = (k + RSZ > i) ? i - k : RSZ;
		ret = read(fd_in,c,j);
		if(ret < 0) break;
		k += ret; count += ret;
		if(k == i) break;
	    }
	    if(ret < 0) break;
	    if(count) {
		ret = lame_encode_buffer(gfp,b1,b1,count/2,(unsigned char *)b0,OCHSZ);
		if(ret < 0) break;
		c = (unsigned char *) b0;
		count = ret;
		for(j = 0; j < count; j += RSZ, c += ret) {
		     ret = (j + RSZ > count) ? count - j : RSZ;
		     write(fd_out,c,ret);
		}
	    }
	} while(k < i);

	k = (uint32_t) lame_encode_flush(gfp,(unsigned char *)b0,OCHSZ);
	if(k) write(fd_out,b0,k);

	k = lame_get_lametag_frame(gfp,(unsigned char *)b0,OCHSZ);
	if(k > 0) write(fd_out,b0,k);

	lame_close(gfp);
	free(b0);
	free(b1);

     return 1;	
}
Example #3
0
/* DEPRECATED. same as lame_set_findReplayGain() */
int
lame_set_ReplayGain_input( lame_global_flags*  gfp,
                           int                 arg )
{
    return lame_set_findReplayGain(gfp, arg);
}