[Flac-dev] FLAC::Encoder::Stream == "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA"

Anon Ymous w536h45eui7r6mjhugzt4rf3t5ezu at googlemail.com
Wed Sep 28 16:46:24 PDT 2011


I'm using flac-1.2.1 and visual studio 2010 on windows xp sp3
and I want to compress raw CDDA with the stream encoder to a file.

But I just can't get the flac encoder to work,
the encoder always returns an error
enc.get_state() == "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA"
get_verify_decoder_state() == "FLAC__STREAM_DECODER_READ_FRAME"



this is the code I have now

/*****************************************************************************/
    FLAC__StreamEncoderInitStatus init_status;
    TMyFlacEncoder                enc;
    bool                          ok = true;

    unsigned int sample_size        = 4; //2 * (16 / 8); 2 channels * (16
bits / 8) bytes
    unsigned int samples_per_sector = disc.getBytesPerSector(trackNum) /
sample_size / 2 /*channels*/;
    unsigned int total_samples      = trackLength * samples_per_sector;


    // compress
    ok &= enc.set_verify(true);
    ok &= enc.set_channels       (    2); //      2 channels
    ok &= enc.set_bits_per_sample(   16); //     16 bits
    ok &= enc.set_sample_rate    (44100); // 44.100 Hz
    ok &= enc.set_compression_level((FCompressionStrength > 8) ? 8 :
FCompressionStrength);
    ok &= enc.set_total_samples_estimate(total_samples);

    enc.setOutFile(&file);


    /* initialize encoder */
    init_status = enc.init();
    if( (!ok) || (init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK)) {
        return false;
    }



    /* read sectors from disc and feed to encoder */
    for (unsigned int i = 0; i < trackLength; ++i) {

        disc.seekTrack(i, trackNum, false);

        ok = enc.process_interleaved((FLAC__int32*)disc.getBuffer(),
samples_per_sector);

        FProgressCur++;

        if (!ok || !progressCallback()) {
            cout << "Flac error: " << enc.get_state().as_cstring() << endl;
            cout << "Flac verify state: " <<
enc.get_verify_decoder_state().as_cstring() << endl;
            return false;
        }

    }

    ok &= enc.finish();
/*****************************************************************************/

disc.seekTrack, seeks the disc in LBA mode
disc.getBuffer, returns the buffer pointer to the cd sectors of the last
seek, this is 2352 bytes in length for CDDA



and the encoder child class from FLAC::Encoder::Stream

/*****************************************************************************/
class TMyFlacEncoder: public FLAC::Encoder::Stream {
    protected:
        TMyFileAccess  *FFile; // the file we are writing to
        long long      FFlacOffset;


        virtual FLAC__StreamEncoderReadStatus read_callback (FLAC__byte
buffer[], size_t *bytes)
        {
            if(*bytes > 0) {
                *bytes = FFile->Read(buffer, sizeof(FLAC__byte), *bytes);
                if(FFile->Error())
                    return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
                else if(*bytes == 0)
                    return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
                else
                    return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
            }
            else
                return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
        }


        virtual FLAC__StreamEncoderWriteStatus write_callback (const
FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame)
        {

            if ( FFile->Write((unsigned char*)buffer, 1, bytes) != bytes ) {
                return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
            }

            return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
        }

        virtual FLAC__StreamEncoderSeekStatus seek_callback (FLAC__uint64
absolute_byte_offset)
        {
            if (FFile->Seek(absolute_byte_offset + FFlacOffset, SEEK_SET) <
0 ) {
                return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
            }

            return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
        }

        virtual FLAC__StreamEncoderTellStatus tell_callback (FLAC__uint64
*absolute_byte_offset)
        {
            long long pos = FFile->Tell() - FFlacOffset;
            *absolute_byte_offset = (FLAC__uint64)pos;

            if( pos < 0 ) {
                return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
            }

            return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
        }


    public:
        TMyFlacEncoder(): FLAC::Encoder::Stream() {

            FFile = NULL;

        }

        // you need to call this before starting the compression
        void setOutFile(TMyFileAccess *file)
        {
            FFile = file;
            FFlacOffset = file->Tell();
        }


};
/*****************************************************************************/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20110929/98a988c0/attachment.htm 


More information about the Flac-dev mailing list