ux.Master.Read C# (CSharp) Method

Read() public method

生成された PCM データを読み込みます。
public Read ( float buffer, int offset, int count ) : int
buffer float 格納先のバッファ。
offset int バッファに対するオフセット。
count int 読み込まれる要素数。
return int
        public int Read(float[] buffer, int offset, int count)
        {
            // バッファクリア
            Array.Clear(buffer, offset, count);

            // ハンドルの適用
            this.ApplyHandle();

            // count は バイト数
            // Part.Generate にはサンプル数を与える
            for (int k = 0; k < this.partCount; k++)
            {
                if (!this.parts[k].IsSounding)
                    continue;

                this.parts[k].Generate(count / 2);

                // 波形合成
                for (int i = offset, j = 0; i < count; i++, j++)
                    buffer[i] += this.parts[k].Buffer[j];
            }

            // コンプレッサ増幅度
            float threshold = this.compressorThreshold;
            float ratio = this.compressorRatio;
            float gain = 1.0f / (threshold + (1.0f - threshold) * ratio);
            float upover = threshold * (1.0f - ratio);
            float downover = -threshold * (1.0f - ratio);

            for (int i = offset, length = offset + count; i < length; i++)
            {
                float output = buffer[i] * this.masterVolume * gain;

                if (output == 0.0f)
                    continue;

                // 圧縮
                output =
                    ((output > threshold) ? upover + ratio * output :
                    (output < -threshold) ? downover + ratio * output : output);

                // クリッピングと代入
                buffer[i] = (output > 1.0f) ? 1.0f : (output < -1.0f) ? -1.0f : output;
            }

            return count;
        }