/// <summary> /// Initialize the media element for playback /// </summary> /// <param name="streamConfig">Object containing stream configuration details</param> void InitializeMediaPlayer(MoonlightStreamConfiguration streamConfig, AvStreamSource streamSource) { this._streamSource = streamSource; _videoMss = new MediaStreamSource(new VideoStreamDescriptor(VideoEncodingProperties.CreateH264())); _videoMss.BufferTime = TimeSpan.Zero; _videoMss.CanSeek = false; _videoMss.Duration = TimeSpan.Zero; _videoMss.SampleRequested += _videoMss_SampleRequested; XAudio2 xaudio = new XAudio2(); MasteringVoice masteringVoice = new MasteringVoice(xaudio, 2, 48000); WaveFormat format = new WaveFormat(48000, 16, 2); // Set for low latency playback StreamDisplay.RealTimePlayback = true; // Render on the full window to avoid extra compositing StreamDisplay.IsFullWindow = true; // Disable built-in transport controls StreamDisplay.AreTransportControlsEnabled = false; // Start playing right away StreamDisplay.AutoPlay = true; StreamDisplay.SetMediaStreamSource(_videoMss); AvStream.SetSourceVoice(new SourceVoice(xaudio, format)); }
public XAudioDevice() { if (StackTraceExtensions.StartedFromNUnitConsoleButNotFromNCrunch) return; XAudio = new XAudio2(); MasteringVoice = new MasteringVoice(XAudio); }
/// <summary> /// Initializes a new instance of the <see cref="AudioPlayer" /> class. /// </summary> /// <param name="xaudio2">The xaudio2 engine.</param> /// <param name="audioStream">The input audio stream.</param> public AudioPlayer(XAudio2 xaudio2, Stream audioStream) { this.xaudio2 = xaudio2; audioDecoder = new AudioDecoder(audioStream); //sourceVoice = new SourceVoice(xaudio2, audioDecoder.WaveFormat); sourceVoice = new SourceVoice(xaudio2, audioDecoder.WaveFormat,0,1.0f); localVolume = 1.0f; sourceVoice.BufferEnd += sourceVoice_BufferEnd; sourceVoice.Start(); bufferEndEvent = new AutoResetEvent(false); playEvent = new ManualResetEvent(false); waitForPlayToOutput = new ManualResetEvent(false); clock = new Stopwatch(); // Pre-allocate buffers audioBuffersRing = new AudioBuffer[3]; memBuffers = new DataPointer[audioBuffersRing.Length]; for (int i = 0; i < audioBuffersRing.Length; i++) { audioBuffersRing[i] = new AudioBuffer(); memBuffers[i].Size = 32 * 1024; // default size 32Kb memBuffers[i].Pointer = Utilities.AllocateMemory(memBuffers[i].Size); } // Initialize to stopped State = AudioPlayerState.Stopped; // Starts the playing thread playingTask = Task.Factory.StartNew(PlayAsync, TaskCreationOptions.LongRunning); }
public override void Dispose(bool disposing) { if (disposing) { if (sourceVoice != null) { sourceVoice.FlushSourceBuffers(); sourceVoice.Stop(); sourceVoice.Dispose(); sourceVoice = null; } if (xAudioBuffer != null) { xAudioBuffer.Stream.Dispose(); xAudioBuffer.Stream = null; xAudioBuffer = null; } if (xAudio != null) { xAudio.StopEngine(); xAudio.Dispose(); xAudio = null; } } }
//public static async Task<XSound> CreateAsync(SharpDX.XAudio2.XAudio2 device, string fileName, int? group = null) //{ // var sound = new XSound(device, fileName, group); // sound.Voice = await //} public XSound(SharpDX.XAudio2.XAudio2 device, string fileName, int?group = null) { Device = device; FileName = fileName; GroupId = @group; Voice = CreateVoice(device, fileName); }
public static void Destroy() { if (Music.m_XAudio2 == null) { return; } Music.Stop(); if (Music.m_SourceVoice != null) { Music.m_SourceVoice.Stop(); ((Voice)Music.m_SourceVoice).DestroyVoice(); Music.m_SourceVoice = (SourceVoice)null; } if (Music.m_AudioDecoder != null) { (Music.m_AudioDecoder).Dispose(); Music.m_AudioDecoder = (AudioDecoder)null; } ((Voice)Music.m_MasteringVoice).DestroyVoice(); ((DisposeBase)Music.m_MasteringVoice).Dispose(); Music.m_MasteringVoice = (MasteringVoice)null; ((DisposeBase)Music.m_XAudio2).Dispose(); Music.m_XAudio2 = (SharpDX.XAudio2.XAudio2)null; MediaFactory.Shutdown(); Music.IsDisposed = true; Music.m_PlayingTask.Wait(); }
public WaveManager() { xAudio = new XAudio2(); var mastering = new MasteringVoice(xAudio); mastering.SetVolume(1, 0); xAudio.StartEngine(); }
/// <summary> /// Creates and configures a submix voice with an effect chain. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels in the input audio data of the submix voice. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. </param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of submix voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. </param> /// <param name="flags">[in] Flags that specify the behavior of the submix voice. Can be 0 or the following: ValueDescriptionXAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.? </param> /// <param name="processingStage">[in] An arbitrary number that specifies when this voice is processed with respect to other submix voices, if the XAudio2 engine is running other submix voices. The voice is processed after all other voices that include a smaller ProcessingStage value, and before all other voices that include a larger ProcessingStage value. Voices that include the same ProcessingStage value are processed in any order. A submix voice cannot send to another submix voice with a lower or equal ProcessingStage value; this prevents audio being lost due to a submix cycle. </param> /// <param name="effectDescriptors">[in, optional] Pointer to a list of XAUDIO2_EFFECT_CHAIN structures that describe an effect chain to use in the submix voice.</param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSubmixVoice([Out] IXAudio2SubmixVoice** ppSubmixVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 ProcessingStage,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SubmixVoice(XAudio2 device, int inputChannels, int inputSampleRate, SubmixVoiceFlags flags, int processingStage, EffectDescriptor[] effectDescriptors) : base(IntPtr.Zero) { if (effectDescriptors != null) { unsafe { var tempSendDescriptor = new EffectChain(); var effectDescriptorNatives = new EffectDescriptor.__Native[effectDescriptors.Length]; for (int i = 0; i < effectDescriptorNatives.Length; i++) effectDescriptors[i].__MarshalTo(ref effectDescriptorNatives[i]); tempSendDescriptor.EffectCount = effectDescriptorNatives.Length; fixed (void* pEffectDescriptors = &effectDescriptorNatives[0]) { tempSendDescriptor.EffectDescriptorPointer = (IntPtr)pEffectDescriptors; device.CreateSubmixVoice(this, inputChannels, inputSampleRate, unchecked((int)flags), processingStage, null, tempSendDescriptor); } } } else { device.CreateSubmixVoice(this, inputChannels, inputSampleRate, unchecked((int)flags), processingStage, null, null); } }
public MySourceVoice(XAudio2 device, WaveFormat sourceFormat) { m_voice = new SourceVoice(device, sourceFormat, true); m_voice.BufferEnd += OnStopPlaying; m_valid = true; Flush(); }
/// <summary> /// Initializes a new instance of the <see cref="AudioProcessorParamNative<T>" /> class. /// </summary> /// <param name="device">The device.</param> protected AudioProcessorParamNative(SharpDX.XAudio2.XAudio2 device) : base(IntPtr.Zero) { if (device == null) { throw new ArgumentNullException("device"); } this.device = device; }
public EffectManager(XAudio2 xaudio2, int maxInstances, string soundPath) { this.xaudio2 = xaudio2; this.maxInstances = maxInstances; this.soundPath = soundPath; this.instances = new Dictionary<WaveFormat, List<SourceVoice>>(); }
public Audio(String fileName) { device = new XAudio2(); masteringVoice = new MasteringVoice(device); stream = new SoundStream(File.OpenRead("Content/"+fileName)); buffer = new AudioBuffer {Stream = stream.ToDataStream(), AudioBytes = (int)stream.Length, Flags = BufferFlags.EndOfStream}; stream.Close(); }
public MySourceVoicePool(XAudio2 audioEngine, WaveFormat waveformat, MyCueBank owner) { m_audioEngine = audioEngine; m_waveFormat = waveformat; m_owner = owner; m_availableVoices = new MyConcurrentQueue<MySourceVoice>(32); m_fadingOutVoices = new List<MySourceVoice>(); m_currentCount = 0; }
public MySourceVoice(XAudio2 device, WaveFormat sourceFormat) { m_voice = new SourceVoice(device, sourceFormat, true); m_voice.BufferEnd += OnStopPlayingBuffered; m_valid = true; m_dataStreams = new Queue<DataStream>(); Flush(); }
public static unsafe bool HasDeviceChanged(XAudio2 engine, string displayName) { const int GetDeviceDetailsMethodOffset = 4; XAUDIO2_DEVICE_DETAILS details; var result = (Result)NativeCall.Function<int, IntPtr, int, IntPtr>(new NativeFunction(engine.NativePointer, GetDeviceDetailsMethodOffset), engine.NativePointer, 0, new IntPtr(&details)); result.CheckError(); return !displayName.Equals(details.DisplayName, 256); }
public SoundManager(int sounds) { _audio = new XAudio2(); _masteringVoice = new MasteringVoice(_audio); _masteringVoice.SetVolume(0.5f); _soundStreams = new SoundStream[sounds]; _audioBuffers = new AudioBuffer[sounds]; _sourceVoices = new SourceVoice[sounds]; }
public SoundManager(int cntVoices) { audio = new XAudio2(); masteringVoice = new MasteringVoice(audio); masteringVoice.SetVolume(0.5f); voices = new SourceVoice[cntVoices]; buffers = new AudioBuffer[cntVoices]; streams = new SoundStream[cntVoices]; }
internal static void InitializeSoundEffect() { try { if (Device == null) { #if !WINRT && DEBUG try { //Fails if the XAudio2 SDK is not installed Device = new XAudio2(XAudio2Flags.DebugEngine, ProcessorSpecifier.DefaultProcessor); Device.StartEngine(); } catch #endif { Device = new XAudio2(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor); Device.StartEngine(); } } // Just use the default device. #if WINRT string deviceId = null; #else const int deviceId = 0; #endif if (MasterVoice == null) { // Let windows autodetect number of channels and sample rate. MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceId); MasterVoice.SetVolume(_masterVolume, 0); } // The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout. #if WINRT Speakers = (Speakers)MasterVoice.ChannelMask; #else var deviceDetails = Device.GetDeviceDetails(deviceId); Speakers = deviceDetails.OutputFormat.ChannelMask; #endif } catch { // Release the device and null it as // we have no audio support. if (Device != null) { Device.Dispose(); Device = null; } MasterVoice = null; } }
public void SetAudioEngine(XAudio2 audioEngine) { if (m_audioEngine != audioEngine) { m_audioEngine = audioEngine; m_playingVoices.Clear(); m_availableVoices.Clear(); m_fadingOutVoices.Clear(); m_maxCount = 0; } }
public void SetAudioEngine(XAudio2 audioEngine) { if (m_audioEngine != audioEngine) { if (OnAudioEngineChanged != null) OnAudioEngineChanged(); m_audioEngine = audioEngine; m_availableVoices.Clear(); m_fadingOutVoices.Clear(); m_currentCount = 0; } }
public TrackPlayer(XAudio2 xaudio2, string[] filenames) { if (filenames.Length == 0) throw new ArgumentException("No filenames specified"); this.xaudio2 = xaudio2; this.filenames = filenames; this.rnd = new Random(); this.players = new List<AudioPlayer>(); }
public X3DAudioEngine() { _xaudio2 = new XAudio2(); _masteringVoice = new MasteringVoice(_xaudio2); _deviceFormat = _xaudio2.GetDeviceDetails(0).OutputFormat; _x3dAudio = new X3DAudio(_deviceFormat.ChannelMask); Position = new Vector3D(0, 0, 0); Rotation = System.Windows.Media.Media3D.Quaternion.Identity; }
/// <summary> /// Creates and configures a mastering voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels the mastering voice expects in its input audio. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. InputChannels can be set to XAUDIO2_DEFAULT_CHANNELS, with the default being determined by the current platform. Windows Attempts to detect the system speaker configuration setup. Xbox 360 Defaults to 5.1 surround. </param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of the mastering voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. InputSampleRate can be set to XAUDIO2_DEFAULT_SAMPLERATE, with the default being determined by the current platform. Windows Windows XP defaults to 44100. Windows Vista and Windows 7 default to the setting specified in the Sound Control Panel. The default for this setting is 44100 (or 48000 if required by the driver). Xbox 360 Defaults to 48000. </param> /// <param name="deviceId">[in] Index of the output device that will be sent input by the mastering voice. Specifying the default value of 0 causes XAudio2 to select the global default audio device. </param> /// <unmanaged>HRESULT IXAudio2::CreateMasteringVoice([Out] IXAudio2MasteringVoice** ppMasteringVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 DeviceIndex,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public MasteringVoice(XAudio2 device, int inputChannels = 2, int inputSampleRate = 44100) : base(device) { if (device.Version == XAudio2Version.Version27) { device.CreateMasteringVoice27(this, inputChannels, inputSampleRate, 0, 0, null); } else { device.CreateMasteringVoice(this, inputChannels, inputSampleRate, 0, null, null, AudioStreamCategory.GameEffects); } }
/// <summary> /// SharpDX XAudio2 sample. Plays wav/xwma/adpcm files from the disk. /// </summary> static void Main(string[] args) { var xaudio2 = new XAudio2(); var masteringVoice = new MasteringVoice(xaudio2); PLaySoundFile(xaudio2, "1) Playing a standard WAV file", "ergon.wav"); PLaySoundFile(xaudio2, "2) Playing a XWMA file", "ergon.xwma"); PLaySoundFile(xaudio2, "3) Playing an ADPCM file", "ergon.adpcm.wav"); masteringVoice.Dispose(); xaudio2.Dispose(); }
public XAudio2Mixer() { _xAudio = new XAudio2(); _xAudio.StartEngine(); _masteringVoice = new MasteringVoice(_xAudio); _buffers = new XAudioBuffer[NumBuffers]; for (var i = 0; i < NumBuffers; i++) { _buffers[i] = new XAudioBuffer(BufferSize); } }
public XAudioSound(string filename, XAudioDevice device) : base(filename, device) { xAudio = device.XAudio2; using (var stream = LoadStream("Content/" + filename + ".wav")) { format = stream.Format; length = CalculateLengthInSeconds(format, (int)stream.Length); buffer = CreateAudioBuffer(stream.ToDataStream()); decodedInfo = stream.DecodedPacketsInfo; } }
private void Dispose(bool disposing) { if (audio != null) { audio.StopEngine(); audio.Dispose(); audio = null; foreach (SourceVoice voice in voices) voice.Dispose(); foreach (SoundStream stream in streams) stream.Dispose(); } }
internal FactoryHandlerXAudio2() { try { m_xaudioDevice = new SharpDX.XAudio2.XAudio2(SharpDX.XAudio2.XAudio2Version.Default); m_masteringVoice = new SharpDX.XAudio2.MasteringVoice(m_xaudioDevice); } catch (Exception) { m_xaudioDevice = null; m_masteringVoice = null; } }
/// <summary> /// /// </summary> public override void Initialize() { try { if (Device == null) { Device = new XAudio2(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor); Device.StartEngine(); } var DeviceFormat = Device.GetDeviceDetails(0).OutputFormat; // Just use the default device. const int deviceId = 0; if (MasterVoice == null) { // Let windows autodetect number of channels and sample rate. MasterVoice = new MasteringVoice(Device, XAudio2.DefaultChannels, XAudio2.DefaultSampleRate, deviceId); MasterVoice.SetVolume(_masterVolume, 0); } // The autodetected value of MasterVoice.ChannelMask corresponds to the speaker layout. var deviceDetails = Device.GetDeviceDetails(deviceId); Speakers = deviceDetails.OutputFormat.ChannelMask; var dev3d = Device3D; Log.Debug("Audio devices :"); for ( int devId = 0; devId < Device.DeviceCount; devId++ ) { var device = Device.GetDeviceDetails( devId ); Log.Debug( "[{1}] {0}", device.DisplayName, devId ); Log.Debug( " role : {0}", device.Role ); Log.Debug( " id : {0}", device.DeviceID ); } } catch { // Release the device and null it as // we have no audio support. if (Device != null) { Device.Dispose(); Device = null; } MasterVoice = null; } soundWorld = new SoundWorld(Game); }
public static void CreateFX(SharpDX.XAudio2.XAudio2 device, System.Guid clsid, SharpDX.ComObject effectRef) { #if !WINDOWS_UWP if (device.Version == XAudio2Version.Version27) { var clsid15 = clsid; if (clsid15 == CLSID_FXEcho) { clsid15 = CLSID_FXEcho_15; } else if (clsid15 == CLSID_FXEQ) { clsid15 = CLSID_FXEQ_15; } else if (clsid15 == CLSID_FXMasteringLimiter) { clsid15 = CLSID_FXMasteringLimiter_15; } else if (clsid15 == CLSID_FXReverb) { clsid15 = CLSID_FXReverb_15; } IntPtr nativePtr; var result = (Result)CreateFX15(ref clsid15, out nativePtr); if (result.Success) { effectRef.NativePointer = nativePtr; return; } } #endif if (device.Version == XAudio2Version.Version28) { CreateFX28(clsid, effectRef, IntPtr.Zero, 0); } #if WINDOWS_UWP else if (device.Version == XAudio2Version.Version29) { CreateFX29(clsid, effectRef, IntPtr.Zero, 0); } #endif else { throw new NotSupportedException(string.Format("XAudio2 Version [{0}] is not supported for this effect", device.Version)); } }
// 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); } } }
public PlayForm() { InitializeComponent(); // Initalize XAudio2 xaudio2 = new XAudio2(XAudio2Flags.None, ProcessorSpecifier.DefaultProcessor); masteringVoice = new MasteringVoice(xaudio2); var waveFormat = new WaveFormat(44100, 32, 2); sourceVoice = new SourceVoice(xaudio2, waveFormat); int bufferSize = waveFormat.ConvertLatencyToByteSize(60000); DataStream dataStream = new DataStream(bufferSize, true, true); // Prepare the initial sound to modulate int numberOfSamples = bufferSize / waveFormat.BlockAlign; for (int i = 0; i < numberOfSamples; i++) { float value = (float)(Math.Cos(2 * Math.PI * 220.0 * i / waveFormat.SampleRate) * 0.5); dataStream.Write(value); dataStream.Write(value); } dataStream.Position = 0; audioBuffer = new AudioBuffer { Stream = dataStream, Flags = BufferFlags.EndOfStream, AudioBytes = bufferSize, LoopBegin = 0, LoopLength = numberOfSamples, LoopCount = AudioBuffer.LoopInfinite }; // Set the effect on the source ModulatorEffect = new ModulatorEffect(); modulatorDescriptor = new EffectDescriptor(ModulatorEffect); reverb = new Reverb(xaudio2); effectDescriptor = new EffectDescriptor(reverb); //sourceVoice.SetEffectChain(modulatorDescriptor, effectDescriptor); sourceVoice.SetEffectChain(modulatorDescriptor); //sourceVoice.EnableEffect(0); this.Closed += new EventHandler(PlayForm_Closed); }
protected SourceVoice CreateVoice(SharpDX.XAudio2.XAudio2 device, string fileName) { using (var stream = new SoundStream(File.OpenRead(fileName))) { _format = stream.Format; _buffer = new AudioBuffer { Stream = stream.ToDataStream(), AudioBytes = (int)stream.Length, Flags = BufferFlags.EndOfStream }; _packetsInfo = stream.DecodedPacketsInfo; } var sourceVoice = new SourceVoice(device, _format, true); return(sourceVoice); }
static void Main(string[] args) { XAudio2 audioDevice = new XAudio2(); Console.WriteLine("Device count: " + audioDevice.DeviceCount); for (int indexOfDevice = 0; indexOfDevice < audioDevice.DeviceCount; indexOfDevice++) { DeviceDetails deviceDetails = audioDevice.GetDeviceDetails(indexOfDevice); Console.WriteLine("DeviceID: " + deviceDetails.DeviceID); Console.WriteLine("Device Name: " + deviceDetails.DisplayName); Console.WriteLine("Output format:" + deviceDetails.OutputFormat); Console.WriteLine("Role: " + deviceDetails.Role); Console.WriteLine(); } MasteringVoice masteringVoice = new MasteringVoice(audioDevice); Console.WriteLine("Volume: " + masteringVoice.Volume); Console.ReadKey(); }
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(); }
protected SourceVoice CreateVoice(SharpDX.XAudio2.XAudio2 device, string fileName) { fileName = fileName.Replace("/", "\\"); var file = Package.Current.InstalledLocation.GetFileAsync(fileName).Await(); var streamWithContentType = file.OpenReadAsync().Await(); var st = streamWithContentType.AsStreamForRead(); using (var stream = new SoundStream(st)) { _format = stream.Format; _buffer = new AudioBuffer { Stream = stream.ToDataStream(), AudioBytes = (int)stream.Length, Flags = BufferFlags.EndOfStream }; _packetsInfo = stream.DecodedPacketsInfo; } var sourceVoice = new SourceVoice(device, _format, true); return(sourceVoice); }
//static int dev_ind = 0; public void Init(int dev, int ch) { xa_sou = new SharpDX.XAudio2.XAudio2(SharpDX.XAudio2.XAudio2Version.Version27); //if (dev >= xa_sou.DeviceCount) //{ MessageBox.Show("device_max:" + (xa_sou.DeviceCount - 1).ToString() + " select is:" // + dev + "\r\nError Restart device 0"); dev_ind = 0; } //else { dev_ind = dev; } switch (ch) { case 21: ch = 3; break; case 51: ch = 6; break; } //var xa_mas = new SharpDX.XAudio2.MasteringVoice(xa_sou, ch, 48000, dev_ind); var xa_mas = new SharpDX.XAudio2.MasteringVoice(xa_sou, ch, 48000); xa_mas.Dispose(); mus_start.Clear(); }
/// <summary> /// Creates and configures a source voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat"/> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat"/> have a <see cref="SharpDX.Multimedia.WaveFormat"/> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat"/> structure and use it as the value for pSourceFormat. </param> /// <param name="flags">[in] Flags that specify the behavior of the source voice. A flag can be 0 or a combination of one or more of the following: ValueDescriptionXAUDIO2_VOICE_NOPITCHNo pitch control is available on the voice.?XAUDIO2_VOICE_NOSRCNo sample rate conversion is available on the voice, the voice's outputs must have the same sample rate.Note The XAUDIO2_VOICE_NOSRC flag causes the voice to behave as though the XAUDIO2_VOICE_NOPITCH flag also is specified. ?XAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.?XAUDIO2_VOICE_MUSICThe voice is used to play background music. The system automatically can replace the voice with music selected by the user.? </param> /// <param name="maxFrequencyRatio">[in] Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between XAUDIO2_MIN_FREQ_RATIO and XAUDIO2_MAX_FREQ_RATIO. Subsequent calls to <see cref="SharpDX.XAudio2.SourceVoice.SetFrequencyRatio"/> are clamped between XAUDIO2_MIN_FREQ_RATIO and MaxFrequencyRatio. The maximum value for this argument is defined as XAUDIO2_MAX_FREQ_RATIO, which allows pitch to be raised by up to 10 octaves. If MaxFrequencyRatio is less than 1.0, the voice will use that ratio immediately after being created (rather than the default of 1.0). Xbox 360 For XMA voices there is an additional restriction on the MaxFrequencyRatio argument and the voice's sample rate. The product of these two numbers cannot exceed XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO for one-channel voices or XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL for voices with any other number of channels. If the value specified for MaxFrequencyRatio is too high for the specified format, the call to CreateSourceVoice fails and produces a debug message. Note XAudio2's memory usage can be reduced by using the lowest possible MaxFrequencyRatio value. </param> /// <param name="callback">[in, optional] Pointer to a client-provided callback interface, <see cref="SharpDX.XAudio2.VoiceCallback"/>. </param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, float maxFrequencyRatio, VoiceCallback callback) : this(device, sourceFormat, flags, maxFrequencyRatio, callback, null) { }
/// <summary> /// Creates and configures a source voice with callback through delegates. /// </summary> /// <param name="device">an instance of <see cref="SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat" /> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat" /> have a <see cref="SharpDX.Multimedia.WaveFormat" /> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat" /> structure and use it as the value for pSourceFormat.</param> /// <param name="flags">[in] Flags that specify the behavior of the source voice. A flag can be 0 or a combination of one or more of the following: ValueDescriptionXAUDIO2_VOICE_NOPITCHNo pitch control is available on the voice.?XAUDIO2_VOICE_NOSRCNo sample rate conversion is available on the voice, the voice's outputs must have the same sample rate.Note The XAUDIO2_VOICE_NOSRC flag causes the voice to behave as though the XAUDIO2_VOICE_NOPITCH flag also is specified. ?XAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.?XAUDIO2_VOICE_MUSICThe voice is used to play background music. The system automatically can replace the voice with music selected by the user.?</param> /// <param name="maxFrequencyRatio">[in] Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between XAUDIO2_MIN_FREQ_RATIO and XAUDIO2_MAX_FREQ_RATIO. Subsequent calls to <see cref="SharpDX.XAudio2.SourceVoice.SetFrequencyRatio" /> are clamped between XAUDIO2_MIN_FREQ_RATIO and MaxFrequencyRatio. The maximum value for this argument is defined as XAUDIO2_MAX_FREQ_RATIO, which allows pitch to be raised by up to 10 octaves. If MaxFrequencyRatio is less than 1.0, the voice will use that ratio immediately after being created (rather than the default of 1.0). Xbox 360 For XMA voices there is an additional restriction on the MaxFrequencyRatio argument and the voice's sample rate. The product of these two numbers cannot exceed XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO for one-channel voices or XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL for voices with any other number of channels. If the value specified for MaxFrequencyRatio is too high for the specified format, the call to CreateSourceVoice fails and produces a debug message. Note XAudio2's memory usage can be reduced by using the lowest possible MaxFrequencyRatio value.</param> /// <param name="enableCallbackEvents">if set to <c>true</c> [enable callback events].</param> /// <returns>No enableCallbackEvents.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, float maxFrequencyRatio, bool enableCallbackEvents) : this(device, sourceFormat, flags, maxFrequencyRatio, enableCallbackEvents, null) { }
public XSoundManager() { XAudio2 = new SharpDX.XAudio2.XAudio2(); MasteringVoice = new MasteringVoice(XAudio2); }
/// <summary> /// Creates and configures a source voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat"/> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat"/> have a <see cref="SharpDX.Multimedia.WaveFormat"/> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat"/> structure and use it as the value for pSourceFormat. </param> /// <param name="flags">[in] Flags that specify the behavior of the source voice. A flag can be 0 or a combination of one or more of the following: ValueDescriptionXAUDIO2_VOICE_NOPITCHNo pitch control is available on the voice.?XAUDIO2_VOICE_NOSRCNo sample rate conversion is available on the voice, the voice's outputs must have the same sample rate.Note The XAUDIO2_VOICE_NOSRC flag causes the voice to behave as though the XAUDIO2_VOICE_NOPITCH flag also is specified. ?XAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.?XAUDIO2_VOICE_MUSICThe voice is used to play background music. The system automatically can replace the voice with music selected by the user.? </param> /// <param name="maxFrequencyRatio">[in] Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between XAUDIO2_MIN_FREQ_RATIO and XAUDIO2_MAX_FREQ_RATIO. Subsequent calls to <see cref="SharpDX.XAudio2.SourceVoice.SetFrequencyRatio"/> are clamped between XAUDIO2_MIN_FREQ_RATIO and MaxFrequencyRatio. The maximum value for this argument is defined as XAUDIO2_MAX_FREQ_RATIO, which allows pitch to be raised by up to 10 octaves. If MaxFrequencyRatio is less than 1.0, the voice will use that ratio immediately after being created (rather than the default of 1.0). Xbox 360 For XMA voices there is an additional restriction on the MaxFrequencyRatio argument and the voice's sample rate. The product of these two numbers cannot exceed XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO for one-channel voices or XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL for voices with any other number of channels. If the value specified for MaxFrequencyRatio is too high for the specified format, the call to CreateSourceVoice fails and produces a debug message. Note XAudio2's memory usage can be reduced by using the lowest possible MaxFrequencyRatio value. </param> /// <param name="callback">[in, optional] Pointer to a client-provided callback interface, <see cref="SharpDX.XAudio2.VoiceCallback"/>. </param> /// <param name="effectDescriptors">[in, optional] Pointer to a list of XAUDIO2_EFFECT_CHAIN structures that describe an effect chain to use in the source voice.</param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, float maxFrequencyRatio, VoiceCallback callback, EffectDescriptor[] effectDescriptors) : base(IntPtr.Zero) { CreateSourceVoice(device, sourceFormat, flags, maxFrequencyRatio, callback == null ? IntPtr.Zero : VoiceShadow.ToIntPtr(callback), effectDescriptors); }
/// <summary> /// Creates and configures a source voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat"/> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat"/> have a <see cref="SharpDX.Multimedia.WaveFormat"/> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat"/> structure and use it as the value for pSourceFormat. </param> /// <param name="flags">[in] Flags that specify the behavior of the source voice. A flag can be 0 or a combination of one or more of the following: ValueDescriptionXAUDIO2_VOICE_NOPITCHNo pitch control is available on the voice.?XAUDIO2_VOICE_NOSRCNo sample rate conversion is available on the voice, the voice's outputs must have the same sample rate.Note The XAUDIO2_VOICE_NOSRC flag causes the voice to behave as though the XAUDIO2_VOICE_NOPITCH flag also is specified. ?XAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.?XAUDIO2_VOICE_MUSICThe voice is used to play background music. The system automatically can replace the voice with music selected by the user.? </param> /// <param name="maxFrequencyRatio">[in] Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between XAUDIO2_MIN_FREQ_RATIO and XAUDIO2_MAX_FREQ_RATIO. Subsequent calls to <see cref="SharpDX.XAudio2.SourceVoice.SetFrequencyRatio"/> are clamped between XAUDIO2_MIN_FREQ_RATIO and MaxFrequencyRatio. The maximum value for this argument is defined as XAUDIO2_MAX_FREQ_RATIO, which allows pitch to be raised by up to 10 octaves. If MaxFrequencyRatio is less than 1.0, the voice will use that ratio immediately after being created (rather than the default of 1.0). Xbox 360 For XMA voices there is an additional restriction on the MaxFrequencyRatio argument and the voice's sample rate. The product of these two numbers cannot exceed XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO for one-channel voices or XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL for voices with any other number of channels. If the value specified for MaxFrequencyRatio is too high for the specified format, the call to CreateSourceVoice fails and produces a debug message. Note XAudio2's memory usage can be reduced by using the lowest possible MaxFrequencyRatio value. </param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, float maxFrequencyRatio) : this(device, sourceFormat, flags, maxFrequencyRatio, true) { }
public static void Play(string fileName) { if (!Music.Stopped && Music.m_FileName == fileName) { return; } if (Music.m_XAudio2 == null) { MediaFactory.Startup(131184, 1); Music.m_XAudio2 = new SharpDX.XAudio2.XAudio2(); Music.m_XAudio2.StartEngine(); Music.m_MasteringVoice = new MasteringVoice(Music.m_XAudio2, 0, 0, 0); Music.m_AudioDecoder = new AudioDecoder(); Music.m_PlayingTask = Task.Factory.StartNew(new System.Action(Music.PlayAsync), TaskCreationOptions.LongRunning); } string path = Engine.FileManager.ResolveMUL(string.Format("music/{0}", (object)fileName)); if (!File.Exists(path)) { return; } if (!Music.Stopped) { Music.Stop(); } Music.m_FileName = fileName; Music.m_FileStream = new NativeFileStream(path, (NativeFileMode)3, 0, (NativeFileShare)1); Music.m_AudioDecoder.SetSourceStream((Stream)Music.m_FileStream); if (Music.m_SourceVoice == null) { Music.m_SourceVoice = new SourceVoice(Music.m_XAudio2, Music.m_AudioDecoder.WaveFormat); Music.m_SourceVoice.BufferEnd += (new System.Action <IntPtr>(Music.SourceVoice_BufferEnd)); } Music.m_SourceVoice.Start(); Music.m_AudioBuffers = new AudioBuffer[3]; Music.m_MemoryBuffers = new DataPointer[Music.m_AudioBuffers.Length]; for (int index = 0; index < Music.m_AudioBuffers.Length; ++index) { Music.m_AudioBuffers[index] = new AudioBuffer(); Music.m_MemoryBuffers[index].Size = 32768; Music.m_MemoryBuffers[index].Pointer = Utilities.AllocateMemory((int)Music.m_MemoryBuffers[index].Size, 16); } PlayUO.Volume volume = Preferences.Current.Music.Volume; if (volume != null && volume.Mute) { return; } if (volume != null) { ((Voice)Music.m_SourceVoice).SetVolume(1f, 0); } bool flag = false; if (Music.Stopped) { ++Music.m_PlayCounter; Music.m_WaitForPlayToOutput.Reset(); flag = true; } else { Music.m_Clock.Start(); } Music.m_State = (PMediaPlayerState)2; Music.m_PlayEvent.Set(); if (!flag) { return; } Music.m_WaitForPlayToOutput.WaitOne(); }
/// <summary> /// Creates and configures a submix voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels in the input audio data of the submix voice. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. </param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of submix voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. </param> /// <param name="flags">[in] Flags that specify the behavior of the submix voice. Can be 0 or the following: ValueDescriptionXAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.? </param> /// <param name="processingStage">[in] An arbitrary number that specifies when this voice is processed with respect to other submix voices, if the XAudio2 engine is running other submix voices. The voice is processed after all other voices that include a smaller ProcessingStage value, and before all other voices that include a larger ProcessingStage value. Voices that include the same ProcessingStage value are processed in any order. A submix voice cannot send to another submix voice with a lower or equal ProcessingStage value; this prevents audio being lost due to a submix cycle. </param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSubmixVoice([Out] IXAudio2SubmixVoice** ppSubmixVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 ProcessingStage,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SubmixVoice(XAudio2 device, int inputChannels, int inputSampleRate, SubmixVoiceFlags flags, int processingStage) : base(IntPtr.Zero) { device.CreateSubmixVoice(this, inputChannels, inputSampleRate, flags, processingStage, null, null); }
/// <summary> /// Creates and configures a source voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat"/> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat"/> have a <see cref="SharpDX.Multimedia.WaveFormat"/> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat"/> structure and use it as the value for pSourceFormat. </param> /// <param name="flags">[in] Flags that specify the behavior of the source voice. A flag can be 0 or a combination of one or more of the following: ValueDescriptionXAUDIO2_VOICE_NOPITCHNo pitch control is available on the voice.?XAUDIO2_VOICE_NOSRCNo sample rate conversion is available on the voice, the voice's outputs must have the same sample rate.Note The XAUDIO2_VOICE_NOSRC flag causes the voice to behave as though the XAUDIO2_VOICE_NOPITCH flag also is specified. ?XAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.?XAUDIO2_VOICE_MUSICThe voice is used to play background music. The system automatically can replace the voice with music selected by the user.? </param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags) : this(device, sourceFormat, flags, true) { }
/// <summary> /// Creates and configures a mastering voice on the default audio device. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels the mastering voice expects in its input audio. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. InputChannels can be set to XAUDIO2_DEFAULT_CHANNELS, with the default being determined by the current platform. Windows Attempts to detect the system speaker configuration setup. Xbox 360 Defaults to 5.1 surround. </param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of the mastering voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. InputSampleRate can be set to XAUDIO2_DEFAULT_SAMPLERATE, with the default being determined by the current platform. Windows Windows XP defaults to 44100. Windows Vista and Windows 7 default to the setting specified in the Sound Control Panel. The default for this setting is 44100 (or 48000 if required by the driver). Xbox 360 Defaults to 48000. </param> /// <unmanaged>HRESULT IXAudio2::CreateSubmixVoice([Out] IXAudio2SubmixVoice** ppSubmixVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 DeviceIndex,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SubmixVoice(XAudio2 device, int inputChannels, int inputSampleRate) : this(device, inputChannels, inputSampleRate, SubmixVoiceFlags.None, 0) { }
/// <summary>Initializes a new instance of the <see cref="T:Gorgon.Examples.AudioPlayback"/> class.</summary> public AudioPlayback() { _audio = new Xa.XAudio2(); _masterVoice = new Xa.MasteringVoice(_audio); }
/// <summary> /// Creates and configures a mastering voice (Valid only for XAudio2.7) /// </summary> /// <param name="device">an instance of <see cref="SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels the mastering voice expects in its input audio. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. InputChannels can be set to XAUDIO2_DEFAULT_CHANNELS, with the default being determined by the current platform. Windows Attempts to detect the system speaker configuration setup. Xbox 360 Defaults to 5.1 surround.</param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of the mastering voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. InputSampleRate can be set to XAUDIO2_DEFAULT_SAMPLERATE, with the default being determined by the current platform. Windows Windows XP defaults to 44100. Windows Vista and Windows 7 default to the setting specified in the Sound Control Panel. The default for this setting is 44100 (or 48000 if required by the driver). Xbox 360 Defaults to 48000.</param> /// <param name="deviceIndex">Index of the device.</param> /// <unmanaged>HRESULT IXAudio2::CreateMasteringVoice([Out] IXAudio2MasteringVoice** ppMasteringVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 DeviceIndex,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public MasteringVoice(XAudio2 device, int inputChannels, int inputSampleRate, int deviceIndex) : base(device) { device.CheckVersion27(); device.CreateMasteringVoice27(this, inputChannels, inputSampleRate, 0, deviceIndex, null); }
/// <summary> /// Creates and configures a source voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat"/> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat"/> have a <see cref="SharpDX.Multimedia.WaveFormat"/> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat"/> structure and use it as the value for pSourceFormat. </param> /// <param name="flags">[in] Flags that specify the behavior of the source voice. A flag can be 0 or a combination of one or more of the following: ValueDescriptionXAUDIO2_VOICE_NOPITCHNo pitch control is available on the voice.?XAUDIO2_VOICE_NOSRCNo sample rate conversion is available on the voice, the voice's outputs must have the same sample rate.Note The XAUDIO2_VOICE_NOSRC flag causes the voice to behave as though the XAUDIO2_VOICE_NOPITCH flag also is specified. ?XAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.?XAUDIO2_VOICE_MUSICThe voice is used to play background music. The system automatically can replace the voice with music selected by the user.? </param> /// <param name="enableCallbackEvents">True to enable delegate callbacks on this instance. Default is false</param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, bool enableCallbackEvents) : this(device, sourceFormat, flags, 1.0f, enableCallbackEvents) { }
public EngineCallbackImpl(XAudio2 xAudio2) { XAudio2 = xAudio2; }
public MasteringVoice(XAudio2 device, int inputChannels = 0, int inputSampleRate = 0, int deviceIndex = 0) : base(IntPtr.Zero) { device.CreateMasteringVoice(this, inputChannels, inputSampleRate, 0, deviceIndex, null); }
/// <summary> /// Creates and configures a mastering voice on the default audio device, with stereo channels at 44100Hz. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <unmanaged>HRESULT IXAudio2::CreateSubmixVoice([Out] IXAudio2SubmixVoice** ppSubmixVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 DeviceIndex,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SubmixVoice(XAudio2 device) : this(device, 2) { }
/// <summary> /// Creates and configures a mastering voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels the mastering voice expects in its input audio. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. InputChannels can be set to XAUDIO2_DEFAULT_CHANNELS, with the default being determined by the current platform. Windows Attempts to detect the system speaker configuration setup. Xbox 360 Defaults to 5.1 surround. </param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of the mastering voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. InputSampleRate can be set to XAUDIO2_DEFAULT_SAMPLERATE, with the default being determined by the current platform. Windows Windows XP defaults to 44100. Windows Vista and Windows 7 default to the setting specified in the Sound Control Panel. The default for this setting is 44100 (or 48000 if required by the driver). Xbox 360 Defaults to 48000. </param> /// <param name="deviceIndex">[in] Index of the output device that will be sent input by the mastering voice. Specifying the default value of 0 causes XAudio2 to select the global default audio device. </param> /// <unmanaged>HRESULT IXAudio2::CreateMasteringVoice([Out] IXAudio2MasteringVoice** ppMasteringVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 DeviceIndex,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> #if DIRECTX11_1 public MasteringVoice(XAudio2 device, int inputChannels = 2, int inputSampleRate = 44100, string deviceId = null) : base(IntPtr.Zero) { device.CreateMasteringVoice(this, inputChannels, inputSampleRate, 0, deviceId, null, AudioStreamCategory.GameEffects); }
/// <summary> /// Creates and configures a mastering voice (Valid only for XAudio2.8) /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels the mastering voice expects in its input audio. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. InputChannels can be set to XAUDIO2_DEFAULT_CHANNELS, with the default being determined by the current platform. Windows Attempts to detect the system speaker configuration setup. Xbox 360 Defaults to 5.1 surround. </param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of the mastering voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. InputSampleRate can be set to XAUDIO2_DEFAULT_SAMPLERATE, with the default being determined by the current platform. Windows Windows XP defaults to 44100. Windows Vista and Windows 7 default to the setting specified in the Sound Control Panel. The default for this setting is 44100 (or 48000 if required by the driver). Xbox 360 Defaults to 48000. </param> /// <param name="deviceId">[in] Index of the output device that will be sent input by the mastering voice. Specifying the default value of 0 causes XAudio2 to select the global default audio device. </param> /// <unmanaged>HRESULT IXAudio2::CreateMasteringVoice([Out] IXAudio2MasteringVoice** ppMasteringVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 DeviceIndex,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public MasteringVoice(XAudio2 device, int inputChannels, int inputSampleRate, string deviceId) : base(device) { device.CreateMasteringVoice(this, inputChannels, inputSampleRate, 0, deviceId, null, AudioStreamCategory.GameEffects); }
protected Voice(XAudio2 device) : base(IntPtr.Zero) { this.device = device; }
/// <summary> /// Creates and configures a source voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat"/> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat"/> have a <see cref="SharpDX.Multimedia.WaveFormat"/> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat"/> structure and use it as the value for pSourceFormat. </param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat) : this(device, sourceFormat, true) { }
/// <summary> /// Creates and configures a source voice with callback through delegates. /// </summary> /// <param name="device">an instance of <see cref="SharpDX.XAudio2.XAudio2" /></param> /// <param name="sourceFormat">[in] Pointer to a <see cref="SharpDX.Multimedia.WaveFormat" /> structure. This structure contains the expected format for all audio buffers submitted to the source voice. XAudio2 supports voice types of PCM, xWMA, ADPCM (Windows only), and XMA (Xbox 360 only). XAudio2 supports the following PCM formats. 8-bit (unsigned) integer PCM 16-bit integer PCM (Optimal format for XAudio2) 20-bit integer PCM (either in 24 or 32 bit containers) 24-bit integer PCM (either in 24 or 32 bit containers) 32-bit integer PCM 32-bit float PCM (Preferred format after 16-bit integer) The number of channels in a source voice must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. The sample rate of a source voice must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. Note Data formats such as XMA, {{ADPCM}}, and {{xWMA}} that require more information than provided by <see cref="SharpDX.Multimedia.WaveFormat" /> have a <see cref="SharpDX.Multimedia.WaveFormat" /> structure as the first member in their format structure. When creating a source voice with one of those formats cast the format's structure as a <see cref="SharpDX.Multimedia.WaveFormat" /> structure and use it as the value for pSourceFormat.</param> /// <param name="flags">[in] Flags that specify the behavior of the source voice. A flag can be 0 or a combination of one or more of the following: ValueDescriptionXAUDIO2_VOICE_NOPITCHNo pitch control is available on the voice.?XAUDIO2_VOICE_NOSRCNo sample rate conversion is available on the voice, the voice's outputs must have the same sample rate.Note The XAUDIO2_VOICE_NOSRC flag causes the voice to behave as though the XAUDIO2_VOICE_NOPITCH flag also is specified. ?XAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.?XAUDIO2_VOICE_MUSICThe voice is used to play background music. The system automatically can replace the voice with music selected by the user.?</param> /// <param name="maxFrequencyRatio">[in] Highest allowable frequency ratio that can be set on this voice. The value for this argument must be between XAUDIO2_MIN_FREQ_RATIO and XAUDIO2_MAX_FREQ_RATIO. Subsequent calls to <see cref="SharpDX.XAudio2.SourceVoice.SetFrequencyRatio" /> are clamped between XAUDIO2_MIN_FREQ_RATIO and MaxFrequencyRatio. The maximum value for this argument is defined as XAUDIO2_MAX_FREQ_RATIO, which allows pitch to be raised by up to 10 octaves. If MaxFrequencyRatio is less than 1.0, the voice will use that ratio immediately after being created (rather than the default of 1.0). Xbox 360 For XMA voices there is an additional restriction on the MaxFrequencyRatio argument and the voice's sample rate. The product of these two numbers cannot exceed XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MONO for one-channel voices or XAUDIO2_MAX_RATIO_TIMES_RATE_XMA_MULTICHANNEL for voices with any other number of channels. If the value specified for MaxFrequencyRatio is too high for the specified format, the call to CreateSourceVoice fails and produces a debug message. Note XAudio2's memory usage can be reduced by using the lowest possible MaxFrequencyRatio value.</param> /// <param name="enableCallbackEvents">if set to <c>true</c> [enable callback events].</param> /// <param name="effectDescriptors">[in, optional] Pointer to a list of XAUDIO2_EFFECT_CHAIN structures that describe an effect chain to use in the source voice.</param> /// <returns>No enableCallbackEvents.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSourceVoice([Out] IXAudio2SourceVoice** ppSourceVoice,[In] const WAVEFORMATEX* pSourceFormat,[None] UINT32 Flags,[None] float MaxFrequencyRatio,[In, Optional] IXAudio2VoiceCallback* pCallback,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SourceVoice(XAudio2 device, SharpDX.Multimedia.WaveFormat sourceFormat, SharpDX.XAudio2.VoiceFlags flags, float maxFrequencyRatio, bool enableCallbackEvents, EffectDescriptor[] effectDescriptors) : base(IntPtr.Zero) { CreateSourceVoice(device, sourceFormat, flags, maxFrequencyRatio, enableCallbackEvents ? VoiceShadow.ToIntPtr(voiceCallbackImpl = new VoiceCallbackImpl(this)) : IntPtr.Zero, effectDescriptors); }
/// <summary> /// Creates and configures a mastering voice on the default audio device and 44100Hz. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels the mastering voice expects in its input audio. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. InputChannels can be set to XAUDIO2_DEFAULT_CHANNELS, with the default being determined by the current platform. Windows Attempts to detect the system speaker configuration setup. Xbox 360 Defaults to 5.1 surround. </param> /// <unmanaged>HRESULT IXAudio2::CreateSubmixVoice([Out] IXAudio2SubmixVoice** ppSubmixVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 DeviceIndex,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SubmixVoice(XAudio2 device, int inputChannels) : this(device, 2, 44100) { }
/// <summary> /// Creates and configures a submix voice. /// </summary> /// <param name="device">an instance of <see cref = "SharpDX.XAudio2.XAudio2" /></param> /// <param name="inputChannels">[in] Number of channels in the input audio data of the submix voice. InputChannels must be less than or equal to XAUDIO2_MAX_AUDIO_CHANNELS. </param> /// <param name="inputSampleRate">[in] Sample rate of the input audio data of submix voice. This rate must be a multiple of XAUDIO2_QUANTUM_DENOMINATOR. InputSampleRate must be between XAUDIO2_MIN_SAMPLE_RATE and XAUDIO2_MAX_SAMPLE_RATE. </param> /// <param name="flags">[in] Flags that specify the behavior of the submix voice. Can be 0 or the following: ValueDescriptionXAUDIO2_VOICE_USEFILTERThe filter effect should be available on this voice.? </param> /// <param name="processingStage">[in] An arbitrary number that specifies when this voice is processed with respect to other submix voices, if the XAudio2 engine is running other submix voices. The voice is processed after all other voices that include a smaller ProcessingStage value, and before all other voices that include a larger ProcessingStage value. Voices that include the same ProcessingStage value are processed in any order. A submix voice cannot send to another submix voice with a lower or equal ProcessingStage value; this prevents audio being lost due to a submix cycle. </param> /// <returns>No documentation.</returns> /// <unmanaged>HRESULT IXAudio2::CreateSubmixVoice([Out] IXAudio2SubmixVoice** ppSubmixVoice,[None] UINT32 InputChannels,[None] UINT32 InputSampleRate,[None] UINT32 Flags,[None] UINT32 ProcessingStage,[In, Optional] const XAUDIO2_VOICE_SENDS* pSendList,[In, Optional] const XAUDIO2_EFFECT_CHAIN* pEffectChain)</unmanaged> public SubmixVoice(XAudio2 device, int inputChannels, int inputSampleRate, SubmixVoiceFlags flags, int processingStage) : this(device, inputChannels, inputSampleRate, flags, processingStage, null) { }
/// <summary> /// Initialize the media element for playback /// </summary> /// <param name="streamConfig">Object containing stream configuration details</param> void InitializeMediaPlayer(MoonlightStreamConfiguration streamConfig, AvStreamSource streamSource) { this._streamSource = streamSource; // This code is based upon the MS FFmpegInterop project on GitHub VideoEncodingProperties videoProps = VideoEncodingProperties.CreateH264(); videoProps.ProfileId = H264ProfileIds.High; videoProps.Width = (uint)streamConfig.GetWidth(); videoProps.Height = (uint)streamConfig.GetHeight(); videoProps.Bitrate = (uint)streamConfig.GetBitrate(); _videoMss = new MediaStreamSource(new VideoStreamDescriptor(videoProps)); _videoMss.BufferTime = TimeSpan.Zero; _videoMss.CanSeek = false; _videoMss.Duration = TimeSpan.Zero; _videoMss.SampleRequested += _videoMss_SampleRequested; XAudio2 xaudio = new XAudio2(); MasteringVoice masteringVoice = new MasteringVoice(xaudio, 2, 48000); WaveFormat format = new WaveFormat(48000, 16, 2); // Set for low latency playback StreamDisplay.RealTimePlayback = true; // Render on the full window to avoid extra compositing StreamDisplay.IsFullWindow = true; // Disable built-in transport controls StreamDisplay.AreTransportControlsEnabled = false; StreamDisplay.SetMediaStreamSource(_videoMss); AvStream.SetSourceVoice(new SourceVoice(xaudio, format)); }