[Flac-dev] Getting subframe type=verbatim on 16 bit files
James Smith
jsmith at landmarkdigital.com
Thu Sep 7 08:01:21 PDT 2006
Here's how I set up the data for processing:
// For moving data into 32 bit shape
uint8_t *buffer8 = NULL;
uint16_t *buffer16 = NULL;
uint32_t *buffer32 = NULL;
unsigned sample32;
unsigned sample, channel;
uint32_t bitsPerSample = this->get_bits_per_sample();
numFrames = inData.GetSize();
numChannels = this->get_channels();
// How big is our sample that we want to give to FLACC?
// bitsPerSample is 8,16,24,32
// So 8 = no change for numFrames
// 16 = half it
// 24,32 = 1/4 the needs..
if (bitsPerSample == 16)
numFrames = numFrames / 2;
else if (bitsPerSample > 16)
numFrames = numFrames / 4;
// if stereo then spread data over both channels and not just one!
if (numChannels == 2) numFrames = numFrames / 2;
// buffer for FLAC use
flacBuffer = (int32_t **)calloc(numChannels, sizeof(int32_t *));
if (flacBuffer == NULL)
return false;
// channel buffer to zero 1 or 2 (stereo)
for(channel = 0; channel < numChannels; ++channel)
{
flacBuffer[channel] = NULL;
}
// set up buffers for channels
for(channel = 0; channel < numChannels; ++channel)
{
flacBuffer[channel] = (int32_t*)calloc(numFrames, sizeof(int32_t));
if (flacBuffer[channel] == NULL)
return false;
}
// uint32_t tempjunk;
// Need to get our pcm Data into 32 bit shape and with with channels...
// See how sample32 is the index into the 32 bit array
// while the sample index can handle things when stereo (i.e. 2
channels) occurs.
switch(bitsPerSample)
{
case SIXTEEN_BITS:
buffer16 = (uint16_t*)inData.GetData(); // so we index thru out
data in 16 byte chunks
for(sample = sample32 = 0; sample32 < numFrames; sample32++)
{
for(channel = 0; channel < numChannels; channel++, sample++)
{
flacBuffer[channel][sample32] =
(uint32_t)(uint16_t)buffer16[sample];
}
}
break;
..........
}
set_total_samples_estimate (numFrames); // note we are doing this
before the init function is called!
return true;
}
On 9/6/06 8:28 PM, "Josh Coalson" <xflac at yahoo.com> wrote:
> looks fine, I would suspect how the PCM sample are formatted
> and sent to process(), could you show that part of the code?
>
> Josh
>
>
> --- James Smith <jsmith at landmarkdigital.com> wrote:
>
>>
>> I'm using libFLACC++ and libFLAC and I think that I'm using the calls
>> in the
>> typical order (see code below). But every monoe or stereo file that
>> I send
>> thru I get files that are the same sze as the orginal wave files.
>>
>> Doing a flac -a on the flac files I see that I get:
>>
>> frame=9 blocksize=4608 sample_rate=8000 channels=1
>> channel_assignment=INDEPENDENT
>> subframe=0 wasted_bits=0 type=VERBATIM
>> .......
>>
>> Any idea why/ where I have goofed?
>>
>> Thanks,
>>
>> James
>>
>>
>> Code snippet:
>> ===================================================
>> FlacEncoder flacCompressor;
>> bool setValue = false;
>>
>> // set up regular parameters
>> setValue = flacCompressor.set_channels (numChannels);
>> setValue = flacCompressor.set_bits_per_sample (bitsPerSample);
>> setValue = flacCompressor.set_sample_rate (sampleRate);
>> setValue = flacCompressor.set_blocksize(4608);
>> setValue = flacCompressor.set_qlp_coeff_precision (0);
>> setValue = flacCompressor.set_min_residual_partition_order (3);
>> setValue = flacCompressor.set_max_residual_partition_order (3);
>> setValue = flacCompressor.set_max_lpc_order (8);
>> setValue = flacCompressor.set_rice_parameter_search_dist(0);
>> setValue = flacCompressor.set_do_exhaustive_model_search(false);
>> setValue = flacCompressor.set_do_escape_coding(false);
>>
>>
>> if (numChannels > 1)
>> {
>> setValue = flacCompressor.set_do_mid_side_stereo(true);
>> setValue = flacCompressor.set_loose_mid_side_stereo(true);
>> }
>>
>> if (!flacCompressor.SetupInboundBuffer(pcmData)) return false;
>>
>>
>> FLAC__StreamMetadata padding;
>> FLAC__StreamMetadata *metadata [1];
>>
>> // stuff some pading for metadata
>> padding.type = FLAC__METADATA_TYPE_PADDING;
>> padding.is_last = 0;
>> padding.length = 40;
>> metadata[0] = &padding;
>> setValue = flacCompressor.set_metadata(metadata, 1);
>>
>> FlacEncoder::Stream::State flacState = flacCompressor.init();
>>
>> /*
>> // verify that the values are correct...they are fine, why still
>> verbatim?
>> int i;
>> i = flacCompressor.get_channels ();
>> i = flacCompressor.get_bits_per_sample ();
>> i = flacCompressor.get_sample_rate ();
>> i = flacCompressor.get_blocksize();
>> i = flacCompressor.get_qlp_coeff_precision (); // default=0 so
>> encoding
>> software picks the best
>> i = flacCompressor.get_min_residual_partition_order ();
>> i = flacCompressor.get_max_residual_partition_order (); //
>> Had tried
>> 0,6 now try 3,3
>> i = flacCompressor.get_max_lpc_order ();
>> setValue = flacCompressor.get_do_mid_side_stereo();
>> setValue = flacCompressor.get_loose_mid_side_stereo();
>> */
>>
>> // is this state okay?
>> if (flacState != FLAC__STREAM_ENCODER_OK)
>> return false; // bad settings for doing this compression so
>> quit...
>>
>> // shoot the final data buffer to the encoder....
>> // we would have called process_interleaved if we had not created
>> an
>> array per channel above...
>> if (!flacCompressor.DoProcess())
>> {
>> flacState = flacCompressor.get_state();
>> return false;
>> }
>>
>> flacState = flacCompressor.get_state();
>> flacCompressor.finish();
>>
>> flacCompressor.Release();
>>
>> return true;
>> }
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
********************************************
This message is intended only for the use of the Addressee and
may contain information that is PRIVILEGED and CONFIDENTIAL.
If you are not the intended recipient, you are hereby notified
that any dissemination of this communication is strictly prohibited.
If you have received this communication in error, please erase
all copies of the message and its attachments and notify us
immediately.
Thank you.
********************************************
More information about the Flac-dev
mailing list