Ejemplo n.º 1
0
 public virtual void Read(Note[] notes, float[] buffer, int inclusiveFrom, int exclusiveTo, NoteWaveArgs args)
 {
     Debug.Assert(notes != null, "NoteWaveProvider.Read: notes == null");
     foreach (var n in notes)
     {
         n.UpdatePhase(FTime);
     }
 }
Ejemplo n.º 2
0
        public override void Read(Note[] notes, float[] buffer, int inclusiveFrom, int exclusiveTo, NoteWaveArgs args)
        {
            base.Read(notes, buffer, inclusiveFrom, exclusiveTo, args);

            var    count     = exclusiveTo - inclusiveFrom;
            var    count2    = count / 2;
            double startTime = FTime;

            Parallel.For(0, count2, (n) =>
            {
                var time = startTime + n * FTimeDelta;

                SoundPointValue op = new SoundPointValue();

                for (int i = 0; i < notes.Length; i++)
                {
                    op += notes[i].GetValue(time);
                }

                op *= args.MasterVolume;

                var index         = inclusiveFrom + 2 * n;
                buffer[index]     = (float)op.Left;
                buffer[index + 1] = (float)op.Right;
            });

            unsafe
            {
                // Фиксирую указатель на массив
                fixed(float *bf = buffer)
                {
                    // Указатель на начало массива
                    float *f = bf;
                    // Количество итераций - половина размера массива
                    var c = count2;

                    while (c > 0)
                    {
                        // Проверка для правого канала
                        if (*f > args.MaxR)
                        {
                            args.MaxR = *f;
                        }
                        f++;
                        // Проверка для левого канала
                        if (*f > args.MaxL)
                        {
                            args.MaxL = *f;
                        }
                        f++;
                        c--;
                    }
                }
            }

            FTime += count2 * FTimeDelta;
        }
Ejemplo n.º 3
0
        public override void Read(Note[] notes, float[] buffer, int inclusiveFrom, int exclusiveTo, NoteWaveArgs args)
        {
            var s = sw.ElapsedMilliseconds;

            if ((FOldSamplesHash != args.SamplesHash) || (FOldSamplesHash == 0))
            {
                FOldSamplesHash = args.SamplesHash;
                InitSampleArgs(args.Samples);
            }

            Dictionary <int, int> wfIndexDict = new Dictionary <int, int>();

            for (int i = 0; i < args.Samples.Length; i++)
            {
                wfIndexDict.Add(args.Samples[i].Key.GetHashCode(), i);
            }

            base.Read(notes, buffer, inclusiveFrom, exclusiveTo, args);
            int timeChannelsCount = exclusiveTo - inclusiveFrom;

            int nCount = notes.Length;
            int pCount = 0;

            if (nCount > 0)
            {
                pCount = notes[0].Points.Length;
            }

            OpenCLInfo info = new OpenCLInfo()
            {
                startTime    = (float)FTime,
                timeDelta    = (float)FTimeDelta,
                sampleRate   = Format.SampleRate,
                noteCount    = (uint)nCount,
                pointCount   = (uint)pCount,
                masterVolume = (float)args.MasterVolume
            };

            info.inclusiveFrom = (uint)inclusiveFrom;

            OpenCLPointInfo[] points = new OpenCLPointInfo[nCount * pCount];

            OpenCLNote[] envs   = new OpenCLNote[nCount];
            float[]      result = new float[timeChannelsCount];

            int index = 0;

            for (int n = 0; n < nCount; n++)
            {
                for (int p = 0; p < pCount; p++, index++)
                {
                    points[index] = new OpenCLPointInfo()
                    {
                        ampl     = (float)notes[n].Points[p].Volume,
                        freq     = (float)notes[n].Points[p].Frequency,
                        leftPct  = (float)notes[n].Points[p].LeftPct,
                        rightPct = (float)notes[n].Points[p].RightPct,
                        wfIndex  = -1,
                        isMute   = (byte)(notes[n].Points[p].IsMute ? 1 : 0)
                    };
                    if (wfIndexDict.TryGetValue(notes[n].Points[p].Waveform.GetHashCode(), out var wfi))
                    {
                        points[index].wfIndex = wfi;
                    }
                }
                envs[n] = new OpenCLNote()
                {
                    envelope = notes[n].Envelope.GetOpenCL(),
                    volume   = (float)notes[n].Volume
                };
            }

            long br = 0, ar = 0, ac = 0;

            if (nCount * pCount > 0)
            {
                br = sw.ElapsedMilliseconds;

                Run(new OpenCLInfo[] { info }, points, envs, result);

                ar = sw.ElapsedMilliseconds;

                if (App.DebugMode)
                {
                    Debug.WriteLine("");
                }

                for (int i = 0, j = inclusiveFrom; i < result.Length; i++, j++)
                {
                    var fR = result[i];
                    if (fR > args.MaxR)
                    {
                        args.MaxR = fR;
                    }
                    buffer[j] = fR;

                    i++; j++;

                    var fL = result[i];
                    if (fL > args.MaxL)
                    {
                        args.MaxL = fL;
                    }
                    buffer[j] = fL;
                }


                ac = sw.ElapsedMilliseconds;
            }
            else
            {
                for (int i = 0, j = inclusiveFrom; i < result.Length; i++, j++)
                {
                    buffer[j] = 0;
                }
            }

            FTime += timeChannelsCount / 2 * FTimeDelta;

            var gc = sw.ElapsedMilliseconds;

            if (App.DebugMode)
            {
                Debug.WriteLine($"OpenCLWaveProvider.Read: tot {gc - s}");
            }
        }
Ejemplo n.º 4
0
        public override void Read(Note[] notes, float[] buffer, int inclusiveFrom, int exclusiveTo, NoteWaveArgs args)
        {
            base.Read(notes, buffer, inclusiveFrom, exclusiveTo, args);

            for (int n = inclusiveFrom; n < exclusiveTo; n++)
            {
                SoundPointValue op = new SoundPointValue();
                for (int i = 0; i < notes.Length; i++)
                {
                    op += notes[i].GetValue(FTime);
                }

                op = op * args.MasterVolume;

                if (op.Right > args.MaxR)
                {
                    args.MaxR = op.Right;
                }

                //op = new SoundPointValue();

                buffer[n] = (float)op.Left;

                n++;

                if (op.Left > args.MaxL)
                {
                    args.MaxL = op.Left;
                }
                buffer[n] = (float)op.Right;

                FTime += FTimeDelta;
            }
        }