Exemplo n.º 1
0
        internal MySourceVoice GetVoice(MyCueId cueId, MyInMemoryWave wave, CuePart part = CuePart.Start)
        {
            MyWaveFormat myWaveFormat = new MyWaveFormat()
            {
                Encoding   = wave.WaveFormat.Encoding,
                Channels   = wave.WaveFormat.Channels,
                SampleRate = wave.WaveFormat.SampleRate,
                WaveFormat = wave.WaveFormat
            };

            MySourceVoice voice = m_voicePools[myWaveFormat].NextAvailable();

            if (voice == null)
            {
                return(null);
            }
            voice.Flush();
            voice.SubmitSourceBuffer(cueId, wave, part);

            if (m_applyReverb)
            {
                voice.Voice.SetEffectChain(m_effectDescriptor);
                voice.Voice.EnableEffect(0);
            }
            else
            {
                voice.Voice.SetEffectChain(null);
            }
            return(voice);
        }
Exemplo n.º 2
0
        internal MySourceVoice GetVoice(MyCueId cueId, out int waveNumber, MySoundDimensions type = MySoundDimensions.D2, int tryIgnoreWaveNumber = -1)
        {
            waveNumber = -1;
            MySoundData cue = GetCue(cueId);

            if ((cue == null) || (cue.Waves == null) || (cue.Waves.Count == 0))
            {
                return(null);
            }

            CuePart        part;
            MyInMemoryWave wave = GetRandomWave(cue, type, out waveNumber, out part, tryIgnoreWaveNumber);

            if (wave == null && type == MySoundDimensions.D2)
            {
                type = MySoundDimensions.D3;
                wave = GetRandomWave(cue, type, out waveNumber, out part, tryIgnoreWaveNumber);
            }
            if (wave == null)
            {
                return(null);
            }

            MySourceVoice voice = GetVoice(cueId, wave, part);

            if (voice == null)
            {
                return(null);
            }

            if (cue.Loopable)
            {
                wave = GetWave(cue, type, waveNumber, CuePart.Loop);
                if (wave != null)
                {
                    Debug.Assert(voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding);
                    if (voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding)
                    {
                        voice.SubmitSourceBuffer(cueId, wave, CuePart.Loop);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(string.Format("Inconsistent encodings: '{0}', got '{1}', expected '{2}', part = '{3}'", cueId, wave.WaveFormat.Encoding, voice.Owner.WaveFormat.Encoding, CuePart.Loop));
                    }
                }
                wave = GetWave(cue, type, waveNumber, CuePart.End);
                if (wave != null)
                {
                    Debug.Assert(voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding);
                    if (voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding)
                    {
                        voice.SubmitSourceBuffer(cueId, wave, CuePart.End);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(string.Format("Inconsistent encodings: '{0}', got '{1}', expected '{2}', part = '{3}'", cueId, wave.WaveFormat.Encoding, voice.Owner.WaveFormat.Encoding, CuePart.End));
                    }
                }
            }

#if DEBUG
            if (voice.CueEnum.IsNull == false)
            {
                AddVoiceForDebug(voice);
            }
#endif

            return(voice);
        }
Exemplo n.º 3
0
        internal MySourceVoice GetVoice(MyStringId hashedCue, MySoundDimensions type = MySoundDimensions.D2)
        {
            MySoundData cue = GetCue(hashedCue);

            if ((cue == null) || (cue.Waves == null) || (cue.Waves.Count == 0))
            {
                return(null);
            }

            int            waveNumber;
            CuePart        part;
            MyInMemoryWave wave = GetRandomWave(cue, type, out waveNumber, out part);

            if (wave == null && type == MySoundDimensions.D2)
            {
                type = MySoundDimensions.D3;
                wave = GetRandomWave(cue, type, out waveNumber, out part);
            }
            if (wave == null)
            {
                return(null);
            }

            MySourceVoice voice = GetVoice(hashedCue, wave, part);

            if (voice == null)
            {
                return(null);
            }

            if (cue.Loopable)
            {
                wave = GetWave(cue, type, waveNumber, CuePart.Loop);
                if (wave != null)
                {
                    Debug.Assert(voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding);
                    if (voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding)
                    {
                        voice.SubmitSourceBuffer(hashedCue, wave, CuePart.Loop);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(string.Format("Inconsistent encodings: '{0}', got '{1}', expected '{2}', part = '{3}'", hashedCue, wave.WaveFormat.Encoding, voice.Owner.WaveFormat.Encoding, CuePart.Loop));
                    }
                }
                wave = GetWave(cue, type, waveNumber, CuePart.End);
                if (wave != null)
                {
                    Debug.Assert(voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding);
                    if (voice.Owner.WaveFormat.Encoding == wave.WaveFormat.Encoding)
                    {
                        voice.SubmitSourceBuffer(hashedCue, wave, CuePart.End);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(string.Format("Inconsistent encodings: '{0}', got '{1}', expected '{2}', part = '{3}'", hashedCue, wave.WaveFormat.Encoding, voice.Owner.WaveFormat.Encoding, CuePart.End));
                    }
                }
            }
            return(voice);
        }