Example #1
0
        private void EnsureInitialized()
        {
            if (!this.initialized)
            {
                this.handle = FLAC__stream_encoder_new();
                if (this.handle == IntPtr.Zero)
                {
                    throw new FlacException("Error allocating encoder");
                }

                if (!FLAC__stream_encoder_set_channels(this.handle, pcm.ChannelCount))
                {
                    throw new FlacException("Error setting channels");
                }
                if (!FLAC__stream_encoder_set_bits_per_sample(this.handle, pcm.BitsPerSample))
                {
                    throw new FlacException("Error setting bits per sample");
                }
                if (!FLAC__stream_encoder_set_sample_rate(this.handle, pcm.SampleRate))
                {
                    throw new FlacException("Error setting sample rate");
                }
                if (this.finalSampleCount != 0)
                {
                    if (!FLAC__stream_encoder_set_total_samples_estimate(this.handle, this.finalSampleCount))
                    {
                        throw new FlacException("Error setting total samples estimate");
                    }
                }
                if (!FLAC__stream_encoder_set_compression_level(this.handle, this.compressionLevel))
                {
                    throw new FlacException("Error setting compression level");
                }

                this.internalWriteCallback = this.WriteCallback;
                this.internalSeekCallback  = this.SeekCallback;
                this.internalTellCallback  = this.TellCallback;

                if (FLAC__stream_encoder_init_stream(this.handle, this.internalWriteCallback, this.internalSeekCallback, this.internalTellCallback, null, IntPtr.Zero) != 0)
                {
                    throw new FlacException("Error initializing encoder");
                }

                this.initialized = true;
            }
        }
Example #2
0
 internal static extern FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(IntPtr encoder,
                                                                                       FLAC__StreamEncoderWriteCallback write_callback,
                                                                                       FLAC__StreamEncoderSeekCallback seek_callback,
                                                                                       FLAC__StreamEncoderTellCallback tell_callback,
                                                                                       FLAC__StreamEncoderMetadataCallback metadata_callback,
                                                                                       void *client_data);
Example #3
0
 private static extern int FLAC__stream_encoder_init_stream(IntPtr encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, IntPtr client_data);
        private void EnsureInitialized()
        {
            if (!this.initialized)
            {
                this.handle = FLAC__stream_encoder_new();
                if (this.handle == IntPtr.Zero)
                {
                    throw new FlacException("Error allocating encoder");
                }

                if (!FLAC__stream_encoder_set_channels(this.handle, pcm.ChannelCount))
                {
                    throw new FlacException("Error setting channels");
                }
                if (!FLAC__stream_encoder_set_bits_per_sample(this.handle, pcm.BitsPerSample))
                {
                    throw new FlacException("Error setting bits per sample");
                }
                if (!FLAC__stream_encoder_set_sample_rate(this.handle, pcm.SampleRate))
                {
                    throw new FlacException("Error setting sample rate");
                }
                if (this.finalSampleCount != 0)
                {
                    if (!FLAC__stream_encoder_set_total_samples_estimate(this.handle, this.finalSampleCount))
                    {
                        throw new FlacException("Error setting total samples estimate");
                    }
                }
                if (!FLAC__stream_encoder_set_compression_level(this.handle, this.compressionLevel))
                {
                    throw new FlacException("Error setting compression level");
                }

                this.internalWriteCallback = this.WriteCallback;
                this.internalSeekCallback = this.SeekCallback;
                this.internalTellCallback = this.TellCallback;

                if (FLAC__stream_encoder_init_stream(this.handle, this.internalWriteCallback, this.internalSeekCallback, this.internalTellCallback, null, IntPtr.Zero) != 0)
                {
                    throw new FlacException("Error initializing encoder");
                }

                this.initialized = true;
            }
        }
 private static extern int FLAC__stream_encoder_init_stream(IntPtr encoder, FLAC__StreamEncoderWriteCallback write_callback, FLAC__StreamEncoderSeekCallback seek_callback, FLAC__StreamEncoderTellCallback tell_callback, FLAC__StreamEncoderMetadataCallback metadata_callback, IntPtr client_data);