OSDN Git Service

#37271 TimeStretch=OFFの時に限り、ミキシング負荷を従来の半分にした。
[dtxmania/dtxmania.git] / FDK17プロジェクト / コード / 03.サウンド / CSound.cs
index f455658..5ea1acc 100644 (file)
@@ -48,50 +48,6 @@ namespace FDK
                        {\r
                                return _nMasterVolume;\r
                        }\r
-                       //get\r
-                       //{\r
-                       //    if ( SoundDeviceType == ESoundDeviceType.ExclusiveWASAPI || SoundDeviceType == ESoundDeviceType.ASIO )\r
-                       //    {\r
-                       //        return Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_GVOL_STREAM ) / 100;\r
-                       //    }\r
-                       //    else\r
-                       //    {\r
-                       //        return 100;\r
-                       //    }\r
-                       //}\r
-                       //set\r
-                       //{\r
-                       //    if ( SoundDeviceType == ESoundDeviceType.ExclusiveWASAPI )\r
-                       //    {\r
-                       //                      // LINEARでなくWINDOWS(2)を使う必要があるが、exclusive時は使用不可、またデバイス側が対応してないと使用不可\r
-                       //        bool b = BassWasapi.BASS_WASAPI_SetVolume( BASSWASAPIVolume.BASS_WASAPI_CURVE_LINEAR, value / 100.0f );\r
-                       //        if ( !b )\r
-                       //        {\r
-                       //            BASSError be = Bass.BASS_ErrorGetCode();\r
-                       //            Trace.TraceInformation( "WASAPI Master Volume Set Error: " + be.ToString() );\r
-                       //        }\r
-                       //    }\r
-                       //}\r
-                       //set\r
-                       //{\r
-                       //    if ( SoundDeviceType == ESoundDeviceType.ExclusiveWASAPI || SoundDeviceType == ESoundDeviceType.ASIO )\r
-                       //    {\r
-                       //        bool b = Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_GVOL_STREAM, value * 100 );\r
-                       //        if ( !b )\r
-                       //        {\r
-                       //            BASSError be = Bass.BASS_ErrorGetCode();\r
-                       //            Trace.TraceInformation( "Master Volume Set Error: " + be.ToString() );\r
-                       //        }\r
-                       //    }\r
-                       //}\r
-                       //set\r
-                       //{\r
-                       //    if ( SoundDeviceType == ESoundDeviceType.ExclusiveWASAPI || SoundDeviceType == ESoundDeviceType.ASIO )\r
-                       //    {\r
-                       //        var nodes = new BASS_MIXER_NODE[ 1 ] { new BASS_MIXER_NODE( 0, (float) value ) };\r
-                       //        BassMix.BASS_Mixer_ChannelSetEnvelope( SoundDevice.hMixer, BASSMIXEnvelope.BASS_MIXER_ENV_VOL, nodes );\r
-                       //    }\r
-                       //}\r
                        set\r
                        {\r
                                SoundDevice.nMasterVolume = value;\r
@@ -729,8 +685,7 @@ namespace FDK
                        CSound clone = (CSound) MemberwiseClone();      // これだけだとCY連打が途切れる&タイトルに戻る際にNullRef例外発生\r
                        this.DirectSound.DuplicateSoundBuffer( this.Buffer, out clone.Buffer );\r
 \r
-                       // CSound.listインスタンス.Add( this );                   // インスタンスリストに登録。\r
-                       // 本来これを加えるべきだが、Add後Removeできなくなっている。Clone()の仕方の問題であろう。\r
+                       CSound.listインスタンス.Add( clone );                     // インスタンスリストに登録。\r
 \r
                        return clone;\r
                }\r
@@ -758,6 +713,7 @@ namespace FDK
                {\r
                        this.e作成方法 = E作成方法.ファイルから;\r
                        this.strファイル名 = strファイル名;\r
+\r
                        if ( String.Compare( Path.GetExtension( strファイル名 ), ".xa", true ) == 0 ||\r
                                 String.Compare( Path.GetExtension( strファイル名 ), ".mp3", true ) == 0 ||\r
                                 String.Compare( Path.GetExtension( strファイル名 ), ".ogg", true ) == 0 ) // caselessで文字列比較\r
@@ -1197,29 +1153,25 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
                }\r
                public void t再生位置を変更する( long n位置ms )\r
                {\r
-                       if( this.bBASSサウンドである )\r
+                       if ( this.bBASSサウンドである )\r
                        {\r
                                bool b = true;\r
                                try\r
                                {\r
                                        b = BassMix.BASS_Mixer_ChannelSetPosition( this.hBassStream, Bass.BASS_ChannelSeconds2Bytes( this.hBassStream, n位置ms * this.db周波数倍率 * this.db再生速度 / 1000.0 ), BASSMode.BASS_POS_BYTES );\r
                                }\r
-                               catch( Exception e )\r
+                               catch ( Exception e )\r
                                {\r
-                                       Trace.TraceInformation( Path.GetFileName( this.strファイル名 ) + ": Seek error: " + e.ToString() + ": " + n位置ms + "ms" );\r
+                                       Trace.TraceInformation( Path.GetFileName( this.strファイル名 ) + ": Seek error: " + e.ToString() );\r
                                }\r
                                finally\r
                                {\r
                                        if ( !b )\r
                                        {\r
                                                BASSError be = Bass.BASS_ErrorGetCode();\r
-                                               Trace.TraceInformation( Path.GetFileName( this.strファイル名 ) + ": Seek error: " + be.ToString() + ": " + n位置ms + "MS" );\r
+                                               Trace.TraceInformation( Path.GetFileName( this.strファイル名 ) + ": Seek error: " + be.ToString() );\r
                                        }\r
                                }\r
-                               //if ( this.n総演奏時間ms > 5000 )\r
-                               //{\r
-                               //    Trace.TraceInformation( Path.GetFileName( this.strファイル名 ) + ": Seeked to " + n位置ms + "ms = " + Bass.BASS_ChannelSeconds2Bytes( this.hBassStream, n位置ms * this.db周波数倍率 * this.db再生速度 / 1000.0 ) );\r
-                               //}\r
                        }\r
                        else if( this.bDirectSoundである )\r
                        {\r
@@ -1232,37 +1184,9 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
                                {\r
                                        Trace.TraceError( "{0}: Seek error: {1}", Path.GetFileName( this.strファイル名 ), n位置ms, e.Message );\r
                                }\r
-                               //if ( this.n総演奏時間ms > 5000 )\r
-                               //{\r
-                               //    Trace.TraceInformation( Path.GetFileName( this.strファイル名 ) + ": Seeked to " + n位置ms + "ms = " + n位置sample );\r
-                               //}\r
-                       }\r
-               }\r
-               /// <summary>\r
-               /// デバッグ用\r
-               /// </summary>\r
-               /// <param name="n位置byte"></param>\r
-               /// <param name="db位置ms"></param>\r
-               public void t再生位置を取得する( out long n位置byte, out double db位置ms )\r
-               {\r
-                       if ( this.bBASSサウンドである )\r
-                       {\r
-                               n位置byte = BassMix.BASS_Mixer_ChannelGetPosition( this.hBassStream );\r
-                               db位置ms = Bass.BASS_ChannelBytes2Seconds( this.hBassStream, n位置byte );\r
-                       }\r
-                       else if ( this.bDirectSoundである )\r
-                       {\r
-                               n位置byte = this.Buffer.CurrentPlayPosition;\r
-                               db位置ms = n位置byte / this.Buffer.Format.SamplesPerSecond / 0.001 / _db周波数倍率 / _db再生速度;\r
-                       }\r
-                       else\r
-                       {\r
-                               n位置byte = 0;\r
-                               db位置ms = 0.0;\r
                        }\r
                }\r
 \r
-\r
                public static void tすべてのサウンドを初期状態に戻す()\r
                {\r
                        foreach ( var sound in CSound.listインスタンス )\r
@@ -1499,7 +1423,7 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
 \r
                                default:\r
                                        break;\r
-                       }\r
+                               }\r
                        #endregion\r
 \r
                        this.e作成方法 = E作成方法.ファイルから;\r
@@ -1533,7 +1457,6 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
        \r
                        tBASSサウンドを作成する・ストリーム生成後の共通処理( hMixer );\r
                }\r
-\r
                /// <summary>\r
                /// Decode "RIFF chunked Vorbis" to "raw wave"\r
                /// because BASE.DLL has two problems for RIFF chunked Vorbis;\r
@@ -1552,8 +1475,8 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
                        {\r
                                using ( var ws = new WaveStream( strファイル名 ) )\r
                                {\r
-                                       if ( ws.Format.FormatTag == (WaveFormatTag) 0x6770 ||   // Ogg Vorbis Mode 2+\r
-                                                ws.Format.FormatTag == (WaveFormatTag) 0x6771 )        // Ogg Vorbis Mode 3+\r
+                                       if ( ws.Format.FormatTag == ( WaveFormatTag ) 0x6770 || // Ogg Vorbis Mode 2+\r
+                                                ws.Format.FormatTag == ( WaveFormatTag ) 0x6771 )      // Ogg Vorbis Mode 3+\r
                                        {\r
                                                Trace.TraceInformation( Path.GetFileName( strファイル名 ) + ": RIFF chunked Vorbis. Decode to raw Wave first, to avoid BASS.DLL troubles" );\r
                                                try\r
@@ -1573,7 +1496,7 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
                                // DirectShowのデコードに失敗したら、次はACMでのデコードを試すことになるため、ここではエラーログを出さない。\r
                                // Trace.TraceWarning( "Warning: " + Path.GetFileName( strファイル名 ) + " : デコードに失敗しました。" );\r
                        }\r
-                       catch ( Exception )\r
+                       catch ( Exception )\r
                        {\r
                                Trace.TraceWarning( "Warning: " + Path.GetFileName( strファイル名 ) + " : 読み込みに失敗しました。" );\r
                        }\r
@@ -1581,7 +1504,6 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
 \r
                        return bファイルにVorbisコンテナが含まれている;\r
                }\r
-\r
                private void tBASSサウンドを作成するXA( string strファイル名, int hMixer, BASSFlag flags )\r
                {\r
                        int nPCMデータの先頭インデックス;\r
@@ -1625,7 +1547,8 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
 \r
                        // 個々のストリームの出力をテンポ変更のストリームに入力する。テンポ変更ストリームの出力を、Mixerに出力する。\r
 \r
-//                     if ( CSound管理.bIsTimeStretch )      // TimeStretchのON/OFFに関わりなく、テンポ変更のストリームを生成する。後からON/OFF切り替え可能とするため。\r
+                       _hTempoStream = 0;\r
+                       if ( CSound管理.bIsTimeStretch )      // TimeStretchのON/OFFに関わりなく、テンポ変更のストリームを生成する。後からON/OFF切り替え可能とするため。\r
                        {\r
                                this._hTempoStream = BassFx.BASS_FX_TempoCreate( this._hBassStream, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_FX_FREESOURCE );\r
                                if ( this._hTempoStream == 0 )\r