using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Collections.Generic;
namespace SFML
{
namespace Audio
{
////////////////////////////////////////////////////////////
///
/// Specialized SoundRecorder which saves the captured
/// audio data into a sound buffer
///
////////////////////////////////////////////////////////////
public class SoundBufferRecorder : SoundRecorder
{
////////////////////////////////////////////////////////////
///
/// Sound buffer containing the recorded data (invalid until the capture stops)
///
////////////////////////////////////////////////////////////
public SoundBuffer SoundBuffer
{
get
{
return mySoundBuffer;
}
}
////////////////////////////////////////////////////////////
///
/// Called when a new capture starts
///
/// False to abort recording audio data, true to continue
////////////////////////////////////////////////////////////
protected override bool OnStart()
{
mySamplesArray.Clear();
return true;
}
////////////////////////////////////////////////////////////
///
/// Process a new chunk of recorded samples
///
/// Array of samples to process
/// False to stop recording audio data, true to continue
////////////////////////////////////////////////////////////
protected override bool OnProcessSamples(short[] samples)
{
mySamplesArray.AddRange(samples);
return true;
}
////////////////////////////////////////////////////////////
///
/// Called when the current capture stops
///
////////////////////////////////////////////////////////////
protected override void OnStop()
{
mySoundBuffer = new SoundBuffer(mySamplesArray.ToArray(), 1, SampleRate);
}
List mySamplesArray = new List();
SoundBuffer mySoundBuffer = null;
}
}
}