Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - sfml-ah

Pages: [1]
1
Audio / When the Stream Stops.....
« on: March 02, 2011, 11:47:53 pm »
Thanks again for the fast reply.

When the stream stops, I try to check for the status after supplying new data and change it to Playing Status by calling Play().

This action causes the resulting Audio Output to have a tick-sound at the very start of each call to Play() ( where the data supply stops for a short term ), which in turn confuses the Noise Reduction Group.

So using the temporary solution mentioned previously, allows me to avoid calling Play(), thus no tick-sound in the Audio Output.


Note: The received Audio Data (sdata) corresponds to RF with LSB, USB, FM, or AM modulation for now. And you're right concerning the OnSeek() function. And why is OnStart() removed in 2.0?


Thanks in advance for your help.

2
Audio / Temporary Solution.....
« on: March 02, 2011, 04:54:27 pm »
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)
Code: [Select]

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:
Code: [Select]

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.

3
Audio / Extending SoundStream/C#, Lack of examples? Not working?
« on: March 01, 2011, 02:38:30 pm »
I'm working on DSP-related processing where I need to process the data received (Samples) from the DSP as a Sound Stream i.e. to play the data for starters...
The following is an attempt to achieve such functionality:
Code: [Select]

   public class AudioStream : SoundStream {

        private List<short> myBuffer;
        private int offset;
        private int myBufferSize;

        public AudioStream( int myBufferSize )
        {
            this.offset = 0;
            this.myBufferSize = myBufferSize;
            myBuffer = new List<short>();
        }

        protected override bool OnGetData(out short[] samples)
        {
            samples = null;
            if (offset + myBufferSize >= myBuffer.Count)
                return false;
            samples = new short[myBuffer.Count - offset];
            myBuffer.CopyTo(samples, offset);
            offset += myBuffer.Count - offset;
            return true;
        }

        protected override void OnSeek(float timeOffset)
        {
            offset =  Convert.ToInt16(timeOffset);
        }

        public void setData(short[] samples) {
            myBuffer.AddRange(samples);
        }
        public void clearBuffer()
        {
            myBuffer.Clear();
            offset = 0;
        }
    }

///Usage
if(audioStream.Status == SoundStatus.Stopped)
       audioStream.clearBuffer();
audioStream.setData(sdata);
if (audioStream.Status != SoundStatus.Playing)
      audioStream.Play();

Problem: The above usage part causes the AudioStream to Stop playing, and if the clearBuffer() is removed it replays old data.
Question: Where did I went wrong? and if so, how to correct/make it work?
Note: the data is received via a function....
Thanks in advance for your help...

Pages: [1]