Exemplo n.º 1
0
// Returns 0 if successful
// Returns -1 if unsuccessful
static int init_header_info(twolame_options * glopts)
{
    frame_header *header = &glopts->header;

    /* use the options to create header info structure */
    header->lay = 2;
    header->error_protection = glopts->error_protection;
    header->version = glopts->version;

    // Convert the sampling frequency to the required index
    header->samplerate_idx = twolame_get_samplerate_index(glopts->samplerate_out);
    if (header->samplerate_idx < 0) {
        fprintf(stderr, "Not a valid samplerate: %i\n", glopts->samplerate_out);
        return -1;
    }

    // Convert the bitrate to the an index
    if (glopts->freeformat)
        header->bitrate_index = 0;
    else
    {
        header->bitrate_index = twolame_get_bitrate_index(glopts->bitrate, header->version);
        if (header->bitrate_index < 0) {
            fprintf(stderr, "Not a valid bitrate (%i) for MPEG version '%s'\n", glopts->bitrate,
                    twolame_mpeg_version_name(glopts->version));
            return -1;
        }
    }
    if (glopts->vbr && glopts->vbr_max_bitrate > 0)
    {
        /* user required vbr and a specified max bitrate */
        /* convert max VBR bitrate to an index */
        glopts->vbr_upper_index = twolame_get_bitrate_index(glopts->vbr_max_bitrate, header->version);
        if (glopts->vbr_upper_index < 0) {
            fprintf(stderr, "Not a valid max VBR bitrate for this version: %i\n",
                    glopts->vbr_max_bitrate);
            return -1;
        }
    }
    // Copy accross the other settings
    header->padding = 0; /* when requested, padding will be evaluated later for this frame */
    header->private_extension = glopts->private_extension;
    header->mode = glopts->mode;
    header->mode_ext = 0;
    header->copyright = glopts->copyright;
    header->original = glopts->original;
    header->emphasis = glopts->emphasis;

    return 0;
}
Exemplo n.º 2
0
// Returns 0 if successful
// Returns -1 if unsuccessful
static int init_header_info( twolame_options *glopts ) {
	frame_header *header = &glopts->header;
	
	/* use the options to create header info structure */
	header->lay = 2;
	header->error_protection = glopts->error_protection;
	header->version = glopts->version;
	
	// Convert the sampling frequency to the required index
	header->samplerate_idx = twolame_get_samplerate_index( glopts->samplerate_out ); 
	if (header->samplerate_idx < 0) {
		fprintf(stdout,"Not a valid samplerate: %i\n",glopts->samplerate_out );
		return -1;
	}
	
	// Convert the bitrate to the an index	
	header->bitrate_index = twolame_get_bitrate_index(glopts->bitrate, header->version);
	if (header->bitrate_index < 0) {
		fprintf(stdout,"Not a valid bitrate (%i) for MPEG version '%s'\n", glopts->bitrate, 
			twolame_mpeg_version_name(glopts->version));
		return -1;
	}
		
	// Convert the max VBR bitrate to the an index	
	glopts->vbr_upper_index = twolame_get_bitrate_index(glopts->vbr_max_bitrate, header->version);
	if (glopts->vbr_upper_index < 0) {
		fprintf(stdout,"Not a valid max VBR bitrate for this version: %i\n",glopts->vbr_max_bitrate);
		return -1;
	}
	
	// Copy accross the other settings	
	header->padding = glopts->padding;
	header->private_bit = glopts->private_bit;
	header->mode = glopts->mode;
	header->mode_ext = 0;
	header->copyright = glopts->copyright;
	header->original = glopts->original;
	header->emphasis = glopts->emphasis;
	
	return 0;
}