[Flac-dev] Storing FLAC in Matroska

Jory jcsston at ToughGuy.net
Wed Jul 9 00:09:12 PDT 2003


Nevermind I got it working :)
I needed to byte-swap the output

----- Original Message -----
From: "Jory" <jcsston at ToughGuy.net>
To: <flac-dev at lists.sourceforge.net>
Cc: "Jory" <jcsston at ToughGuy.net>
Sent: Tuesday, July 08, 2003 10:59 PM
Subject: Re: [Flac-dev] Storing FLAC in Matroska


> First, Thank you for your answers.
>
> I using the following code to try simply decode a flac file and write the
> decoded data raw PCM file. The resulting file is just noise and pops, so
is
> the decoded data in a different format than PCM?
>
> struct flacData {
>  FILE *inputFile;
>  FILE *outputFile;
>  char *filename;
> };
>
> FLAC__StreamDecoderReadStatus flac_DecoderReadCallback(const
> FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void
> *client_data)
> {
>  flacData *ourData = (flacData *)client_data;
>
>  *bytes = fread((void *)buffer, 1, *bytes, ourData->inputFile);
>
>  return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
> };
>
> FLAC__StreamDecoderWriteStatus flac_DecoderWriteCallback(const
> FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32
> *const buffer[], void *client_data)
> {
>  flacData *ourData = (flacData *)client_data;
>
>  for(int current_sample = 0; current_sample < frame->header.blocksize;
> current_sample++)
>  {
>   for(int channel = 0; channel < frame->header.channels; channel++)
>   {
>    fwrite((void *)&buffer[channel][current_sample], 1, 1,
> ourData->outputFile);
>   }
>  }
>
>  return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
> };
>
> void flac_DecoderMetaDataCallback(const FLAC__StreamDecoder *decoder,
const
> FLAC__StreamMetadata *metadata, void *client_data)
> {
>  flacData *ourData = (flacData *)client_data;
>
> };
>
> void flac_DecoderErrorCallback(const FLAC__StreamDecoder *decoder,
> FLAC__StreamDecoderErrorStatus status, void *client_data)
> {
>  flacData *ourData = (flacData *)client_data;
>
> };
>
> int main(int argc, char* argv[])
> {
>  //Create the FLAC stream decoder
>  FLAC__StreamDecoder *flac_file = FLAC__stream_decoder_new();
>
>  //Setup the callbacks
>  FLAC__stream_decoder_set_read_callback(flac_file,
> (FLAC__StreamDecoderReadCallback)flac_DecoderReadCallback);
>  FLAC__stream_decoder_set_write_callback(flac_file,
> (FLAC__StreamDecoderWriteCallback)flac_DecoderWriteCallback);
>  FLAC__stream_decoder_set_metadata_callback(flac_file,
> (FLAC__StreamDecoderMetadataCallback)flac_DecoderMetaDataCallback);
>  FLAC__stream_decoder_set_error_callback(flac_file,
> (FLAC__StreamDecoderErrorCallback)flac_DecoderErrorCallback);
>
>  //Set our data up
>  flacData *flacObjData = new flacData;
>  flacObjData->filename = "C:\\My Music\\44.1Hz Stereo PCM_5.flac";
>  flacObjData->inputFile = fopen(flacObjData->filename, "rb");
>  flacObjData->outputFile = fopen("test.raw", "wb");
>  FLAC__stream_decoder_set_client_data(flac_file, (void *)flacObjData);
>
>  //Init the decoder
>  FLAC__stream_decoder_init(flac_file);
>  //Start decoding, the callbacks do all the work from here
>  FLAC__stream_decoder_process_until_end_of_stream(flac_file);
>  return 0;
> }
>
> ----- Original Message -----
> From: "Josh Coalson" <xflac at yahoo.com>
> To: "Jory" <jcsston at ToughGuy.net>; <flac-dev at lists.sourceforge.net>
> Cc: <Matroska-devel at lists.matroska.org>
> Sent: Tuesday, July 08, 2003 5:02 PM
> Subject: Re: [Flac-dev] Storing FLAC in Matroska
>
>
> > --- Jory <jcsston at ToughGuy.net> wrote:
> > > Hello,
> > >     I'm looking into storing FLAC audio in Matroska and I have a few
> > > questions.
> > >
> > > 1. Can I use libflac to extract the compressed frames?
> > > Or will I need to write up a simple file parser?
> >
> > I'm not sure I understand your question, but one unfortunate
> > fact about native FLAC is that you cannot discover the frame
> > boundaries without decoding.  But you can decode a file, and
> > after each frame get the current stream position from the
> > decoder, which will tell you where to chop the original stream.
> > See the source for metaflac for an example, where it uses this
> > method to add seekpoints to a seektable.
> >
> > > 2. What is required to decode the frames?
> > > From the docs I understand that you need the FRAME and you may need
> > > the
> > > METADATA_BLOCK.
> >
> > If it is in the streamable subset, you need only what's in the
> > frames.  If not, you may need some numbers from the STREAMINFO
> > metadata block.  Search for 'subset' on
> > http://flac.sourceforge.net/format.html
> >
> > Josh
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!
> > http://sbc.yahoo.com
>
>






More information about the Flac-dev mailing list