/* Copyright (C) 2014 DaikonForge */ namespace DaikonForge.VoIP { /// /// Helper class for separating input microphone data into chunks of a certain number of samples /// public class ChunkBuffer { //private List samples = new List(); private FastList samples = new FastList(); /// /// Add incoming samples to the buffer /// public void AddSamples( BigArray incomingSamples ) { int writeIndex = samples.Count * 4; int newLength = samples.Count + incomingSamples.Length; int writeBytes = incomingSamples.Length * 4; samples.EnsureCapacity( newLength ); samples.ForceCount( newLength ); incomingSamples.CopyTo( 0, samples.Items, writeIndex, writeBytes ); //for( int i = 0; i < incomingSamples.Length; i++ ) //{ // samples[ writeIndex + i ] = incomingSamples[ i ]; //} } /// /// Retrieve a chunk of the given size and fill destination array with samples /// /// True if a chunk is available, false otherwise public bool RetrieveChunk( float[] destination ) { if( samples.Count < destination.Length ) return false; for( int i = 0; i < destination.Length; i++ ) { destination[ i ] = samples[ i ]; } samples.RemoveRange( 0, destination.Length ); return true; } } }