OSDN Git Service

#24820 XA対応。ただし、再生できるXAとできないXAがある模様。
authoryyagi <yyagi@16f42ceb-6dc6-49c8-ba94-f2d53467949d>
Sat, 22 Dec 2012 16:03:02 +0000 (16:03 +0000)
committeryyagi <yyagi@16f42ceb-6dc6-49c8-ba94-f2d53467949d>
Sat, 22 Dec 2012 16:03:02 +0000 (16:03 +0000)
git-svn-id: http://svn.osdn.jp/svnroot/dtxmania/branches/120724(DTXMania%20with%20%2324820)@468 16f42ceb-6dc6-49c8-ba94-f2d53467949d

FDK17プロジェクト/コード/03.サウンド/CSound.cs
実行時フォルダ/DTXManiaGR.exe
実行時フォルダ/FDK.dll

index 9b8fdbb..c584106 100644 (file)
@@ -210,6 +210,8 @@ Debug.WriteLine( "★★tサウンドを生成する()" + SoundDevice.e出力デ
                #endregion\r
 \r
 \r
+               private STREAMPROC _myStreamCreate;  // make it global, so that the GC can not remove it\r
+\r
                /// <summary>\r
                /// <para>0:最小~100:原音</para>\r
                /// </summary>\r
@@ -657,6 +659,7 @@ Debug.WriteLine( "停止: " + System.IO.Path.GetFileName( this.strファイル
                        if( this.bBASSサウンドである )\r
                        {\r
                                BassMix.BASS_Mixer_ChannelSetPosition( this.hBassStream, 0 );\r
+                               pos = 0;\r
                        }\r
                        else if( this.bDirectSoundである )\r
                        {\r
@@ -918,17 +921,42 @@ Debug.WriteLine( "ピン止め完了:" + Path.GetFileName( strファイル名 )
                                //xaDecodeConvert( hxas, ref xash );\r
 \r
 \r
-                       this.hBassStream = Bass.BASS_SampleCreate(256, 28160, 1, 1, BASSFlag.BASS_SAMPLE_LOOP| BASSFlag.BASS_SAMPLE_OVER_POS); // create sample\r
+//this.hBassStream = Bass.BASS_SampleCreate(256, 28160, 1, 1, BASSFlag.BASS_SAMPLE_LOOP| BASSFlag.BASS_SAMPLE_OVER_POS); // create sample\r
+//if ( this.hBassStream == 0 )\r
+//{\r
+//    BASSError err = Bass.BASS_ErrorGetCode();\r
+//    Debug.WriteLine( "11BASS_SampleCreate: " + err );\r
+//        throw new Exception( "11サウンドストリームの生成に失敗しました。(BASS_SampleCreate: " + err + ")" );\r
+//    }\r
 //short[] data = new short[128]; // data buffer\r
 //int a;\r
 //for (a=0; a<128; a++)\r
 //    data[a]=(short)(32767.0*Math.Sin((double)a*6.283185/64)); // sine wave\r
-//Bass.BASS_SampleSetData(this.hBassStream, data); // set the sample's data\r
+//bool bb=Bass.BASS_SampleSetData(this.hBassStream, data); // set the sample's data\r
+//if ( !bb )\r
+//{\r
+//    hGC.Free();\r
+//    BASSError err = Bass.BASS_ErrorGetCode();\r
+//    Debug.WriteLine( "11BASS_SampleSetData: " + err );\r
+//    throw new Exception( "サウンドストリームの生成に失敗しました。(BASS_SampleSetData)" );\r
+//}\r
 \r
 \r
-Debug.WriteLine( "xash.nDstLen=" + xa.xash.nDstLen + ", xah.nSamplesPerSec=" + xa.xah.nSamplesPerSec + ", xah.nChannels=" + xa.xah.nChannels );\r
+Debug.WriteLine( "xash.nDstLen=" + xa.xastreamheader.nDstLen + ", xah.nSamplesPerSec=" + xa.xaheader.nSamplesPerSec + ", xah.nChannels=" + xa.xaheader.nChannels );\r
                        //this.hBassStream = Bass.BASS_SampleCreate( (int) xash.nDstLen, xah.nSamplesPerSec, xah.nChannels, 1, flags );\r
-                       this.hBassStream = Bass.BASS_SampleCreate( (int) xa.xash.nDstLen, xa.xah.nSamplesPerSec, xa.xah.nChannels, 1, (BASSFlag) 0 );\r
+//◆ XA Decorder liblary 001 のバグ\r
+//デコード後の XASTREAMHEADER::nDstUsed が大きめの値を返してくるので\r
+//そのままのサイズで再生すると最後にノイズが乗る。\r
+//そこで、xaDecodeConvert() 後のPCMサイズは、次の式で算出する。\r
+//dwPCMSize = nSamples * nChannels * 2;\r
+//(nSamples, nChannels は XAHEADER のメンバ)\r
+\r
+                       _myStreamCreate = new STREAMPROC( MyFileProc );\r
+\r
+                       int length = (int) ( xa.xaheader.nSamples * xa.xaheader.nChannels * 2 );\r
+Debug.WriteLine( "length=" + length );\r
+//                     this.hBassStream = Bass.BASS_SampleCreate( length, xa.xaheader.nSamplesPerSec, xa.xaheader.nChannels, 1, BASSFlag.BASS_STREAM_DECODE );\r
+                       this.hBassStream = Bass.BASS_StreamCreate( xa.xaheader.nSamplesPerSec, xa.xaheader.nChannels, BASSFlag.BASS_STREAM_DECODE, _myStreamCreate, IntPtr.Zero );\r
                        if ( this.hBassStream == 0 )\r
                        {\r
                                hGC.Free();\r
@@ -937,15 +965,15 @@ Debug.WriteLine( "BASS_SampleCreate: " + err );
                                throw new Exception( "サウンドストリームの生成に失敗しました。(BASS_SampleCreate: " + err + ")" );\r
                        }\r
 Debug.WriteLine( "SampleCreate完了:" + Path.GetFileName( strファイル名 ) );\r
-                       bool b = Bass.BASS_SampleSetData( this.hBassStream, this.byArrWAVファイルイメージ);             // ★★★★★★★★★★★★★★ 多分bufをshort見せしないとダメ!!!\r
-                       if ( !b )\r
-                       {\r
-                               hGC.Free();\r
-                               BASSError err = Bass.BASS_ErrorGetCode();\r
-                               Debug.WriteLine( "BASS_SampleSetData: " + err );\r
-                               throw new Exception( "サウンドストリームの生成に失敗しました。(BASS_SampleSetData)" );\r
-                       }\r
-Debug.WriteLine( "SampleSetData完了:" + Path.GetFileName( strファイル名 ) );\r
+//            bool b = Bass.BASS_SampleSetData( this.hBassStream, this.byArrWAVファイルイメージ);              // ★★★★★★★★★★★★★★ 多分bufをshort見せしないとダメ!!!\r
+//            if ( !b )\r
+//            {\r
+//                hGC.Free();\r
+//                BASSError err = Bass.BASS_ErrorGetCode();\r
+//                Debug.WriteLine( "BASS_SampleSetData: " + err );\r
+//                throw new Exception( "サウンドストリームの生成に失敗しました。(BASS_SampleSetData)" );\r
+//            }\r
+//Debug.WriteLine( "SampleSetData完了:" + Path.GetFileName( strファイル名 ) );\r
 \r
 \r
                        // ミキサーにBASSファイルストリームを追加。\r
@@ -960,13 +988,35 @@ Debug.WriteLine( "StreamAddChannel完了:" + Path.GetFileName( strファイル
 Debug.WriteLine( "listインスタンス.Add完了:" + Path.GetFileName( strファイル名 ) );\r
 \r
                        // nBytesとn総演奏時間の取得; DTXMania用に追加。\r
-                       nBytes = Bass.BASS_ChannelGetLength( this.hBassStream );\r
+                       //nBytes = Bass.BASS_ChannelGetLength( this.hBassStream );\r
+                       nBytes = length;\r
                        double seconds = Bass.BASS_ChannelBytes2Seconds( this.hBassStream, nBytes );\r
                        this.n総演奏時間ms = (int) ( seconds * 1000 );\r
-\r
-                       Debug.WriteLine( "nBytes=" + nBytes + ", n総演奏時間ms=" + this.n総演奏時間ms );\r
+Debug.WriteLine( "nBytes=" + nBytes + ", n総演奏時間=" + this.n総演奏時間ms );\r
                }\r
                //-----------------\r
+\r
+//             private byte[] _data = null; // our local buffer\r
+               private int pos = 0;\r
+               private int MyFileProc( int handle, IntPtr buffer, int length, IntPtr user )\r
+               {\r
+\r
+                       // increase the data buffer as needed\r
+                       //if ( _data == null || _data.Length < length )\r
+                       //    _data = new byte[ length ];\r
+\r
+                       int bytesread = ( pos + length > Convert.ToInt32(nBytes) ) ? Convert.ToInt32(nBytes) - pos : length;\r
+\r
+                       Marshal.Copy( byArrWAVファイルイメージ, pos, buffer, bytesread );\r
+                       pos += bytesread;\r
+\r
+                       if ( bytesread < length )\r
+                       {\r
+                               // set indicator flag\r
+                               bytesread |= (int) BASSStreamProc.BASS_STREAMPROC_END;\r
+                       }\r
+                       return bytesread;\r
+               }\r
                #endregion\r
        }\r
 }\r
index 1abeabd..20cc916 100644 (file)
Binary files a/実行時フォルダ/DTXManiaGR.exe and b/実行時フォルダ/DTXManiaGR.exe differ
index d4d48fe..821ea1f 100644 (file)
Binary files a/実行時フォルダ/FDK.dll and b/実行時フォルダ/FDK.dll differ