/// <summary> /// Adds the samples from the specified clip to the ones in the currently-playing clip(s). /// </summary> public void Mix(OVRHapticsClip clip) { int numClipsToMix = 0; int numSamplesToMix = 0; int numSamplesRemaining = clip.Count; while (numSamplesRemaining > 0 && numClipsToMix < m_pendingClips.Count) { int 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) { OVRHapticsClip mixClip = new OVRHapticsClip(numSamplesToMix); OVRHapticsClip a = clip; int aReadCount = 0; for (int i = 0; i < numClipsToMix; i++) { OVRHapticsClip b = m_pendingClips[i].Clip; for (int bReadCount = m_pendingClips[i].ReadCount; bReadCount < b.Count; bReadCount++) { if (OVRHaptics.Config.SampleSizeInBytes == 1) { byte sample = 0; // TODO support multi-byte samples if ((aReadCount < a.Count) && (bReadCount < b.Count)) { sample = (byte)(Mathf.Clamp(a.Samples[aReadCount] + b.Samples[bReadCount], 0, System.Byte.MaxValue)); // 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 (OVRHaptics.Config.SampleSizeInBytes == 1) { mixClip.WriteSample(a.Samples[aReadCount]); // TODO support multi-byte samples } aReadCount++; } m_pendingClips[0] = new ClipPlaybackTracker(mixClip); for (int i = 1; i < numClipsToMix; i++) { m_pendingClips.RemoveAt(1); } } else { m_pendingClips.Add(new ClipPlaybackTracker(clip)); } }
/// <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)); } }
/// <summary> /// Adds the samples from the specified clip to the ones in the currently-playing clip(s). /// </summary> public void Mix(OVRHapticsClip clip) { int numClipsToMix = 0; int numSamplesToMix = 0; int numSamplesRemaining = clip.Count; while (numSamplesRemaining > 0 && numClipsToMix < m_pendingClips.Count) { int 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) { OVRHapticsClip mixClip = new OVRHapticsClip(numSamplesToMix); OVRHapticsClip a = clip; int aReadCount = 0; for (int i = 0; i < numClipsToMix; i++) { OVRHapticsClip b = m_pendingClips[i].Clip; for(int bReadCount = m_pendingClips[i].ReadCount; bReadCount < b.Count; bReadCount++) { if (OVRHaptics.Config.SampleSizeInBytes == 1) { byte sample = 0; // TODO support multi-byte samples if ((aReadCount < a.Count) && (bReadCount < b.Count)) { sample = (byte)(Mathf.Clamp(a.Samples[aReadCount] + b.Samples[bReadCount], 0, System.Byte.MaxValue)); // 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 (OVRHaptics.Config.SampleSizeInBytes == 1) { mixClip.WriteSample(a.Samples[aReadCount]); // TODO support multi-byte samples } aReadCount++; } m_pendingClips[0] = new ClipPlaybackTracker(mixClip); for (int i = 1; i < numClipsToMix; i++) { m_pendingClips.RemoveAt(1); } } else { m_pendingClips.Add(new ClipPlaybackTracker(clip)); } }