Exemplo n.º 1
0
 /// <summary>
 /// Creates the XAudio2.
 /// </summary>
 private void CreateXAudio2()
 {
     try
     {
         _xaudio2 = new XAudio2_8(XAudio2Processor.Xaudio2DefaultProcessor);
     }
     catch (Exception)
     {
         try
         {
             _xaudio2 = new XAudio2_7(false, XAudio2Processor.Xaudio2DefaultProcessor);
         }
         catch
         {
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates the XAudio2.
 /// </summary>
 private void CreateXAudio2()
 {
     try
     {
         _xaudio2 = new XAudio2_8(XAudio2Processor.Xaudio2DefaultProcessor);
     }
     catch (Exception)
     {
         try
         {
             _xaudio2 = new XAudio2_7(false, XAudio2Processor.Xaudio2DefaultProcessor);
         }
         catch
         {
         }
     }
 }
Exemplo n.º 3
0
        internal StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource, VoiceCallback voiceCallback, int bufferSize)
            : base(CreateSourceVoice(xaudio2, waveSource, voiceCallback), xaudio2.Version)
        {
            _voiceCallback = voiceCallback;
            _waveSource = waveSource;

            var maxBufferBytes = (int)waveSource.WaveFormat.MillisecondsToBytes(bufferSize);
            _buffer = new byte[maxBufferBytes];

            for (int i = 0; i < _buffers.Length; i++)
            {
                var buffer = new XAudio2Buffer(maxBufferBytes);
                _buffers[i] = buffer;
            }

            InitializeForStreaming();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new XAudio2SoundProvider class
 /// <param name="xaudio2">The XAudio2 Instance.</param>
 /// <param name="soundInitializer">The ISoundInitializer.</param>
 /// </summary>
 internal XAudio2SoundProvider(CSCore.XAudio2.XAudio2 xaudio2, ISoundInitializer soundInitializer)
 {
     SoundInitializer = soundInitializer;
     _xaudio2         = xaudio2;
     _xaudio2.CreateMasteringVoice();
 }
Exemplo n.º 5
0
 public void Initialize()
 {
     _source = GlobalTestConfig.TestMp3();
     _xaudio2 = CreateXAudio2();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new XAudio2SoundProvider class
 /// <param name="xaudio2">The XAudio2 Instance.</param>
 /// <param name="soundInitializer">The ISoundInitializer.</param>
 /// </summary>
 internal XAudio2SoundProvider(CSCore.XAudio2.XAudio2 xaudio2, ISoundInitializer soundInitializer)
 {
     SoundInitializer = soundInitializer;
     _xaudio2 = xaudio2;
     _xaudio2.CreateMasteringVoice();
 }
Exemplo n.º 7
0
 public void Initialize()
 {
     _source  = GlobalTestConfig.TestMp3();
     _xaudio2 = CreateXAudio2();
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Creates an instance of the <see cref="StreamingSourceVoice" /> class.
        /// </summary>
        /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class.</param>
        /// <param name="waveSource"><see cref="IWaveSource" /> which provides the audio data to stream.</param>
        /// <param name="bufferSize">
        ///     Buffersize of the internal used buffers in milliseconds. Values in the range from 70ms to
        ///     200ms are recommended.
        /// </param>
        /// <returns>Configured <see cref="StreamingSourceVoice" /> instance.</returns>
        public static StreamingSourceVoice Create(XAudio2 xaudio2, IWaveSource waveSource, int bufferSize = 100)
        {
            var voiceCallback = new VoiceCallback();
            IntPtr ptr = xaudio2.CreateSourceVoicePtr(waveSource.WaveFormat, VoiceFlags.None,
                XAudio2.DefaultFrequencyRatio, voiceCallback,
                null, null);

            return new StreamingSourceVoice(ptr, voiceCallback, waveSource, bufferSize);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamingSourceVoice"/> class.
 /// </summary>
 /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class, used to create the <see cref="XAudio2SourceVoice"/>.</param>
 /// <param name="waveSource">The <see cref="IWaveSource" /> instance which provides audio data to play.</param>
 /// <param name="bufferSize">
 ///     Buffersize of the internal buffers, in milliseconds. Values in the range from 70ms to
 ///     200ms are recommended.
 /// </param>
 public StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource, int bufferSize)
     : this(xaudio2, waveSource, new VoiceCallback(), bufferSize)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamingSourceVoice"/> class with a default buffer size of 100ms.
 /// </summary>
 /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class, used to create the <see cref="XAudio2SourceVoice"/>.</param>
 /// <param name="waveSource">The <see cref="IWaveSource" /> instance which provides audio data to play.</param>
 public StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource)
     : this(xaudio2, waveSource, 100)
 {
 }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamingSourceVoice"/> class.
 /// </summary>
 /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class, used to create the <see cref="XAudio2SourceVoice"/>.</param>
 /// <param name="waveSource">The <see cref="IWaveSource" /> instance which provides audio data to play.</param>
 /// <param name="bufferSize">
 ///     Buffersize of the internal buffers, in milliseconds. Values in the range from 70ms to
 ///     200ms are recommended.
 /// </param>
 public StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource, int bufferSize)
     : this(xaudio2, waveSource, new VoiceCallback(), bufferSize)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamingSourceVoice"/> class with a default buffer size of 100ms.
 /// </summary>
 /// <param name="xaudio2">Instance of the <see cref="XAudio2" /> class, used to create the <see cref="XAudio2SourceVoice"/>.</param>
 /// <param name="waveSource">The <see cref="IWaveSource" /> instance which provides audio data to play.</param>
 public StreamingSourceVoice(XAudio2 xaudio2, IWaveSource waveSource)
     : this(xaudio2, waveSource, 100)
 {
 }
Exemplo n.º 13
0
        private static IntPtr CreateSourceVoice(XAudio2 xaudio2, IWaveSource waveSource, VoiceCallback callback)
        {
            if (xaudio2 == null)
                throw new ArgumentNullException("xaudio2");
            if (waveSource == null)
                throw new ArgumentNullException("waveSource");

            return xaudio2.CreateSourceVoicePtr(waveSource.WaveFormat, VoiceFlags.None,
                XAudio2.DefaultFrequencyRatio, callback,
                null, null);
        }