[Flac-dev] Basic Encoder Help
Andrew Gatt
andrew.gatt at cmatic.co.uk
Tue Nov 2 05:04:24 PST 2004
Hello all,
I've been writing a basic encoder using libFLAC++. It seems to work fine, as in the resultant file is playable in any FLAC compatible player, however the compression ratio is very small - the main example being a 60MB file compressing to 54MB, i guess there's an option i've missed, but i cannot track it down. I was hoping someone could point it out for me:
FLAC::Encoder::File flac;
void setup()
{
FLAC__FileEncoderState state;
flac.set_filename(output_filename.c_str());
flac.set_channels (2);
flac.set_bits_per_sample (16);
flac.set_sample_rate (44100);
flac.set_do_exhaustive_model_search(false);
flac.set_do_escape_coding(false);
flac.set_do_mid_side_stereo(true);
flac.set_loose_mid_side_stereo(false);
flac.set_qlp_coeff_precision(0);
flac.set_min_residual_partition_order(3);
flac.set_max_residual_partition_order(3);
flac.set_rice_parameter_search_dist(0);
flac.set_max_lpc_order(8);
state = flac.init();
}
int write(long num_bytes, unsigned char *buffer)
{
int32_t sample[1176]; // sample numbers are set to one frame of a CD
samples = 588; // which contains 588 samples per channel per frame
int j=0;
for (int i=0; i<2352; i+=4) { // Converting unsigned char to signed long
sample[j++] = buffer[i] + (buffer[i+1] << 8);
sample[j++] = buffer[i+2] + (buffer[i+3] << 8);
}
flac.process_interleaved((const FLAC__int32*)&sample[0], samples);
}
void finish()
{
flac.finish();
}
These are actually class members, but i've pulled them out to try and make it easier to spot any mistakes. I've tried to set it up to have an equivalent to quality level 5 on the command line flac utility. I'm pulling the bytes off a CD hence the reason they are in char format when they enter the write loop. The write loop is called for every frame (i've tried changing this - writing to the the process function with a larger buffer, but it doesn't seem to make any difference).
Any ideas anyone?
Thanks
Andrew
More information about the Flac-dev
mailing list