Beispiel #1
0
        public void Process(ref Sample sample)
        {
            sampleBuffer.Add(ref sample);

            if (sampleBuffer.Count == bufferSize)
            {
                uint   bid;
                byte[] data = GetSampleData();

                sampleBuffer.Clear();

                al.GenBuffers(1, out bid);
                al.BufferData(bid, AL.FORMAT_STEREO16, data, data.Length, 44100);

                bufferQueue.Enqueue(bid);

                if (bufferQueue.Count >= bufferCount)
                {
                    int sourceState;

                    al.GetSourcei(sid, AL.SOURCE_STATE, out sourceState);

                    if (sourceState != AL.PLAYING)
                    {
                        al.SourcePlay(sid);
                    }
                }
            }
        }
Beispiel #2
0
        private void ProcessSample()
        {
            // Enumerate all active providers.
            foreach (SampleProvider provider in activeProviders)
            {
                // Let the provider process one sample.
                provider.Process();

                // If the provider has stopped mark it for removal.
                if (provider.State == SampleProviderState.Stopped)
                {
                    stoppedProviders.Add(provider);
                }
            }

            // Enumerate all active channels.
            foreach (Channel channel in activeChannels)
            {
                // Let the channel mix all buffered samples and apply the effect chain to the mixed sample.
                // All the generated samples are buffered into the master buffer.
                if (!channel.Mix())
                {
                    // If the channel did not mix anything mark it for removal.
                    stoppedChannels.Add(channel);
                }
            }

            // Mix all the buffered samples in the master buffer.
            Sample finalSample = new Sample(0f, 0f);

            foreach (Sample sample in masterBuffer)
            {
                finalSample.left  += sample.left;
                finalSample.right += sample.right;
            }

            // Send the final mixed sample to the OpenAL voice.
            openALVoice.Process(ref finalSample);

            // Remove all the marked providers.
            if (stoppedProviders.Count != 0)
            {
                foreach (SampleProvider provider in stoppedProviders)
                {
                    activeProviders.Remove(provider);
                }

                stoppedProviders.Clear();
            }

            // Remove all the marked channels.
            if (stoppedChannels.Count != 0)
            {
                foreach (Channel channel in stoppedChannels)
                {
                    activeChannels.Remove(channel);
                }

                stoppedChannels.Clear();
            }

            listener.IsDirty = false;
            masterBuffer.Clear();
        }