public static bool StreamChunk(IntPtr vFPtr, out PcmData result) { MemoryStream dataStream = null; bool notEof = StreamChunk(vFPtr, ref dataStream, out result.channelCount, out result.sampleRate); result.data = dataStream != null?dataStream.ToArray() : new byte[0]; return(notEof); }
public static bool StreamChunk(VorbisStreamHandle handle, out PcmData pcm, uint bufferSize = DefaultBufferSize) { pcm.dataLength = 0; pcm.channelCount = handle.VorbisInstance.Channels; pcm.sampleRate = handle.VorbisInstance.SampleRate; bool eof = false; float[] buffer = new float[bufferSize]; while (pcm.dataLength < buffer.Length) { int samplesRead; lock (readMutex) { samplesRead = handle.VorbisInstance.ReadSamples(buffer, pcm.dataLength, buffer.Length - pcm.dataLength); } if (samplesRead > 0) { pcm.dataLength += samplesRead; } else { eof = true; break; } } pcm.data = new short[pcm.dataLength]; CastBuffer(buffer, pcm.data, 0, pcm.dataLength); return pcm.dataLength > 0 && !eof; }
public static bool ReadAll(VorbisStreamHandle handle, out PcmData pcm) { pcm.channelCount = handle.VorbisInstance.Channels; pcm.sampleRate = handle.VorbisInstance.SampleRate; pcm.dataLength = 0; List<float[]> allBuffers = new List<float[]>(); bool eof = false; int totalSamplesRead = 0; while (!eof) { float[] buffer = new float[DefaultBufferSize]; int bufferSamplesRead = 0; while(bufferSamplesRead < buffer.Length) { int samplesRead; lock (readMutex) { samplesRead = handle.VorbisInstance.ReadSamples(buffer, pcm.dataLength, buffer.Length - pcm.dataLength); } if (samplesRead > 0) { bufferSamplesRead += samplesRead; } else { eof = true; break; } } allBuffers.Add(buffer); totalSamplesRead += bufferSamplesRead; } if (totalSamplesRead > 0) { pcm.dataLength = totalSamplesRead; pcm.data = new short[totalSamplesRead]; int offset = 0; for (int i = 0; i < allBuffers.Count; i++) { int len = Math.Min(pcm.data.Length - offset, allBuffers[i].Length); CastBuffer(allBuffers[i], pcm.data, offset, len); offset += len; } return !eof; } else { pcm.data = new short[0]; return false; } }
public static bool StreamChunk(IntPtr vFPtr, out PcmData result) { MemoryStream dataStream = null; bool notEof = StreamChunk(vFPtr, ref dataStream, out result.channelCount, out result.sampleRate); result.data = dataStream != null ? dataStream.ToArray() : new byte[0]; return notEof; }