private static int AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED = unchecked((int) 0x88890019);
// for SoundTimer
- public CSCore.CoreAudioAPI.AudioClock AudioClock
- => this.bs_AudioClock;
+ public CSCore.CoreAudioAPI.AudioClock AudioClock => this.bs_AudioClock;
public ExclusiveDevice()
{
//SharpDX.MediaFoundation.MediaFactory.CancelWorkItem( this.出力要請イベントキャンセル用キー ); --> コールバックの実行中にキャンセルしてしまうと NullReference例外
this.出力終了通知.状態 = 同期.TriStateEvent.状態種別.ON;
this.出力終了通知.OFFになるまでブロックする();
+ FDK.Log.Info( "WASAPI出力処理を終了しました。" );
}
//-----------------
#endregion
{
#region " オーディオのレンダリングを停止する。"
//-----------------
- if( null != this.AudioClient )
- this.AudioClient.Stop();
+ this.AudioClient?.Stop();
//-----------------
#endregion
-
#region " ミキサー(とサウンドリスト)は現状を維持する。"
//-----------------
//-----------------
#endregion
}
+
+ FDK.Log.Info( "WASAPIクライアントを終了しました。" );
}
public void サウンドをミキサーに追加する( Sound sound )
{
{
// グローバルリソース (static)
public static SST.フォルダ フォルダ => StrokeStyleT.bs_フォルダ;
+ public static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice Wasapiデバイス => StrokeStyleT.bs_Wasapiデバイス;
+ public static Random 乱数 => StrokeStyleT.bs_乱数;
// get only static property の初期化。
static StrokeStyleT()
this.Text = $"StrokeStyle<T> {System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
this.ClientSize = new System.Drawing.Size( 640, 480 ); // 初期サイズ
+ #region " System.Stopwatch が高解像度タイマを使わないならエラー。"
+ //-----------------
+ if( false == System.Diagnostics.Stopwatch.IsHighResolution )
+ throw new SSTException( "このシステムは、高解像度タイマをサポートしていません。" );
+ //-----------------
+ #endregion
+ #region " MediaFoundation を起動する。"
+ //-----------------
+ SharpDX.MediaFoundation.MediaManager.Startup();
+ //-----------------
+ #endregion
+ #region " Sleep 精度を上げる。"
+ //-----------------
+ StrokeStyleT.timeBeginPeriod( 1 );
+ //-----------------
+ #endregion
+
+ #region " WASAPI デバイスを初期化する。"
+ //----------------
+ StrokeStyleT.bs_Wasapiデバイス = new FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice();
+ StrokeStyleT.bs_Wasapiデバイス.初期化する( 7.0f );
+ //----------------
+ #endregion
+
this.KeyDown += ( target, arg ) => {
// Esc → アプリ終了。
if( arg.KeyCode == System.Windows.Forms.Keys.Escape )
public override void 終了する()
{
Debug.Assert( null == this.デバイスリソース ); // 解放された後である。
+
+ #region " WASAPIデバイスを解放する。"
+ //----------------
+ FDK.Utilities.解放する( ref StrokeStyleT.bs_Wasapiデバイス );
+ //----------------
+ #endregion
+ #region " MediaFoundation を終了する。"
+ //-----------------
+ SharpDX.MediaFoundation.MediaManager.Shutdown();
+ //-----------------
+ #endregion
}
public override void シーンを描画する()
{
#region " バックストア。"
//----------------
private static SST.フォルダ bs_フォルダ = null;
+ private static FDK.メディア.サウンド.WASAPI排他.ExclusiveDevice bs_Wasapiデバイス = null;
+ private static readonly Random bs_乱数 = new Random( DateTime.Now.Millisecond );
//----------------
#endregion
+
+ #region " Win32 API "
+ //-----------------
+ [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeBeginPeriod" )]
+ private static extern uint timeBeginPeriod( uint uMilliseconds );
+
+ [System.Runtime.InteropServices.DllImport( "winmm.dll", EntryPoint = "timeEndPeriod" )]
+ private static extern uint timeEndPeriod( uint uMilliseconds );
+ //-----------------
+ #endregion
}
}