Ejemplo n.º 1
0
        private void InitVoicePools()
        {
            List <MyWaveFormat> waveFormats = m_waveBank.GetWaveFormats();

            if (waveFormats.Count > 0)
            {
                m_voicePools = new Dictionary <MyWaveFormat, MySourceVoicePool>(waveFormats.Count);
                foreach (MyWaveFormat waveFormat in waveFormats)
                {
                    m_voicePools[waveFormat] = new MySourceVoicePool(m_audioEngine, waveFormat.WaveFormat, this);
                }
            }
        }
Ejemplo n.º 2
0
        internal void DestroyVoice()
        {
            m_valid             = false;
            m_currentDescriptor = null;
            StoppedPlaying      = null;
            m_owner             = null;
            m_loopBuffers       = null;

            DisposeWaves();

            if (m_voice == null && m_dataStreams == null)
            {
                return;
            }

            lock (theLock)
            {
                if (m_voice != null && !m_voice.IsDisposed)
                {
                    if (m_voice.NativePointer != IntPtr.Zero)
                    {
                        if (IsValid)
                        {
                            m_voice.Stop();
                        }
                    }
                    if (m_dataStreams != null)
                    {
                        m_voice.BufferEnd -= OnStopPlayingBuffered;
                    }
                    else
                    {
                        m_voice.BufferEnd -= OnStopPlaying;
                    }
                }

                if (m_dataStreams != null)
                {
                    foreach (var dataStream in m_dataStreams)
                    {
                        dataStream.Dispose();
                    }
                    m_dataStreams.Clear();
                }
                m_dataStreams = null;
            }
        }
Ejemplo n.º 3
0
        public MySourceVoice(MySourceVoicePool owner, XAudio2 device, WaveFormat sourceFormat)
        {
            // This value influences how many native memory is allocated in XAudio
            // When shifting sound to higher frequency it needs more data, because it's compressed in time
            // Ratio 2 equals to 11 or 12 semitones (=1 octave)
            // Values around 32 should be pretty safe
            // Values around 128 needs large amount of memory
            // Values > 128 are memory killer
            const float MaxFrequencyRatio = 2;

            m_voice = new SourceVoice(device, sourceFormat, VoiceFlags.UseFilter, MaxFrequencyRatio, true);
            m_voice.BufferEnd += OnStopPlaying;
            m_valid = true;

            m_owner = owner;
            m_owner.OnAudioEngineChanged += m_owner_OnAudioEngineChanged;
            Flush();
        }
Ejemplo n.º 4
0
        public MySourceVoice(MySourceVoicePool owner, XAudio2 device, WaveFormat sourceFormat)
        {
            // This value influences how many native memory is allocated in XAudio
            // When shifting sound to higher frequency it needs more data, because it's compressed in time
            // Ratio 2 equals to 11 or 12 semitones (=1 octave)
            // Values around 32 should be pretty safe
            // Values around 128 needs large amount of memory
            // Values > 128 are memory killer
            const float MaxFrequencyRatio = 2;

            m_voice            = new SourceVoice(device, sourceFormat, VoiceFlags.UseFilter, MaxFrequencyRatio, true);
            m_voice.BufferEnd += OnStopPlaying;
            m_valid            = true;

            m_owner = owner;
            m_owner.OnAudioEngineChanged += m_owner_OnAudioEngineChanged;
            Flush();
        }
Ejemplo n.º 5
0
        internal void DestroyVoice()
        {
            m_valid = false;
            m_currentDescriptor = null;
            StoppedPlaying = null;
            m_owner = null;
            m_loopBuffers = null;

            DisposeWaves();

            if (m_voice == null && m_dataStreams == null)
                return;

            lock (theLock)
            {
                if (m_voice != null && !m_voice.IsDisposed)
                {
                    if (m_voice.NativePointer != IntPtr.Zero)
                    {
                        if (IsValid)
                            m_voice.Stop();
                    }
                    if (m_dataStreams != null)
                        m_voice.BufferEnd -= OnStopPlayingBuffered;
                    else
                        m_voice.BufferEnd -= OnStopPlaying;
                }

                if (m_dataStreams != null)
                {
                    foreach (var dataStream in m_dataStreams)
                        dataStream.Dispose();
                    m_dataStreams.Clear();
                }
                m_dataStreams = null;
            }
        }