FLAC::Encoder::Stream == "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA"



  • Ich möchte CDDA mit flac komprimieren und in eine Datei schreiben,
    aber der encoder bricht immer mit folgendem Fehler ab
    enc.get_state() == "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA"
    get_verify_decoder_state() == "FLAC__STREAM_DECODER_READ_FRAME"

    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();
    
    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();
    		}
    
    };
    


  • Dieser Thread wurde von Moderator/in SeppJ aus dem Forum C++ (auch C++0x) in das Forum Rund um die Programmierung verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.


Anmelden zum Antworten