Thanks for the fast reply. You have a good Community/Support.
Below you will find the required information:
- The code below shows how the data is being updated inside the stream. The Code is inside an event handler that is called when new data or sdata is received: (sdata is 2048 = myBufferSize)
if (audioStream.Status == SFML.Audio.SoundStatus.Stopped)
{
audioStream.clearBuffer();
}
audioStream.setData(sdata); //sdata = short[2048]
if (audioStream.Status != SFML.Audio.SoundStatus.Playing)
{
audioStream.Play();
}
The problem is that the data required to be played is supplied through a function and as soon as the data supply stops for a short term the SoundStream switchs to Stopped Status because of the false return value of the OnGetData. So I need to keep the SoundStream in Playing Status even though the data supply stops for a short term.
Supplying empty/zero array causes ticks in the played audio, thus a temporary solution is realized using the EventWaitHandle class.
The functionality required is similar to the Bass Audio Library Stream Capability, where the data is just "pushed" into the stream resulting in a continuous audio output even if the data supply stops for a short term. But of-course then I have a bigger problem with licensing.
The code below corresponds to the temporary solution:
public class AudioStream : SoundStream
{
private int myBufferSize;
private uint channelCount;
private uint sampleRate;
private short[] tempData;
private static EventWaitHandle ewh;
private bool play;
public AudioStream(int myBufferSize, uint channelCount, uint sampleRate)
{
this.myBufferSize = myBufferSize;
this.channelCount = channelCount;
this.sampleRate = sampleRate;
Initialize(this.channelCount, this.sampleRate);
tempData = new short[myBufferSize];
ewh = new EventWaitHandle(false, EventResetMode.AutoReset);
play = true;
}
protected override bool OnGetData(out short[] samples)
{
ewh.WaitOne();
samples = tempData;
if (!play)
return false;
return true;
}
protected override void OnSeek(float timeOffset)
{
/////
}
public void setData(short[] samples)
{
samples.CopyTo(tempData, 0);
ewh.Set();
}
public void unblock() {
play = false;
ewh.Set();
}
Note: I switch the Audio Library of the whole project from PortAudio to SFML because, I can achieve the same functionality with less pain !!!!
And I'm using the 2.0 version. Any how-to for the OnSeek function is appreciated.