예제 #1
0
        /// <summary>
        /// Init the output audio device
        /// </summary>
        /// <param name="waveProvider">waveProvider interface</param>
        public async Task Init(IWaveProvider waveProvider)
        {
            if (this.device == null)
            {
                // try our hardest to get a divice if the string is null or empty
                await GetDefaultAudioEndpoint();

                NativeMethods.WaitForSingleObjectEx(initSync, 1000, true);
            }

            if (this.device != null)
            {
                try
                {
                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                  async() =>
                    {
                        try
                        {
                            this.EventWriterDLL.BuildLine("+1 start => WasapiOutRT::Init2 => called");

                            this.renderWaveFormat = waveProvider.WaveFormat;
                            await Activate();

                            this.EventWriterDLL.BuildLine("+8 start => WasapiOutRT::Init2 => resampler not needed");
                            this.sourceProvider = waveProvider;

                            // Get the RenderClient
                            this.audioRenderClient = audioClient.AudioRenderClient;

                            this.waitingForInitToFinish = false;

                            this.EventWriterDLL.BuildLine("+9 start => WasapiOutRT::Init2 => finished");
                        }
                        catch (Exception ex)
                        {
                            this.EventWriterDLL.WriteLine(Utils.EventWriterDLL.SeverityTypes.Error, 0x01, "WasapiOutRT::Init2 => Exception: " + ex.Message);
                        }
                    });
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception in WasapiOutRT, waveProvider = " + waveProvider.ToString() + ", " + ex.Message);
                    this.EventWriterDLL.WriteLine(EventWriterDLL.SeverityTypes.Error, 0x01, "WasapiOutRT::Init2 => waveProvider = " + waveProvider.ToString() + ", exception: " + ex.Message);
                }
            }
        }