#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
if( this.bBASSサウンドである )\r
{\r
BassMix.BASS_Mixer_ChannelSetPosition( this.hBassStream, 0 );\r
+ pos = 0;\r
}\r
else if( this.bDirectSoundである )\r
{\r
//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
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
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