예제 #1
0
        /// <summary>
        /// Constructs an RAudioStreamer that plays ogg files in the background, useful for background music
        /// </summary>
        /// <param name="bufferSize">Buffer size</param>
        /// <param name="updateRate">Number of times per second to update</param>
        /// <param name="internalThread">True to use an internal thread, false to use your own thread, in which case use must call EnsureBuffersFilled periodically</param>
        public RAudioStreamer(int bufferSize = DefaultBufferSize, float updateRate = DefaultUpdateRate, bool internalThread = true)
        {
            lock (singletonMutex)
            {
                if (instance != null)
                {
                    throw new InvalidOperationException("Already running");
                }

                Instance = this;
                if (internalThread)
                {
                    underlyingThread = new Thread(EnsureBuffersFilled)
                    {
                        Priority = ThreadPriority.Lowest
                    };
                    underlyingThread.Start();
                }
                else
                {
                    // no need for this, user is in charge
                    updateRate = 0;
                }
            }

            UpdateRate = updateRate;
            BufferSize = bufferSize;

            readSampleBuffer = new float[bufferSize];
            castBuffer       = new short[bufferSize];
        }
예제 #2
0
        public void Dispose()
        {
            lock (singletonMutex)
            {
                Debug.Assert(Instance == this, "Two instances running, somehow...?");

                cancelled = true;
                lock (iterationMutex)
                    streams.Clear();

                Instance         = null;
                underlyingThread = null;
            }
        }