Пример #1
0
        /// <summary>
        /// Creates a clip by mixing the specified clips.
        /// </summary>
        public HapticsClip(HapticsClip a, HapticsClip b)
        {
            var maxCount = a.Count;

            if (b.Count > maxCount)
            {
                maxCount = b.Count;
            }

            Capacity = maxCount;
            Samples  = new byte[Capacity * Haptics.HapticsConfig.SampleSizeInBytes];

            for (var i = 0; i < a.Count || i < b.Count; i++)
            {
                if (Haptics.HapticsConfig.SampleSizeInBytes == 1)
                {
                    byte sample = 0; // TODO support multi-byte samples
                    if ((i < a.Count) && (i < b.Count))
                    {
                        var v = a.Samples[i] + b.Samples[i];
                        sample = (byte)(v <0 ? 0 : v> byte.MaxValue ? byte.MaxValue : v);   // TODO support multi-byte samples
                    }
                    else if (i < a.Count)
                    {
                        sample = a.Samples[i]; // TODO support multi-byte samples
                    }
                    else if (i < b.Count)
                    {
                        sample = b.Samples[i]; // TODO support multi-byte samples
                    }

                    WriteSample(sample); // TODO support multi-byte samples
                }
            }
        }
Пример #2
0
 public ClipPlaybackTracker(HapticsClip clip)
 {
     Clip = clip;
 }
Пример #3
0
            /// <summary>
            /// Adds the samples from the specified clip to the ones in the currently-playing clip(s).
            /// </summary>
            public void Mix(HapticsClip clip)
            {
                var numClipsToMix       = 0;
                var numSamplesToMix     = 0;
                var numSamplesRemaining = clip.Count;

                while (numSamplesRemaining > 0 && numClipsToMix < m_pendingClips.Count)
                {
                    var numSamplesRemainingInClip = m_pendingClips[numClipsToMix].Clip.Count - m_pendingClips[numClipsToMix].ReadCount;
                    numSamplesRemaining -= numSamplesRemainingInClip;
                    numSamplesToMix     += numSamplesRemainingInClip;
                    numClipsToMix++;
                }

                if (numSamplesRemaining > 0)
                {
                    numSamplesToMix    += numSamplesRemaining;
                    numSamplesRemaining = 0;
                }

                if (numClipsToMix > 0)
                {
                    var mixClip = new HapticsClip(numSamplesToMix);

                    var a          = clip;
                    var aReadCount = 0;

                    for (var i = 0; i < numClipsToMix; i++)
                    {
                        var b = m_pendingClips[i].Clip;
                        for (var bReadCount = m_pendingClips[i].ReadCount; bReadCount < b.Count; bReadCount++)
                        {
                            if (HapticsConfig.SampleSizeInBytes == 1)
                            {
                                byte sample = 0; // TODO support multi-byte samples
                                if ((aReadCount < a.Count) && (bReadCount < b.Count))
                                {
                                    var v = a.Samples[aReadCount] + b.Samples[bReadCount];
                                    sample = (byte)(v <0 ? 0 : v> byte.MaxValue ? byte.MaxValue : v);   // TODO support multi-byte samples
                                    aReadCount++;
                                }
                                else if (bReadCount < b.Count)
                                {
                                    sample = b.Samples[bReadCount]; // TODO support multi-byte samples
                                }

                                mixClip.WriteSample(sample); // TODO support multi-byte samples
                            }
                        }
                    }

                    while (aReadCount < a.Count)
                    {
                        if (HapticsConfig.SampleSizeInBytes == 1)
                        {
                            mixClip.WriteSample(a.Samples[aReadCount]); // TODO support multi-byte samples
                        }
                        aReadCount++;
                    }

                    m_pendingClips[0] = new ClipPlaybackTracker(mixClip);
                    for (var i = 1; i < numClipsToMix; i++)
                    {
                        m_pendingClips.RemoveAt(1);
                    }
                }
                else
                {
                    m_pendingClips.Add(new ClipPlaybackTracker(clip));
                }
            }
Пример #4
0
 /// <summary>
 /// Enqueues the specified clip to play after any currently-playing clip finishes.
 /// </summary>
 public void Queue(HapticsClip clip)
 {
     m_pendingClips.Add(new ClipPlaybackTracker(clip));
 }
Пример #5
0
 /// <summary>
 /// Immediately plays the specified clip without waiting for any currently-playing clip to finish.
 /// </summary>
 public void Preempt(HapticsClip clip)
 {
     m_pendingClips.Clear();
     m_pendingClips.Add(new ClipPlaybackTracker(clip));
 }