OSDN Git Service

#31237 WASAPIのバッファ量設定の自動化。
authoryyagi <yyagi@16f42ceb-6dc6-49c8-ba94-f2d53467949d>
Sun, 28 Apr 2013 05:48:51 +0000 (05:48 +0000)
committeryyagi <yyagi@16f42ceb-6dc6-49c8-ba94-f2d53467949d>
Sun, 28 Apr 2013 05:48:51 +0000 (05:48 +0000)
#xxxxx GPUフラッシュ周りのコードのリファクタ。(#ifdefで整理しただけ)
#xxxxx フレーム描画間のsleep()位置の変更。(デフォルトの設定ではこのsleep()は実行されないので注意)

git-svn-id: http://svn.osdn.jp/svnroot/dtxmania/trunk@549 16f42ceb-6dc6-49c8-ba94-f2d53467949d

DTXManiaプロジェクト/DTXManiaプロジェクト.csproj
DTXManiaプロジェクト/コード/ステージ/04.コンフィグ/CActConfigList.cs
DTXManiaプロジェクト/コード/全体/CConfigIni.cs
DTXManiaプロジェクト/コード/全体/CDTXMania.cs
FDK17プロジェクト/コード/03.サウンド/CSound.cs
FDK17プロジェクト/コード/03.サウンド/CSoundDeviceWASAPI.cs
実行時フォルダ(DTXCreator)/FDK.dll
実行時フォルダ/DTXManiaGR.exe
実行時フォルダ/FDK.dll

index 29fb2bf..d6e54f9 100644 (file)
@@ -39,7 +39,7 @@
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">\r
     <DebugSymbols>true</DebugSymbols>\r
     <OutputPath>bin\x86\Debug\</OutputPath>\r
-    <DefineConstants>TRACE;DEBUG;TEST_ENGLISH_ TEST_Direct3D9Ex_ WindowedFullscreen</DefineConstants>\r
+    <DefineConstants>TRACE;DEBUG;_TEST_ENGLISH_ TEST_Direct3D9Ex_ _WindowedFullscreen</DefineConstants>\r
     <DebugType>full</DebugType>\r
     <PlatformTarget>x86</PlatformTarget>\r
     <ErrorReport>prompt</ErrorReport>\r
@@ -49,7 +49,7 @@
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">\r
     <OutputPath>bin\x86\Release\</OutputPath>\r
-    <DefineConstants>TRACE;TEST_ENGLISH_ TEST_Direct3D9Ex_</DefineConstants>\r
+    <DefineConstants>TRACE;TEST_ENGLISH_ TEST_Direct3D9Ex_ _WindowedFullscreen</DefineConstants>\r
     <Optimize>true</Optimize>\r
     <DebugType>pdbonly</DebugType>\r
     <PlatformTarget>x86</PlatformTarget>\r
index ce4b7fb..50715db 100644 (file)
@@ -268,26 +268,26 @@ namespace DTXMania
                        this.list項目リスト.Add(this.iSystemSoundType);\r
 \r
                        // #24820 2013.1.15 yyagi\r
-                       this.iSystemWASAPIBufferSizeMs = new CItemInteger( "WASAPIBufSize", 0, 99999, CDTXMania.ConfigIni.nWASAPIBufferSizeMs,\r
-                               "WASAPI使用時のバッファサイズ:\n" +\r
-                               "0~99999ms を指定可能です。\n" +\r
-                               "0を指定すると、OSがバッファの\n" +\r
-                               "サイズを自動設定します。\n" +\r
-                               "値を小さくするほど発音ラグが\n" +\r
-                               "減少しますが、音割れや異常動作を\n" +\r
-                               "引き起こす場合があります。\n" +\r
-                               "※ 設定はCONFIGURATION画面の\n" +\r
-                               " 終了時に有効になります。",\r
-                               "Sound buffer size for WASAPI:\n" +\r
-                               "You can set from 0 to 99999ms.\n" +\r
-                               "Set 0 to use a default sysytem\n" +\r
-                               "buffer size.\n" +\r
-                               "Smaller value makes smaller lag,\n" +\r
-                               "but it may cause sound troubles.\n" +\r
-                               "\n" +\r
-                               "Note: Exit CONFIGURATION to make\n" +\r
-                               "     the setting take effect." );\r
-                       this.list項目リスト.Add( this.iSystemWASAPIBufferSizeMs );\r
+                       //this.iSystemWASAPIBufferSizeMs = new CItemInteger( "WASAPIBufSize", 0, 99999, CDTXMania.ConfigIni.nWASAPIBufferSizeMs,\r
+                       //    "WASAPI使用時のバッファサイズ:\n" +\r
+                       //    "0~99999ms を指定可能です。\n" +\r
+                       //    "0を指定すると、OSがバッファの\n" +\r
+                       //    "サイズを自動設定します。\n" +\r
+                       //    "値を小さくするほど発音ラグが\n" +\r
+                       //    "減少しますが、音割れや異常動作を\n" +\r
+                       //    "引き起こす場合があります。\n" +\r
+                       //    "※ 設定はCONFIGURATION画面の\n" +\r
+                       //    " 終了時に有効になります。",\r
+                       //    "Sound buffer size for WASAPI:\n" +\r
+                       //    "You can set from 0 to 99999ms.\n" +\r
+                       //    "Set 0 to use a default sysytem\n" +\r
+                       //    "buffer size.\n" +\r
+                       //    "Smaller value makes smaller lag,\n" +\r
+                       //    "but it may cause sound troubles.\n" +\r
+                       //    "\n" +\r
+                       //    "Note: Exit CONFIGURATION to make\n" +\r
+                       //    "     the setting take effect." );\r
+                       //this.list項目リスト.Add( this.iSystemWASAPIBufferSizeMs );\r
 \r
                        // #24820 2013.1.17 yyagi\r
                        string[] asiodevs = CEnumerateAllAsioDevices.GetAllASIODevices();\r
@@ -1501,7 +1501,7 @@ namespace DTXMania
                        this.ct三角矢印アニメ = new CCounter();\r
 \r
                        this.iSystemSoundType_initial                   = this.iSystemSoundType.n現在選択されている項目番号;       // CONFIGに入ったときの値を保持しておく\r
-                       this.iSystemWASAPIBufferSizeMs_initial  = this.iSystemWASAPIBufferSizeMs.n現在の値;                         // CONFIG脱出時にこの値から変更されているようなら\r
+                       // this.iSystemWASAPIBufferSizeMs_initial       = this.iSystemWASAPIBufferSizeMs.n現在の値;                         // CONFIG脱出時にこの値から変更されているようなら\r
                        this.iSystemASIOBufferSizeMs_initial    = this.iSystemASIOBufferSizeMs.n現在の値;                           // サウンドデバイスを再構築する\r
                        this.iSystemASIODevice_initial                  = this.iSystemASIODevice.n現在選択されている項目番号;      //\r
                        base.On活性化();\r
@@ -1526,7 +1526,7 @@ namespace DTXMania
                        // #24820 2013.1.22 yyagi CONFIGでWASAPI/ASIO/DirectSound関連の設定を変更した場合、サウンドデバイスを再構築する。\r
                        #region [ サウンドデバイス変更 ]\r
                        if ( this.iSystemSoundType_initial != this.iSystemSoundType.n現在選択されている項目番号 ||\r
-                               this.iSystemWASAPIBufferSizeMs_initial != this.iSystemWASAPIBufferSizeMs.n現在の値 ||\r
+                               // this.iSystemWASAPIBufferSizeMs_initial != this.iSystemWASAPIBufferSizeMs.n現在の値 ||\r
                                this.iSystemASIOBufferSizeMs_initial != this.iSystemASIOBufferSizeMs.n現在の値 ||\r
                                this.iSystemASIODevice_initial != this.iSystemASIODevice.n現在選択されている項目番号 )\r
                        {\r
@@ -1548,7 +1548,8 @@ namespace DTXMania
                                }\r
 \r
                                FDK.CSound管理.t初期化( soundDeviceType,\r
-                                                                               this.iSystemWASAPIBufferSizeMs.n現在の値,\r
+                                                                               0,\r
+                                                                               // this.iSystemWASAPIBufferSizeMs.n現在の値,\r
                                                                                this.iSystemASIOBufferSizeMs.n現在の値,\r
                                                                                this.iSystemASIODevice.n現在選択されている項目番号 );\r
                                CDTXMania.app.AddSoundTypeToWindowTitle();\r
@@ -1963,12 +1964,12 @@ namespace DTXMania
                private CItemToggle iSystemBufferedInput;\r
                private CItemInteger iSystemRisky;                                      // #23559 2011.7.27 yyagi\r
                private CItemList iSystemSoundType;                                     // #24820 2013.1.3 yyagi\r
-               private CItemInteger iSystemWASAPIBufferSizeMs;         // #24820 2013.1.15 yyagi\r
+//             private CItemInteger iSystemWASAPIBufferSizeMs;         // #24820 2013.1.15 yyagi\r
                private CItemInteger iSystemASIOBufferSizeMs;           // #24820 2013.1.3 yyagi\r
                private CItemList       iSystemASIODevice;                              // #24820 2013.1.17 yyagi\r
 \r
                private int iSystemSoundType_initial;\r
-               private int iSystemWASAPIBufferSizeMs_initial;\r
+//             private int iSystemWASAPIBufferSizeMs_initial;\r
                private int iSystemASIOBufferSizeMs_initial;\r
                private int iSystemASIODevice_initial;\r
 \r
@@ -2170,7 +2171,7 @@ namespace DTXMania
                        CDTXMania.ConfigIni.bUseBoxDefSkin = this.iSystemUseBoxDefSkin.bON;                                                             // #28195 2012.5.6 yyagi\r
 \r
                        CDTXMania.ConfigIni.nSoundDeviceType = this.iSystemSoundType.n現在選択されている項目番号;          // #24820 2013.1.3 yyagi\r
-                       CDTXMania.ConfigIni.nWASAPIBufferSizeMs = this.iSystemWASAPIBufferSizeMs.n現在の値;                         // #24820 2013.1.15 yyagi\r
+//                     CDTXMania.ConfigIni.nWASAPIBufferSizeMs = this.iSystemWASAPIBufferSizeMs.n現在の値;                         // #24820 2013.1.15 yyagi\r
                        CDTXMania.ConfigIni.nASIOBufferSizeMs = this.iSystemASIOBufferSizeMs.n現在の値;                                     // #24820 2013.1.3 yyagi\r
                        CDTXMania.ConfigIni.nASIODevice = this.iSystemASIODevice.n現在選択されている項目番号;                      // #24820 2013.1.17 yyagi\r
 \r
index 351ecdf..bb37899 100644 (file)
@@ -661,7 +661,7 @@ namespace DTXMania
                }\r
                public STAUTOPLAY bAutoPlay;\r
                public int nSoundDeviceType;                            // #24820 2012.12.23 yyagi 出力サウンドデバイス(0=ACM(にしたいが設計がきつそうならDirectShow), 1=ASIO, 2=WASAPI)\r
-               public int nWASAPIBufferSizeMs;                         // #24820 2013.1.15 yyagi WASAPIのバッファサイズ\r
+//             public int nWASAPIBufferSizeMs;                         // #24820 2013.1.15 yyagi WASAPIのバッファサイズ\r
                public int nASIOBufferSizeMs;                           // #24820 2012.12.28 yyagi ASIOのバッファサイズ\r
                public int nASIODevice;                                         // #24820 2013.1.17 yyagi ASIOデバイス\r
                public bool bDynamicBassMixerManagement;        // #24820\r
@@ -1148,7 +1148,7 @@ namespace DTXMania
                        this.bUseBoxDefSkin = true;                                     // #28195 2012.5.6 yyagi box.defによるスキン切替機能を使用するか否か\r
                        this.bTight = false;                        // #29500 2012.9.11 kairera0467 TIGHTモード\r
                        this.nSoundDeviceType = (int) ESoundDeviceTypeForConfig.ACM;    // #24820 2012.12.23 yyagi 初期値はACM\r
-                       this.nWASAPIBufferSizeMs = 0;                           // #24820 2013.1.15 yyagi 初期値は0(自動設定)\r
+//                     this.nWASAPIBufferSizeMs = 0;                           // #24820 2013.1.15 yyagi 初期値は0(自動設定)\r
                        this.nASIODevice = 0;                                           // #24820 2013.1.17 yyagi\r
                        this.nASIOBufferSizeMs = 0;                                     // #24820 2012.12.25 yyagi 初期値は0(自動設定)\r
                        this.bDynamicBassMixerManagement = true;        //\r
@@ -1295,12 +1295,12 @@ namespace DTXMania
                        sw.WriteLine( "SoundDeviceType={0}", (int) this.nSoundDeviceType );\r
                        sw.WriteLine();\r
 \r
-                       sw.WriteLine( "; WASAPI使用時のサウンドバッファサイズ" );\r
-                       sw.WriteLine( "; (0=デバイスに設定されている値を使用, 1~9999=バッファサイズ(単位:ms)の手動指定" );\r
-                       sw.WriteLine( "; WASAPI Sound Buffer Size." );\r
-                       sw.WriteLine( "; (0=Use system default buffer size, 1-9999=specify the buffer size(ms) by yourself)" );\r
-                       sw.WriteLine( "WASAPIBufferSizeMs={0}", (int) this.nWASAPIBufferSizeMs );\r
-                       sw.WriteLine();\r
+                       //sw.WriteLine( "; WASAPI使用時のサウンドバッファサイズ" );\r
+                       //sw.WriteLine( "; (0=デバイスに設定されている値を使用, 1~9999=バッファサイズ(単位:ms)の手動指定" );\r
+                       //sw.WriteLine( "; WASAPI Sound Buffer Size." );\r
+                       //sw.WriteLine( "; (0=Use system default buffer size, 1-9999=specify the buffer size(ms) by yourself)" );\r
+                       //sw.WriteLine( "WASAPIBufferSizeMs={0}", (int) this.nWASAPIBufferSizeMs );\r
+                       //sw.WriteLine();\r
 \r
                        sw.WriteLine( "; ASIO使用時のサウンドデバイス" );\r
                        sw.WriteLine( "; 存在しないデバイスを指定すると、DTXManiaが起動しないことがあります。" );\r
@@ -2066,10 +2066,10 @@ namespace DTXMania
                                                                                        {\r
                                                                                                this.nSoundDeviceType = C変換.n値を文字列から取得して範囲内に丸めて返す( str4, 0, 2, this.nSoundDeviceType );\r
                                                                                        }\r
-                                                                                       else if ( str3.Equals( "WASAPIBufferSizeMs" ) )\r
-                                                                                       {\r
-                                                                                               this.nWASAPIBufferSizeMs = C変換.n値を文字列から取得して範囲内に丸めて返す( str4, 0, 9999, this.nWASAPIBufferSizeMs );\r
-                                                                                       }\r
+                                                                                       //else if ( str3.Equals( "WASAPIBufferSizeMs" ) )\r
+                                                                                       //{\r
+                                                                                       //    this.nWASAPIBufferSizeMs = C変換.n値を文字列から取得して範囲内に丸めて返す( str4, 0, 9999, this.nWASAPIBufferSizeMs );\r
+                                                                                       //}\r
                                                                                        else if ( str3.Equals( "ASIODevice" ) )\r
                                                                                        {\r
                                                                                                string[] asiodev = CEnumerateAllAsioDevices.GetAllASIODevices();\r
index f6579e2..804e326 100644 (file)
@@ -412,7 +412,17 @@ namespace DTXMania
                                st.plugin.OnManagedリソースの作成();\r
                                Directory.SetCurrentDirectory( CDTXMania.strEXEのあるフォルダ );\r
                        }\r
+#if GPUFlushAfterPresent\r
+                       FrameEnd += dtxmania_FrameEnd;\r
+#endif\r
+               }\r
+#if GPUFlushAfterPresent\r
+               void dtxmania_FrameEnd( object sender, EventArgs e )    // GraphicsDeviceManager.game_FrameEnd()後に実行される\r
+               {                                                                                                               // → Present()直後にGPUをFlushする\r
+                                                                                                                               // → 画面のカクツキが頻発したため、ここでのFlushは行わない\r
+                       actFlushGPU.On進行描画();           // Flush GPU\r
                }\r
+#endif\r
                protected override void LoadContent()\r
                {\r
                        if ( ConfigIni.bウィンドウモード )\r
@@ -509,6 +519,14 @@ namespace DTXMania
                        if ( this.bApplicationActive )  // DTXMania本体起動中の本体/モニタの省電力モード移行を抑止\r
                                CPowerManagement.tDisableMonitorSuspend();\r
 \r
+                       // #xxxxx 2013.4.8 yyagi; sleepの挿入位置を、EndScnene~Present間から、BeginScene前に移動。描画遅延を小さくするため。\r
+                       #region [ スリープ ]\r
+                       if ( ConfigIni.nフレーム毎スリープms >= 0 )                    // #xxxxx 2011.11.27 yyagi\r
+                       {\r
+                               Thread.Sleep( ConfigIni.nフレーム毎スリープms );\r
+                       }\r
+                       #endregion\r
+\r
                        this.Device.BeginScene();\r
                        this.Device.Clear( ClearFlags.ZBuffer | ClearFlags.Target, Color.Black, 1f, 0 );\r
 \r
@@ -1336,9 +1354,11 @@ for (int i = 0; i < 3; i++) {
                                                break;\r
                                }\r
                        }\r
-                       this.Device.EndScene();\r
-                       //actFlushGPU.On進行描画();         // Flush GPU\r
-\r
+                       this.Device.EndScene();                 // Present()は game.csのOnFrameEnd()に登録された、GraphicsDeviceManager.game_FrameEnd() 内で実行されるので不要\r
+                                                                                       // (つまり、Present()は、Draw()完了後に実行される)\r
+#if !GPUFlushAfterPresent\r
+                       actFlushGPU.On進行描画();           // Flush GPU    // EndScene()~Present()間 (つまりVSync前) でFlush実行\r
+#endif\r
                        #region [ 全画面・ウインドウ切り替え ]\r
                        if ( this.b次のタイミングで全画面・ウィンドウ切り替えを行う )\r
                        {\r
@@ -1363,12 +1383,6 @@ for (int i = 0; i < 3; i++) {
                                }\r
                        }\r
                        #endregion\r
-                       #region [ スリープ ]\r
-                       if ( ConfigIni.nフレーム毎スリープms >= 0 )                    // #xxxxx 2011.11.27 yyagi\r
-                       {\r
-                               Thread.Sleep( ConfigIni.nフレーム毎スリープms );\r
-                       }\r
-                       #endregion\r
                }\r
 \r
                // その他\r
@@ -1798,7 +1812,8 @@ for (int i = 0; i < 3; i++) {
                                }\r
                                Sound管理 = new CSound管理( base.Window.Handle,\r
                                                                                        soundDeviceType,\r
-                                                                                       CDTXMania.ConfigIni.nWASAPIBufferSizeMs,\r
+                                                                                       // CDTXMania.ConfigIni.nWASAPIBufferSizeMs,\r
+                                                                                       0,\r
                                                                                        CDTXMania.ConfigIni.nASIOBufferSizeMs,\r
                                                                                        CDTXMania.ConfigIni.nASIODevice\r
                                );\r
index e454f18..a297393 100644 (file)
@@ -47,6 +47,7 @@ namespace FDK
                #region [ WASAPI/ASIO/DirectSound設定値 ]\r
                /// <summary>\r
                /// <para>WASAPI 排他モード出力における再生遅延[ms](の希望値)。最終的にはこの数値を基にドライバが決定する)。</para>\r
+               /// <para>→ WASAPI初期化時に自動設定するようにしたため、ここで設定した値は使用しないようになった。</para>\r
                /// </summary>\r
                public static int SoundDelayExclusiveWASAPI = 0;                // SSTでは、50ms\r
                public int GetSoundExclusiveWASAPI()\r
@@ -63,7 +64,7 @@ namespace FDK
                public static int SoundDelaySharedWASAPI = 100;\r
                /// <summary>\r
                /// <para>排他WASAPIバッファの更新間隔。出力間隔ではないので注意。</para>\r
-               /// <para>SoundDelay よりも小さい値であること。(小さすぎる場合はBASSによって自動修正される。)</para>\r
+               /// <para>→ 自動設定されるのでSoundDelay よりも小さい値であること。(小さすぎる場合はBASSによって自動修正される。)</para>\r
                /// </summary>\r
                public static int SoundUpdatePeriodExclusiveWASAPI = 6;\r
                /// <summary>\r
index 973733b..58a6255 100644 (file)
@@ -50,6 +50,12 @@ namespace FDK
 \r
                // メソッド\r
 \r
+               /// <summary>\r
+               /// WASAPIの初期化\r
+               /// </summary>\r
+               /// <param name="mode"></param>\r
+               /// <param name="n希望バッファサイズms">(未使用; 本メソッド内で自動設定する)</param>\r
+               /// <param name="n更新間隔ms">(未使用; 本メソッド内で自動設定する)</param>\r
                public CSoundDeviceWASAPI( Eデバイスモード mode, long n希望バッファサイズms, long n更新間隔ms )\r
                {\r
                        // 初期化。\r
@@ -140,6 +146,7 @@ namespace FDK
                                // Trace.TraceInformation( "Selected Default WASAPI Device: {0}", deviceInfo.name );\r
                                // Trace.TraceInformation( "MinPeriod={0}, DefaultPeriod={1}", deviceInfo.minperiod, deviceInfo.defperiod );\r
                                n更新間隔ms = (long) ( deviceInfo.minperiod * 1000 );\r
+                               n希望バッファサイズms = n更新間隔ms + 1;   // 2013.4.25 #31237 yyagi; バッファサイズ設定の完全自動化。更新間隔=バッファサイズにするとBASS_ERROR_UNKNOWNになるので+1する。\r
                        }\r
                        else\r
                        {\r
index 3700194..89771c5 100644 (file)
Binary files a/実行時フォルダ(DTXCreator)/FDK.dll and b/実行時フォルダ(DTXCreator)/FDK.dll differ
index 18bc3f4..d6bd200 100644 (file)
Binary files a/実行時フォルダ/DTXManiaGR.exe and b/実行時フォルダ/DTXManiaGR.exe differ
index 3700194..89771c5 100644 (file)
Binary files a/実行時フォルダ/FDK.dll and b/実行時フォルダ/FDK.dll differ