/// <summary> /// Create a Unity audio clip for an audio stream. /// </summary> private static AudioClip CreateStreamingAudioClip(string name, MP3StreamReader audioStream) { PCMAudioBuffer streamBuffer = new PCMAudioBuffer(audioStream.channelCount, audioStream.bitDepth, audioStream.samplingRate, 8192); int bufferAudioClipSampleFrameCount = audioStream.samplingRate; return(AudioClip.Create(name, bufferAudioClipSampleFrameCount, audioStream.channelCount, audioStream.samplingRate, true, delegate(float[] samples) { int samplesReturned = FillUnityStreamBuffer(samples, streamBuffer, audioStream); if (audioStream.isOpen && audioStream.isDoneStreaming) { audioStream.Close(); } })); }
void OnAudioFilterRead(float[] samples, int channelCount) { if (UnitySampleRate > 0) { var lowSRSampleCount = (int)((44100.0f / UnitySampleRate) * samples.Length); var lowSRSamples = new float[lowSRSampleCount]; var samplesReturned = AudioUtils.FillUnityStreamBuffer(lowSRSamples, streamBuffer, audioStream); AudioUtils.ResampleHack(lowSRSamples, samples); //AudioUtils.LowPassHack(samples); if (audioStream.isOpen && audioStream.isDoneStreaming) { audioStream.Close(); } } }