Beispiel #1
0
        public DecodingService(int bufferLength, bool useFloatingPoint)
        {            
            _bufferLength = bufferLength;
            _useFloatingPoint = useFloatingPoint;
            _dataQueue = new ByteArrayQueue(_bufferLength);
            _audioFileQueue = new ConcurrentQueue<string>();

            OnNoAudioFileToDecode += () => { };
            StartWorker();
        }
Beispiel #2
0
 public TestByteArrayQueue()
 {
     _queue = new ByteArrayQueue(QueueCapacity);
     _random = new Random();            
 }
Beispiel #3
0
		private void TestDecode(string audioFilePath, bool isBusyDisk)
		{
			// Get byte length for 100ms worth of 44100Hz, 16-bit, Stereo
			int chunkSize = GetByteArrayLengthForMS(100);
			var queue = new ByteArrayQueue(chunkSize * 10);
			bool shouldLoop = true;
			_decodingService.OnNoAudioFileToDecode += () =>
			{
				Console.WriteLine("Finished decoding file!");
				shouldLoop = false;
			};

			Task.Factory.StartNew(() =>
				{
					Console.WriteLine("Starting to decode file...");
					_decodingService.StartDecodingFile(audioFilePath, 0);
				});

			Task.Factory.StartNew(() =>
				{
					while (shouldLoop)
					{
						try
						{
							// Make sure the chunk length doesn't exceed the remaining data in the current file
							int chunkSizeToDequeue = Math.Min(queue.BufferLength - queue.BufferDataLength, Math.Max(queue.BufferDataLength, chunkSize));
							//int chunkSizeToDequeue = Math.Min(queue.BufferLength - queue.BufferDataLength, chunkSize);
							Console.WriteLine("[>>>>>>] Dequeuing data (chunkSize: {0} chunkSizeToDequeue: {1} decodingServiceBuffer: {2}/{3})...", chunkSize, chunkSizeToDequeue, queue.BufferDataLength, queue.BufferLength);

							if (chunkSizeToDequeue > 0)
								queue.Dequeue(chunkSizeToDequeue);

							Thread.Sleep(20);
						}
						catch (Exception ex)
						{
							//Console.WriteLine("Failed: {0}", ex);
						}
					}
				});

			byte counter = 0;
			while (shouldLoop)
			{
				try
				{
					// Make sure we don't dequeue more data than available in the decoder service, or not more data than fits in the audio queue
					int chunkSizeToEnqueue = Math.Min(_decodingService.BufferDataLength, chunkSize);
					chunkSizeToEnqueue = Math.Min(queue.BufferLength - queue.BufferDataLength, chunkSizeToEnqueue);
					Console.WriteLine("[<<<<<<] Enqueuing data (length: {0})...", chunkSizeToEnqueue);

					var data = _decodingService.DequeueData(chunkSizeToEnqueue);
					if (data.Length > 0)
						queue.Enqueue(data);
					//else
					//Console.WriteLine("[Consumer] - No data to dequeue!");

					// Simulate busy disk every 10 cycles
					if (data.Length > 0 && isBusyDisk && counter % 10 == 0)
					{
						Console.WriteLine("!!!!!!!!!! SIMULATE BUSY DISK! !!!!!!!!!!!!!!!!");
						Thread.Sleep(20);
						counter = 0;
					}

					if(data.Length > 0)
						counter++;

					Thread.Sleep(20);
				}
				catch (Exception ex)
				{
					Console.WriteLine("Failed: {0}", ex);
				}
			}
		}