示例#1
0
        private void AudioEngineImpl(AudioDevice device)
        {
            mediaPlayer.Completion += OnMusicCompletion;
            mediaPlayer.Error += OnMusicError;
            mediaPlayer.Prepared += OnMusicPrepared;

            SoundEffectInstance.CreateAudioTracks();
        }
示例#2
0
        // This region is currently nor implemented nor exposed to the client

        private void AudioEngineImpl(AudioDevice device)
        {
            try
            {
                XAudio2 = new XAudio2();
                X3DAudio = new X3DAudio(Speakers.Stereo); // only stereo mode currently supported

                XAudio2.CriticalError += XAudio2OnCriticalError;

                MasteringVoice = new MasteringVoice(XAudio2, 2, (int)AudioSampleRate); // Let XAudio choose an adequate sampling rate for the platform and the configuration but not number of channels [force to stereo 2-channels]. 

                if (!mediaEngineStarted)
                {
                    // MediaManager.Startup(); <- MediaManager.Shutdown is buggy (do not set isStartUp to false) so we are forced to directly use MediaFactory.Startup here while sharpDX is not corrected.
                    MediaFactory.Startup(0x20070, 0);
                    mediaEngineStarted = true;
                }

                PlatformSpecificInit();
            }
            catch (DllNotFoundException exp)
            {
                State = AudioEngineState.Invalidated;
                Logger.Warning("One or more of the XAudio and MediaFoundation dlls were not found on the computer. " +
                               "Audio functionalities will not fully work for the current game instance." +
                               "To fix the problem install or repair the installation of XAudio and Media Foundation. [Exception details: {0}]", exp.Message);
            }
            catch (SharpDX.SharpDXException exp)
            {
                State = AudioEngineState.Invalidated;

                if (exp.ResultCode == XAudioErrorCodes.ErrorInvalidCall)
                {
                    Logger.Warning("Initialization of the audio engine failed. This may be due to missing audio hardware or missing audio outputs. [Exception details: {0}]", exp.Message);
                }
                else if (exp.ResultCode == 0x8007007E)
                {
                    Logger.Warning( "Audio engine initialization failed. This is probably due to missing dll on your computer. " +
                                    "Please check that XAudio2 and MediaFoundation are correctly installed.[Exception details: {0}]", exp.Message);
                }
                else
                {
                    Logger.Warning("Audio engine initialization failed. [Exception details: {0}]", exp.Message);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Create the Audio Engine on the specified device.
        /// </summary>
        /// <param name="device">Device on which to create the audio engine.</param>
        /// <param name="sampleRate">The desired sample rate of the audio graph. 0 let the engine choose the best value depending on the hardware.</param>
        /// <remarks>Available devices can be queried by calling static method <see cref="GetAvailableDevices"/></remarks>
        /// <exception cref="AudioInitializationException">Initialization of the audio engine failed. May be due to memory problems or missing audio hardware.</exception>
        private AudioEngine(AudioDevice device, uint sampleRate = 0)
        {
            if (device != null)
                throw new NotImplementedException();

            State = AudioEngineState.Running;

            AudioSampleRate = sampleRate;

            AudioEngineImpl(device);

            ++nbOfAudioEngineInstances;
        }
示例#4
0
 private void AudioEngineImpl(AudioDevice device)
 {
     if (nbOfAudioEngineInstances == 0)
         ActivateAudioSession();
 }