Esempio n. 1
0
        private void Queue(AudioSample newdata, Priority p = Priority.Normal)
        {
            //System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);      // UI thread.

            //for (int q = 0; q < audioqueue.Count; q++) System.Diagnostics.Debug.WriteLine(q.ToStringInvariant() + " " + (audioqueue[q].audiodata.data != null) + " " + audioqueue[q].priority);

            if (newdata != null)
            {
                //System.Diagnostics.Debug.WriteLine("Play " + ad.Lengthms(newdata.audiodata) + " in queue " + InQueuems() + " " + newdata.priority);

                if (audioqueue.Count > 0 && p > audioqueue[0].priority)         // if something is playing, and we have priority..
                {
                    //System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Priority insert " + p + " front " + audioqueue[0].priority);

                    if (audioqueue[0].priority == Priority.Low)                 // if low at front, remove all other lows after it
                    {
                        List <AudioSample> remove = new List <AudioSample>();
                        for (int i = 1; i < audioqueue.Count; i++)
                        {
                            if (audioqueue[i].priority == Priority.Low)
                            {
                                remove.Add(audioqueue[i]);
                                //System.Diagnostics.Debug.WriteLine("Queue to remove " + i);
                            }
                        }
                        foreach (AudioSample a in remove)
                        {
                            FinishSample(a, false);
                            audioqueue.Remove(a);
                        }
                    }

                    if (audioqueue[0].priority == Priority.High) // High playing, don't interrupt, but this one next
                    {
                        audioqueue.Insert(1, newdata);           // add one past front
                    }
                    else
                    {
                        audioqueue.Insert(1, newdata);  // add one past front
                        ad.Stop();                      // stopping makes it stop, does the callback, this gets called again, audio plays
                    }
                    return;
                }
                else
                {
                    //System.Diagnostics.Debug.WriteLine(Environment.TickCount + "AUDIO queue");

                    newdata.priority = p;
                    audioqueue.Add(newdata);
                    if (audioqueue.Count > 1)       // if not the first in queue, no action yet, let stopped handle it
                    {
                        return;
                    }
                }
            }

            if (audioqueue.Count > 0)
            {
                if (audioqueue[0].linkedq != null && audioqueue[0].linkeds != null)     // linked to another audio q, both must be at front to proceed
                {
                    if (!audioqueue[0].linkedq.IsWaiting(audioqueue[0].linkeds))        // if its not on top, don't play it yet
                    {
                        return;
                    }

                    audioqueue[0].linkedq.ReleaseHalt();        // it is waiting, so its stopped.. release halt on other one
                }

                ad.Start(audioqueue[0].audiodata, audioqueue[0].volume); // driver, play this
                audioqueue[0].SampleStart(this);                         // let callers know a sample started
            }
        }
Esempio n. 2
0
        private void Queue(AudioSample newdata, Priority p = Priority.Normal)
        {
            if (newdata != null)
            {
                if (audioqueue.Count > 0 && p > audioqueue[0].priority)         // if something is playing, and we have priority..
                {
                    System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Priority insert " + p + " front " + audioqueue[0].priority);

                    if (audioqueue[0].priority == Priority.Low)                 // if low at front, remove all other lows after it
                    {
                        List <AudioSample> remove = new List <AudioSample>();
                        for (int i = 1; i < audioqueue.Count; i++)
                        {
                            if (audioqueue[i].priority == Priority.Low)
                            {
                                remove.Add(audioqueue[i]);
                            }
                        }
                        foreach (AudioSample a in remove)
                        {
                            audioqueue.Remove(a);
                            ad.Dispose(a.audiodata); // tell the driver to clean up
                            a.ms?.Dispose();         // dispose of ms handle
                        }
                    }

                    if (audioqueue[0].priority == Priority.High) // High playing, don't interrupt, but this one next
                    {
                        audioqueue.Insert(1, newdata);           // add one past front
                    }
                    else
                    {
                        audioqueue.Insert(1, newdata);  // add one past front
                        ad.Stop();                      // stopping makes it stop, does the callback, this gets called again, audio plays
                    }
                    return;
                }
                else
                {
                    newdata.priority = p;
                    audioqueue.Add(newdata);
                    if (audioqueue.Count > 1)       // if not the first in queue, no action yet, let stopped handle it
                    {
                        return;
                    }
                }
            }

            if (audioqueue.Count > 0)
            {
                if (audioqueue[0].linkedq != null && audioqueue[0].linkeds != null)     // linked to another audio q, both must be at front to proceed
                {
                    if (!audioqueue[0].linkedq.IsWaiting(audioqueue[0].linkeds))        // if its not on top, don't play it yet
                    {
                        return;
                    }

                    audioqueue[0].linkedq.ReleaseHalt();        // it is waiting, so its stopped.. release halt on other one
                }

                ad.Start(audioqueue[0].audiodata, audioqueue[0].volume); // driver, play this

                audioqueue[0].SampleStart(this);                         // let callers know a sample started

                System.Diagnostics.Debug.WriteLine((Environment.TickCount % 10000).ToString("00000") + " Start audio at " + audioqueue[0].volume);
            }
        }