Esempio n. 1
0
        private FlacDecoderWriteStatus WriteCallback(IntPtr decoder, ref FLAC__Frame frame, int **buffer, IntPtr clientData)
        {
            int blocksize = (int)frame.Header.Blocksize;

            if (this.pcm == null)
            {
                this.pcm           = new AudioPCMConfig((int)frame.Header.BitsPerSample, (int)frame.Header.Channels, (int)frame.Header.SampleRate);
                this.decoderLength = FLAC__stream_decoder_get_total_samples(this.handle);
            }

            if (this.audioBuffer == null || this.audioBuffer.Size < blocksize)
            {
                this.audioBuffer = new AudioBuffer(this.pcm, blocksize);
            }

            int channelCount = pcm.ChannelCount;

            for (int i = 0; i < channelCount; ++i)
            {
                fixed(int *sampleBufferPtr = this.audioBuffer.Samples)
                {
                    int *source    = buffer[i];
                    int *sourceEnd = source + blocksize;

                    int *sampleBufferPtrCopy = sampleBufferPtr + i;

                    while (source != sourceEnd)
                    {
                        *sampleBufferPtrCopy = *source;

                        ++source;
                        sampleBufferPtrCopy += channelCount;
                    }
                }
            }

            this.audioBuffer.Length = blocksize;
            this.audioBufferOffset  = 0;
            this.decoderPosition   += blocksize;

            this.audioBuffer.Prepare(this.audioBuffer.Samples, this.audioBuffer.Length);

            return(FlacDecoderWriteStatus.Continue);
        }
        private FlacDecoderWriteStatus WriteCallback(IntPtr decoder, ref FLAC__Frame frame, int** buffer, IntPtr clientData)
        {
            int blocksize = (int)frame.Header.Blocksize;

            if (this.pcm == null)
            {
                this.pcm = new AudioPCMConfig((int)frame.Header.BitsPerSample, (int)frame.Header.Channels, (int)frame.Header.SampleRate);
                this.decoderLength = FLAC__stream_decoder_get_total_samples(this.handle);
            }

            if (this.audioBuffer == null || this.audioBuffer.Size < blocksize)
            {
                this.audioBuffer = new AudioBuffer(this.pcm, blocksize);
            }

            int channelCount = pcm.ChannelCount;
            for (int i = 0; i < channelCount; ++i)
            {
                fixed (int* sampleBufferPtr = this.audioBuffer.Samples)
                {
                    int* source = buffer[i];
                    int* sourceEnd = source + blocksize;

                    int* sampleBufferPtrCopy = sampleBufferPtr + i;

                    while (source != sourceEnd)
                    {
                        *sampleBufferPtrCopy = *source;

                        ++source;
                        sampleBufferPtrCopy += channelCount;
                    }
                }
            }

            this.audioBuffer.Length = blocksize;
            this.audioBufferOffset = 0;
            this.decoderPosition += blocksize;

            this.audioBuffer.Prepare(this.audioBuffer.Samples, this.audioBuffer.Length);

            return FlacDecoderWriteStatus.Continue;
        }