[Flac-dev] trying to write encoder - need help!

Josh Coalson xflac at yahoo.com
Sun Jun 20 14:33:01 PDT 2004


--- Matt Funk <mfunk at telus.net> wrote:
> Hi all,
> 
> I'm attempting to encode raw audio data using libFLAC++. My audio
> data
> is 16 bit, mono, 16000Hz. I set all the appropriate parameters on the
> encoder and then call init().  Everything appears to be ok.
> 
> I don't know how to properly convert from char *data to the
> FLAC__int32
> *[] requested by the process function. I think this is where my
> problem
> is.
> 
> If I call process() like this: 
> 
> FLAC__int32 *samplesArray[1] = { (FLAC__int32 *)data };
> 
> // data size if 4096 bytes
> if (!process(samplesArray, 1024))
> 	die("return false");
> 
> it appears to encode ok, but when I play the flac file, it plays at
> twice the normal speed. I can cheat and tell the encoder that the
> sample
> rate is really 8000 Hz when in reality its 16KHz and it plays ok. 
> 
> So my question is how to convert from char *data to FLAC__int32*
> data?
> I've been looking at encode.c but I'm confused by it (my c skills
> aren't
> fantastic)

if samples are 16bps, why is 'data' a char*, not a short int* or
FLAC__int16* ?

you will first have to convert the 16-bit samples to 32-bit signed.
assuming they are signed short ints (FLAC__int16 *data):

  const unsigned N = 1024;
  FLAC__int32 *samplesArray[1] = { new FLAC__int32[N] };

  for (unsigned i = 0; i < N; i++)
    samplesArray[0][i] = data[i];

  if (!process(samplesArray, 1024))
    die("return false");

  delete [] samplesArray;



		
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail




More information about the Flac-dev mailing list