NVorbis.VorbisReader.ReadSamples C# (CSharp) Method

ReadSamples() public method

Reads decoded samples from the current logical stream
public ReadSamples ( float buffer, int offset, int count ) : int
buffer float The buffer to write the samples to
offset int The offset into the buffer to write the samples to
count int The number of samples to write
return int
        public int ReadSamples(float[] buffer, int offset, int count)
        {
            if (offset < 0) throw new ArgumentOutOfRangeException("offset");
            if (count < 0 || offset + count > buffer.Length) throw new ArgumentOutOfRangeException("count");

            count = ActiveDecoder.ReadSamples(buffer, offset, count);

            if (ClipSamples)
            {
                var decoder = _decoders[_streamIdx];
                for (int i = 0; i < count; i++, offset++)
                {
                    buffer[offset] = Utils.ClipValue(buffer[offset], ref decoder._clipped);
                }
            }

            return count;
        }

Usage Example

Ejemplo n.º 1
0
    public void Mix(float[] data, int channels, float volume)
    {
        if (reader.SampleRate == 44100 && reader.Channels == channels)
        {
            float[] ndata = new float[data.Length];
            int     read  = reader.ReadSamples(ndata, 0, ndata.Length);
            for (int i = 0; i < read; i++)
            {
                float b = ndata[i] * volume;
                float a = data[i];
                data[i] = a + b - a * b;
            }
        }
        else if (reader.SampleRate == 44100)
        {
            float[] ndata = new float[data.Length / channels * reader.Channels];
            int     read  = reader.ReadSamples(ndata, 0, ndata.Length) / reader.Channels;

            for (int i = 0; i < read; i++)
            {
                for (int c = 0; c < channels; c++)
                {
                    float b = ndata[i * reader.Channels + c % reader.Channels] * volume;
                    float a = data[i * channels + c];
                    data[i * channels + c] = a + b - a * b;
                }
            }
        }
        else
        {
            Debug.Log("OnlyPlay 44100,now rate is" + reader.SampleRate);
        }
    }
All Usage Examples Of NVorbis.VorbisReader::ReadSamples