Click here to Skip to main content
15,886,069 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Sebastian Streiger4-Jun-09 4:40
Sebastian Streiger4-Jun-09 4:40 
GeneralRe: XML Serialization Problem with properties that when set change object status Pin
Moreno Airoldi4-Jun-09 4:47
Moreno Airoldi4-Jun-09 4:47 
QuestionPlaying smoothly small pieces with DirectSound Pin
Andrey U2-Jun-09 0:09
Andrey U2-Jun-09 0:09 
AnswerRe: Playing smoothly small pieces with DirectSound Pin
molesworth2-Jun-09 3:31
molesworth2-Jun-09 3:31 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
Andrey U2-Jun-09 4:18
Andrey U2-Jun-09 4:18 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
molesworth2-Jun-09 6:58
molesworth2-Jun-09 6:58 
AnswerRe: Playing smoothly small pieces with DirectSound Pin
Mark Salsbery2-Jun-09 8:26
Mark Salsbery2-Jun-09 8:26 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
Andrey U2-Jun-09 22:37
Andrey U2-Jun-09 22:37 
Thank you very much!

Let me show you what I did.

Playing method:
(I've set the buffer to notify me at the half and at the end)
public void PlayingInThread()
{
    NotifyPlaying();
    playBuffer.Play(0, BufferPlayFlags.Looping);
    bool flag = true;
    byte[] data;
    while (true)
    {
        arePlaying.WaitOne();
        data = jitter.Get();

        if (flag)
        {
            playBuffer.Write(playBufferBytes / 2, data, LockFlag.None);
        }
        else
        {
            playBuffer.Write(0, data, LockFlag.None);
        }

        flag = !flag;
    }
}


And I wrote a very simple jitter class, which uses a queue:
class JitterBuffer
    {
        Queue<byte[]> mBuffer = new Queue<byte[]>();
        int mItemLength;

        public JitterBuffer(int length)
        {
            mItemLength = length;
        }

        public void Put(byte[] data)
        {
            mBuffer.Enqueue(data);
        }

        public byte[] Get()
        {
            if (mBuffer.Count == 0)
                return new byte[mItemLength];
            else
                return mBuffer.Dequeue();
        }
    }



Am I right up to this point?



Testing this code I saw that there is aproximately one more packet (which can't be played because of the slower playing!) received every second.
So my next question is how to deal with 'too much data available'?

To be honest, I'm not very good at threads and I don't know if it is a good solution but I've tried the following code:
public void CatchUp()
{
    if (playBuffer.PlayPosition >= playBufferBytes / 2)
        playBuffer.SetCurrentPosition(playBufferBytes-2);
    else
        playBuffer.SetCurrentPosition(playBufferBytes / 2-2);
}

And I call this method from JitterBuffer.Put() when there are more then 2 packets in the queue. As you can guess in this case I face my initial problems with 'not smooth output'. Maybe I should only drop a packet from the queue when there are a lot?
(What bothers me about the threads is that I manipulate playBuffer from 2 threads in this case. Am I supposed to do it?)


And my last question: should I rely on the notification from a secondary buffer? I've read several times that there are bugs with it.


Regards
GeneralRe: Playing smoothly small pieces with DirectSound Pin
molesworth3-Jun-09 0:58
molesworth3-Jun-09 0:58 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
supercat93-Jun-09 7:07
supercat93-Jun-09 7:07 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
molesworth3-Jun-09 8:47
molesworth3-Jun-09 8:47 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
Mark Salsbery3-Jun-09 9:53
Mark Salsbery3-Jun-09 9:53 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
Mark Salsbery3-Jun-09 9:35
Mark Salsbery3-Jun-09 9:35 
GeneralRe: Playing smoothly small pieces with DirectSound Pin
molesworth3-Jun-09 22:33
molesworth3-Jun-09 22:33 
QuestionRe: Playing smoothly small pieces with DirectSound Pin
BenjoD10-Aug-09 18:31
BenjoD10-Aug-09 18:31 
Questionproblem solving in MDAC ver2.6 Pin
RAJAGOPALMS761-Jun-09 21:54
RAJAGOPALMS761-Jun-09 21:54 
AnswerRe: problem solving in MDAC ver2.6 Pin
Jimmanuel2-Jun-09 1:17
Jimmanuel2-Jun-09 1:17 
GeneralRe: problem solving in MDAC ver2.6 Pin
RAJAGOPALMS762-Jun-09 18:54
RAJAGOPALMS762-Jun-09 18:54 
QuestionHow to Use Network Sniffer Pin
amit512811-Jun-09 20:57
amit512811-Jun-09 20:57 
AnswerRe: How to Use Network Sniffer Pin
Simon P Stevens1-Jun-09 23:43
Simon P Stevens1-Jun-09 23:43 
Questionclient server communication Pin
yrishi1-Jun-09 19:58
yrishi1-Jun-09 19:58 
AnswerRe: client server communication Pin
rohitissharma2-Jun-09 18:07
rohitissharma2-Jun-09 18:07 
QuestionHow to build an IE toolbar that doesn't require installation Pin
zwlei1-Jun-09 17:23
zwlei1-Jun-09 17:23 
AnswerRe: How to build an IE toolbar that doesn't require installation Pin
leo_5551-Jun-09 19:16
leo_5551-Jun-09 19:16 
QuestionInstalling NETCFv35 in Windows Mobile 6 Classic [modified] Pin
Marije1-Jun-09 0:17
Marije1-Jun-09 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.