void Start() { if (Characteristics != null) { character = new float[Characteristics.samples]; Characteristics.GetData(character, 0); } if (Characteristics3D != null) { character = new float[Characteristics3D.Samples]; Characteristics3D.GetData(character, 0); } }
public HRTFSetEntry(double hAngle, double wAngle, double distance, string path) { Azimuth = hAngle; Elevation = wAngle; Distance = distance; Clip clip = AudioReader.ReadClip(path); Data = new float[clip.Channels][]; for (int channel = 0; channel < clip.Channels; ++channel) { Data[channel] = new float[clip.Samples]; } clip.GetData(Data, 0); }
IEnumerator ReadRawAudio() { int loops = 0; int readAbsPos = 0; int prevPos = 0; float[] temp = new float[Sample.Length]; while (Clip != null && Microphone.IsRecording(CurrentDeviceName)) { bool isNewDataAvailable = true; while (isNewDataAvailable) { int currPos = Microphone.GetPosition(CurrentDeviceName); if (currPos < prevPos) { loops++; } prevPos = currPos; var currAbsPos = loops * Clip.samples + currPos; var nextReadAbsPos = readAbsPos + temp.Length; if (nextReadAbsPos < currAbsPos) { Clip.GetData(temp, readAbsPos % Clip.samples); Sample = temp; m_SampleCount++; if (OnSampleReady != null) { OnSampleReady.Invoke(m_SampleCount, Sample); } readAbsPos = nextReadAbsPos; isNewDataAvailable = true; } else { isNewDataAvailable = false; } } yield return(null); } }
/// <summary> /// Generate the next <paramref name="samples"/> samples to be retrieved with <see cref="RetrieveSamples(ReferenceChannel)"/>. /// </summary> public void GenerateSamples(int samples) { // Preparations ReferenceChannel[] layout = ChannelPrototype.GetStandardMatrix(source.Channels); if (output[0].lastSamples.Length != samples) { for (int channel = 0; channel < output.Length; ++channel) { output[channel].lastSamples = null; } cache = new float[source.Channels][]; for (int channel = 0; channel < source.Channels; ++channel) { cache[channel] = new float[samples]; int channelId = GetChannelId(layout[channel]); if (channelId != -1) { output[channelId].lastSamples = cache[channel]; // Cache linked with output, no need to copy } } for (int channel = 0; channel < output.Length; ++channel) { if (output[channel].lastSamples == null) { output[channel].lastSamples = new float[samples]; } } } for (int channel = 0; channel < output.Length; ++channel) { output[channel].writtenTo = false; } // Fetch samples source.GetData(cache, timeSamples); if (timeSamples >= source.Samples) { if (loop) { timeSamples %= source.Samples; } else { timeSamples = 0; OnPlaybackFinished(); } } timeSamples += samples; for (int channel = 0; channel < source.Channels; ++channel) { output[GetChannelId(layout[channel])].writtenTo = true; } // Create missing channels via matrix if asked for if (matrixUpmix) { if (output[0].writtenTo && output[1].writtenTo) // Left and right channels available { if (!output[2].writtenTo) // Create discrete middle channel { float[] left = output[0].lastSamples, right = output[1].lastSamples, center = output[2].lastSamples; for (int offset = 0; offset < samples; ++offset) { center[offset] = (left[offset] + right[offset]) * .5f; } output[2].writtenTo = true; } if (!output[6].writtenTo) // Matrix mix for sides { float[] leftFront = output[0].lastSamples, rightFront = output[1].lastSamples, leftSide = output[6].lastSamples, rightSide = output[7].lastSamples; for (int offset = 0; offset < samples; ++offset) { leftSide[offset] = (leftFront[offset] - rightFront[offset]) * .5f; rightSide[offset] = -leftSide[offset]; } output[6].writtenTo = output[7].writtenTo = true; } if (!output[4].writtenTo) // Extend sides to rears... { bool rearsAvailable = false; // ...but only if there are rears in the system for (int channel = 0; channel < Listener.Channels.Length; ++channel) { float currentY = Listener.Channels[channel].Y; if (currentY < -135 || currentY > 135) { rearsAvailable = true; break; } } if (rearsAvailable) { float[] leftSide = output[6].lastSamples, rightSide = output[7].lastSamples, leftRear = output[4].lastSamples, rightRear = output[5].lastSamples; for (int offset = 0; offset < samples; ++offset) { leftRear[offset] = leftSide[offset] *= .5f; rightRear[offset] = rightSide[offset] *= .5f; } output[4].writtenTo = output[5].writtenTo = true; } } } } }