Ejemplo n.º 1
0
		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;
			}
		}
Ejemplo n.º 2
0
		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;
		}
Ejemplo n.º 3
0
		public static void EndStream(ref VorbisStreamHandle handle)
		{
			if (handle != null)
			{
				handle.Dispose();
				handle = null;
			}
		}
Ejemplo n.º 4
0
		public static bool IsStreamValid(VorbisStreamHandle handle)
		{
			return handle != null && !handle.Disposed;
		}
Ejemplo n.º 5
0
		public static void BeginStreamFromMemory(byte[] memory, out VorbisStreamHandle handle)
		{
			handle = new VorbisStreamHandle(memory);
		}
Ejemplo n.º 6
0
		public static void BeginStreamFromFile(string filename, out VorbisStreamHandle handle)
		{
			handle = new VorbisStreamHandle(filename);
		}