public void 初期化する( CSCore.CoreAudioAPI.AudioClientShareMode 共有モード, double 希望更新間隔sec = 0.015 )
{
+ FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
+
int hr = 0;
lock( this.スレッド間同期 )
this.bs_AudioClock = CSCore.CoreAudioAPI.AudioClock.FromAudioClient( this.AudioClient );
//-----------------
#endregion
-
- #region " ミキサーを生成し初期化する。"
+ #region " エンドポイントバッファを無音で埋めておく。"
//-----------------
- this.Mixer = new Mixer();
- this.Mixer.初期化する( this.更新間隔sample );
+ this.AudioRenderClient.GetBuffer( this.更新間隔sample );
+
+ // 無音を書き込んだことにして、バッファをコミット。(GetBuffer の戻り値は使わない。)
+ this.AudioRenderClient.ReleaseBuffer( this.更新間隔sample, CSCore.CoreAudioAPI.AudioClientBufferFlags.Silent );
//-----------------
#endregion
- #region " 最初のエンドポイントバッファを無音で埋めておく。"
- //-----------------
- var bufferPtr = this.AudioRenderClient.GetBuffer( this.更新間隔sample );
- // 無音を書き込んだことにして、バッファをコミット。(bufferPrtは使わない。)
- this.AudioRenderClient.ReleaseBuffer( this.更新間隔sample, CSCore.CoreAudioAPI.AudioClientBufferFlags.Silent );
+ #region " ミキサーを生成し初期化する。"
+ //-----------------
+ this.Mixer = new Mixer( this.更新間隔sample );
//-----------------
#endregion
#region " ワークキューとイベントを作成し、作業項目を登録する。"
//-----------------
- // MediaFoundation が管理する、プロセス&MMCSSタスクごとに1つずつ作ることができる特別な共有ワークキューを取得、または生成して取得する。
+ // MediaFoundation が管理する、プロセス&MMCSSタスクごとに1つずつ作ることができる特別な共有ワークキューを取得(または生成して取得)する。
int dwTaskId = 0;
- SharpDX.MediaFoundation.MediaFactory.LockSharedWorkQueue(
- ( 0.011 > this.更新間隔sec ) ? "Pro Audio" : "Games", 0, ref dwTaskId, out this.QueueID );
+ SharpDX.MediaFoundation.MediaFactory.LockSharedWorkQueue( ( 0.011 > this.更新間隔sec ) ? "Pro Audio" : "Games", 0, ref dwTaskId, out this.QueueID );
// エンドポイントバッファからの出力要請イベントを作成し、AudioClient に登録する。
this.出力要請イベント = CreateEvent( IntPtr.Zero, false, false, "WASAPI出力要請イベント" );
this.AudioClient.SetEventHandle( this.出力要請イベント );
// コールバックを作成し、ワークキューに最初の作業項目を登録する。
- this.出力要請イベントのコールバック = new MFAsyncCallback( this.QueueID, ( ar ) => {
- this.出力要請イベントへ対応する( ar );
- } );
- //-----------------
- #endregion
- #region " 最初の作業項目を追加する。"
- //-----------------
+ this.出力要請イベントのコールバック = new MFAsyncCallback( this.QueueID, this.出力要請イベントへ対応する );
this.作業項目をキューに格納する();
//-----------------
#endregion
//-----------------
#endregion
}
+
+ FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
}
public void Dispose()
{
+ FDK.Log.BeginInfo( $"{FDK.Utilities.現在のメソッド名}" );
+
Trace.Assert( false == this.Dispose済み );
#region " WASAPI作業項目を終了させる。オーディオのレンダリングを止める前に行うこと。"
FDK.Utilities.解放する( ref this.出力要請イベントのコールバック );
if( IntPtr.Zero != this.出力要請イベント )
- CloseHandle( this.出力要請イベント );
+ Device.CloseHandle( this.出力要請イベント );
//-----------------
#endregion
this.Dispose済み = true;
}
- FDK.Log.Info( "WASAPIクライアントを終了しました。" );
+ FDK.Log.EndInfo( $"{FDK.Utilities.現在のメソッド名}" );
}
public void サウンドをミキサーに追加する( Sound sound )
{
public Mixer()
{
}
+ public Mixer( int エンドポイントバッファサイズsample ) : this()
+ {
+ this.初期化する( エンドポイントバッファサイズsample );
+ }
public void 初期化する( int エンドポイントバッファサイズsample )
{
- lock( this.排他利用 )
+ lock( this.スレッド間同期 )
{
if( エンドポイントバッファサイズsample == this.エンドポイントバッファサイズsample )
return; // サイズに変更があったときのみ初期化する。
}
public void Dispose()
{
- lock( this.排他利用 )
+ lock( this.スレッド間同期 )
{
this.サウンドリスト.Clear();
if( null != this.合成用バッファ )
}
public void サウンドリストをクリアする()
{
- lock( this.排他利用 )
+ lock( this.スレッド間同期 )
{
this.サウンドリスト.Clear();
}
}
public void サウンドを追加する( Sound sound )
{
- lock( this.排他利用 )
+ lock( this.スレッド間同期 )
{
this.サウンドリスト.Add( sound );
}
}
public void サウンドを削除する( Sound sound )
{
- lock( this.排他利用 )
+ lock( this.スレッド間同期 )
{
this.サウンドリスト.Remove( sound );
}
}
public CSCore.CoreAudioAPI.AudioClientBufferFlags エンドポイントへ出力する( void* エンドポイントの出力先, int 出力数sample )
{
- lock( this.排他利用 )
+ lock( this.スレッド間同期 )
{
if( null == this.合成用バッファ )
return CSCore.CoreAudioAPI.AudioClientBufferFlags.Silent;
private int エンドポイントバッファサイズsample = -1;
private readonly List<Sound> サウンドリスト = new List<Sound>();
private void* 合成用バッファ = null;
- private readonly object 排他利用 = new object();
+ private readonly object スレッド間同期 = new object();
}
}