コード例 #1
0
ファイル: RollingPCMBuffer.cs プロジェクト: zetaPRIME/xybrid
        public void Add(PCMBuffer buffer)
        {
            if (buffer.Channels != channels) throw new ArgumentException("Wrong number of channels");

            int length = buffer.SampleLength;
            int pos = 0;

            if (last == null) AddSegment();

            while (pos < length) {
                for (int ch = 0; ch < channels; ch++) last.data[ch, samplesWritten] = buffer[ch, pos];
                pos++;
                samplesWritten++;
                if (samplesWritten == segmentLength) {
                    AddSegment();
                    samplesWritten = 0;
                }
            }
        }
コード例 #2
0
ファイル: PCMBuffer.cs プロジェクト: zetaPRIME/xybrid
        public static PCMBuffer operator *(PCMBuffer pcm, double mult)
        {
            if (mult == 1.0) return pcm;
            if (mult == 0.0) {
                PCMBuffer zb = new PCMBuffer(pcm.sampleRate);
                //double[] silence = new double[pcm.SampleLength];
                foreach (double[] c in pcm.data) zb.data.Add(new double[pcm.SampleLength]);
                return zb;
            }

            PCMBuffer b = new PCMBuffer(pcm.sampleRate);
            foreach (double[] ch in pcm.data) {
                List<double> nc = new List<double>();
                for (int i = 0; i < ch.Length; i++) nc.Add(ch[i] * mult);
                b.data.Add(nc.ToArray());
            }

            return pcm;
        }
コード例 #3
0
ファイル: PCMBuffer.cs プロジェクト: zetaPRIME/xybrid
        public PCMBuffer Delay(int samples)
        {
            double[] silence = new double[samples];

            PCMBuffer b = new PCMBuffer(sampleRate);
            b.data = new List<double[]>();

            for (int c = 0; c < data.Count; c++) b.data.Add(silence.Concat(data[c]).ToArray());
            b.pad();

            return b;
        }
コード例 #4
0
ファイル: PCMBuffer.cs プロジェクト: zetaPRIME/xybrid
        public static PCMBuffer operator +(PCMBuffer left, PCMBuffer right)
        {
            int sampleRate = Math.Max(left.sampleRate, right.sampleRate);
            if (sampleRate != -1 && left.sampleRate != right.sampleRate) throw new NotSupportedException("Sample rates unmatched");

            int chdiff = Math.Abs(left.data.Count - right.data.Count);
            if (chdiff == 0) {
                List<List<double>> fdata = new List<List<double>>();
                int length = 0;
                int ch = left.data.Count;
                for (int i = 0; i < ch; i++) {
                    fdata.Add(new List<double>());
                    if (left.data[i].Length > length) length = left.data[i].Length;
                    if (right.data[i].Length > length) length = right.data[i].Length;
                }
                for (int c = 0; c < ch; c++) {
                    double res = 0;
                    for (int i = 0; i < length; i++) {
                        if (left.data[c].Length > i) res += left.data[c][i];
                        if (right.data[c].Length > i) res += right.data[c][i];
                        fdata[c].Add(res);
                    }
                }
                PCMBuffer b = new PCMBuffer(sampleRate);
                b.data = new List<double[]>();
                foreach (List<double> cht in fdata) b.data.Add(cht.ToArray());
                return b;
            }
            else if (left.data.Count < 3 && right.data.Count < 3) {
                return (left.asStereo() + right.asStereo());
            }
            else {
                throw new NotSupportedException("Addition of PCMBuffers of differing channel counts only supported for stereo+mono");
            }
        }