float[] oafrDataArr = null; // instance buffer void OnAudioFilterRead(float[] data, int channels) { if (result == FMOD.RESULT.OK && openstate == FMOD.OPENSTATE.READY && this.isPlaying && !this.isPaused && !this.finished) { if (this.streamDataBytes == null || this.streamDataBytes.Length != (data.Length * 2)) { LOG(LogLevel.DEBUG, "Alocating new stream buffer of size {0}", data.Length * 2); this.streamDataBytes = new byte[data.Length * 2]; this.streamDataBytesPinned.Free(); this.streamDataBytesPinned = GCHandle.Alloc(this.streamDataBytes, GCHandleType.Pinned); this.streamDataBytesPtr = this.streamDataBytesPinned.AddrOfPinnedObject(); } uint read = 2; result = this.sound.readData(this.streamDataBytesPtr, (uint)this.streamDataBytes.Length, out read); // ERRCHECK(result, "OAFR sound.readData", false); if (result == FMOD.RESULT.OK) { if (read > 0) { int length = AudioStreamSupport.ByteArrayToFloatArray(this.streamDataBytes, read, ref this.oafrDataArr); for (int i = 0; i < length; ++i) { data[i] += this.oafrDataArr[i]; } } else { /* * do not attempt to read from empty buffer again */ this.finished = true; } } else { /* * do not attempt to read from buffer with error again */ this.finished = true; } } }
float[] oafrDataArr = null; // instance buffer float[] GetAudioOutputBuffer(uint _len) { lock (this.outputBufferLock) { // 2 bytes per 1 value - adjust requested length uint len = _len * 2; if (len > outputBuffer.Count) { return(null); } byte[] bArr = outputBuffer.GetRange(0, (int)len).ToArray(); outputBuffer.RemoveRange(0, (int)len); AudioStreamSupport.ByteArrayToFloatArray(bArr, (uint)bArr.Length, ref oafrDataArr); return(this.oafrDataArr); } }