OSDN Git Service

#28822 SoundDecoder.dll を削除。DirectSound使用時、mp3とoggはbass.libを使ってデコードするように変更した。
authoryyagi <yyagi.dtxmania@gmail.com>
Thu, 24 Jan 2019 15:51:50 +0000 (00:51 +0900)
committeryyagi <yyagi.dtxmania@gmail.com>
Thu, 24 Jan 2019 15:51:50 +0000 (00:51 +0900)
DTXMania/コード/全体/Program.cs
FDK/FDK.csproj
FDK/コード/03.サウンド/CSound.cs
FDK/コード/03.サウンド/Cmp3.cs [deleted file]
FDK/コード/03.サウンド/Cmp3ogg.cs [new file with mode: 0644]
FDK/コード/03.サウンド/Cogg.cs [deleted file]
FDK/コード/03.サウンド/Cxa.cs
RuntimeResources/dll/SoundDecoder.dll [deleted file]
RuntimeResources/dll/xadec.dll [deleted file]

index 859d237..1cdff47 100644 (file)
@@ -109,11 +109,6 @@ namespace DTXMania
                                        "libbjxa.dll is not found." + newLine + "Please download DTXMania again."
                                        ))
                                        bDLLnotfound = true;
-                               if (!tDLLの存在チェック("dll\\SoundDecoder.dll",
-                                       "SoundDecoder.dll またはその依存するdllが存在しません。" + newLine + "DTXManiaをダウンロードしなおしてください。",
-                                       "SoundDecoder.dll, or its depended DLL, is not found." + newLine + "Please download DTXMania again."
-                                       ))
-                                       bDLLnotfound = true;
                                if (!tDLLの存在チェック(CDTXMania.D3DXDLL,
                                        CDTXMania.D3DXDLL + " が存在しません。" + newLine + "DirectX Redist フォルダの DXSETUP.exe を実行し、" + newLine + "必要な DirectX ランタイムをインストールしてください。",
                                        CDTXMania.D3DXDLL + " is not found." + newLine + "Please execute DXSETUP.exe in \"DirectX Redist\" folder, to install DirectX runtimes required for DTXMania.",
index c9dbbd7..d605bfa 100644 (file)
     <Compile Include="コード\02.入力\SlimDX.DirectInput.Key.cs" />
     <Compile Include="コード\02.入力\STInputEvent.cs" />
     <Compile Include="コード\03.サウンド\BASSThreadedMixerWrapper.cs" />
-    <Compile Include="コード\03.サウンド\Cmp3.cs" />
-    <Compile Include="コード\03.サウンド\Cogg.cs" />
+    <Compile Include="コード\03.サウンド\Cmp3ogg.cs" />
     <Compile Include="コード\03.サウンド\CSound.cs" />
     <Compile Include="コード\03.サウンド\CSoundDeviceASIO.cs" />
     <Compile Include="コード\03.サウンド\CSoundDeviceDirectSound.cs" />
index cbe2787..367e605 100644 (file)
@@ -857,7 +857,7 @@ namespace FDK
                        this.strファイル名 = strファイル名;
                        if ( String.Compare( Path.GetExtension( strファイル名 ), ".xa", true ) == 0 ||
                                 String.Compare( Path.GetExtension( strファイル名 ), ".mp3", true ) == 0 ||
-                                String.Compare( Path.GetExtension( strファイル名 ), ".ogg", true ) == 0 ) // caselessで文字列比較
+                                String.Compare( Path.GetExtension( strファイル名 ), ".ogg", true ) == 0 )   // caselessで文字列比較
                        {
                                try
                                {
@@ -867,7 +867,8 @@ namespace FDK
                                }
                                catch (Exception e)
                                {
-                                       Trace.TraceWarning("xaファイルの作成に失敗しました。({0})", e.Message);
+                                       string s = Path.GetFileName(strファイル名);
+                                       Trace.TraceWarning($"directsoundサウンドの作成に失敗しました。({s}: {e.Message})");
                                        Trace.TraceWarning("続けて、他のデコーダでの作成を試みます。");
                                }
                        }
@@ -1067,6 +1068,12 @@ namespace FDK
                        tDirectSoundサウンドを作成する_セカンダリバッファの作成とWAVデータ書き込み(
                                ref byArrWAVファイルイメージ, DirectSound, flags, wfx, nPCMサイズbyte, nPCMデータの先頭インデックス );
                        this.eInstType = _eInstType;
+
+//var st = new FileStream("temp3.wav", FileMode.Create);
+//st.Write(byArrWAVファイルイメージ, 0, byArrWAVファイルイメージ.Length);
+//st.Dispose();
+//Trace.TraceInformation("wrote " + byArrWAVファイルイメージ.Length);
+
                }
 
                private void tDirectSoundサウンドを作成する_セカンダリバッファの作成とWAVデータ書き込み
@@ -1917,11 +1924,11 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
                        }
                        else if ( String.Compare( Path.GetExtension( strファイル名 ), ".ogg", true ) == 0 )
                        {
-                               sounddecoder = new Cogg();
+                               sounddecoder = new Cmp3ogg();
                        }
                        else if ( String.Compare( Path.GetExtension( strファイル名 ), ".mp3", true ) == 0 )
                        {
-                               sounddecoder = new Cmp3();
+                               sounddecoder = new Cmp3ogg();
                        }
                        else
                        {
@@ -1970,7 +1977,7 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
                                        var ms = new MemoryStream();
                                        var bw = new BinaryWriter( ms );
                                        bw.Write( new byte[] { 0x52, 0x49, 0x46, 0x46 } );              // 'RIFF'
-                                       bw.Write( (UInt32) totalPCMSize + 44 - 8 );                             // ファイルサイズ - 8 [byte];今は不明なので後で上書きする。
+                                       bw.Write( (UInt32) totalPCMSize + 44 - 8 );                             // ファイルサイズ - 8 [byte];
                                        bw.Write( new byte[] { 0x57, 0x41, 0x56, 0x45 } );              // 'WAVE'
                                        bw.Write( new byte[] { 0x66, 0x6D, 0x74, 0x20 } );              // 'fmt '
                                        bw.Write( (UInt32) ( 16 + ( ( wfx拡張領域_Length > 0 ) ? ( 2/*sizeof(WAVEFORMATEX.cbSize)*/ + wfx拡張領域_Length ) : 0 ) ) );   // fmtチャンクのサイズ[byte]
@@ -2007,6 +2014,13 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ
                                Array.Copy(buffer_rawdata, 0, buffer, wavheadersize, totalPCMSize);
                                totalPCMSize += wavheadersize;
                                nPCMデータの先頭インデックス = wavheadersize;
+
+//string filename = Path.GetFileName(this.strファイル名);
+//var st = new FileStream(filename+".wav", FileMode.Create);
+//st.Write(buffer, 0, buffer.Length);
+//st.Dispose();
+//Trace.TraceInformation($"wrote ({filename}.wav)" + buffer.Length);
+
                        }
                        finally
                        {
diff --git a/FDK/コード/03.サウンド/Cmp3.cs b/FDK/コード/03.サウンド/Cmp3.cs
deleted file mode 100644 (file)
index 761122b..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-using System.IO;
-using System.Diagnostics;
-using System.Threading;
-
-
-namespace FDK
-{
-       public unsafe class Cmp3 : SoundDecoder
-       {
-//             static byte[] FOURCC = Encoding.ASCII.GetBytes( "SggO" );       // OggS の little endian
-
-
-               #region [ SoundDecoder.dll インポート(mpr 関連)]
-               //-----------------
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern void mp3Close( int nHandle );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int mp3Decode( int nHandle, IntPtr pDest, uint szDestSize, int bLoop );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int mp3GetFormat( int nHandle, ref CWin32.WAVEFORMATEX wfx );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern uint mp3GetTotalPCMSize( int nHandle );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int mp3Open( string fileName );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int mp3Seek( int nHandle, uint dwPosition );
-               //-----------------
-               #endregion
-
-
-               public override int Open( string filename )
-               {
-                       return mp3Open( filename );
-               }
-               public override int GetFormat( int nHandle, ref CWin32.WAVEFORMATEX wfx )
-               {
-                       return mp3GetFormat( nHandle, ref wfx );
-               }
-               public override uint GetTotalPCMSize( int nHandle )
-               {
-                       return mp3GetTotalPCMSize( nHandle );
-               }
-               public override int Seek( int nHandle, uint dwPosition )
-               {
-                       return mp3Seek( nHandle, dwPosition );
-               }
-               public override int Decode( int nHandle, IntPtr pDest, uint szDestSize, int bLoop )
-               {
-                       return mp3Decode( nHandle, pDest, szDestSize, bLoop );
-               }
-
-               public override void Close( int nHandle )
-               {
-                       mp3Close( nHandle );
-               }
-
-       }
-}
diff --git a/FDK/コード/03.サウンド/Cmp3ogg.cs b/FDK/コード/03.サウンド/Cmp3ogg.cs
new file mode 100644 (file)
index 0000000..964f413
--- /dev/null
@@ -0,0 +1,156 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.InteropServices;
+using System.IO;
+using System.Diagnostics;
+using System.Threading;
+using Un4seen.Bass;
+using Un4seen.Bass.Misc;
+
+
+namespace FDK
+{
+       public unsafe class Cmp3ogg : SoundDecoder
+       {
+               CWin32.WAVEFORMATEX _wfx;
+               long _TotalPCMSize = 0;
+               private int stream_in = -1;
+               byte[] wavdata = null;
+
+
+               public override int Open( string filename )
+               {
+                       bool r = Bass.BASS_Init(0, 48000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
+
+                       stream_in = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_DECODE);
+                       // BASS_DEFAULT: output 32bit (16bit stereo)
+                       if (stream_in == 0)
+                       {
+                               BASSError be = Bass.BASS_ErrorGetCode();
+                               Trace.TraceInformation("Cmp3: streamcreatefile error: " + be.ToString());
+                       }
+                       _TotalPCMSize = Bass.BASS_ChannelGetLength(stream_in);
+
+
+//string fn = Path.GetFileName(filename); 
+//Trace.TraceInformation("filename=" + fn + ", size=(decode): " + wavdata.Length + ", channelgetlength=" + _TotalPCMSize2 + ", " + _TotalPCMSize) ;
+
+                       return 1;
+               }
+               public override int GetFormat( int nHandle, ref CWin32.WAVEFORMATEX wfx )
+               {
+                       var chinfo = Bass.BASS_ChannelGetInfo(stream_in);
+                       _wfx.wFormatTag = 1;                                        // 1 == PCM
+                       _wfx.nChannels = (ushort)chinfo.chans;                  //
+                       _wfx.nSamplesPerSec = (uint)chinfo.freq;                        //
+                       _wfx.nAvgBytesPerSec = (uint)(chinfo.freq * 2 * chinfo.chans);  //
+                       _wfx.nBlockAlign = (ushort)(2 * chinfo.chans);              // 16bit * mono/stereo
+                       _wfx.wBitsPerSample = 16;
+
+                       //Debug.WriteLine("**WAVEFORMATEX** in Cmp3.cs from stream info");
+                       //Debug.WriteLine("wFormatTag=      " + 1);
+                       //Debug.WriteLine("nChannels =      " + chinfo.chans.ToString("X4"));
+                       //Debug.WriteLine("nSamplesPerSec=  " + chinfo.freq.ToString("X8"));
+                       //Debug.WriteLine("nAvgBytesPerSec= " + (chinfo.freq * 4).ToString("X8"));
+                       //Debug.WriteLine("nBlockAlign=     " + (2 * chinfo.chans).ToString("X4"));
+                       //Debug.WriteLine("wBitsPerSample=  " + (16).ToString("X4"));
+
+                       wfx = _wfx;
+
+                       #region [ Debug info ]
+                       //Debug.WriteLine("**WAVEFORMATEX** in Cmp3.cs from binary array");
+                       //Debug.WriteLine("wFormatTag=      " + wfx.wFormatTag.ToString("X4"));
+                       //Debug.WriteLine("nChannels =      " + wfx.nChannels.ToString("X4"));
+                       //Debug.WriteLine("nSamplesPerSec=  " + wfx.nSamplesPerSec.ToString("X8"));
+                       //Debug.WriteLine("nAvgBytesPerSec= " + wfx.nAvgBytesPerSec.ToString("X8"));
+                       //Debug.WriteLine("nBlockAlign=     " + wfx.nBlockAlign.ToString("X4"));
+                       //Debug.WriteLine("wBitsPerSample=  " + wfx.wBitsPerSample.ToString("X4"));
+                       //Debug.WriteLine("cbSize=          " + wfx.cbSize.ToString("X4"));
+                       #endregion
+
+                       return 0;
+               }
+               public override uint GetTotalPCMSize( int nHandle )
+               {
+                       return (uint)_TotalPCMSize;
+
+                       // return mp3GetTotalPCMSize( nHandle );
+               }
+               public override int Seek( int nHandle, uint dwPosition )
+               {
+                       return 0;
+                       //return mp3Seek( nHandle, dwPosition );
+               }
+               public override int Decode( int nHandle, IntPtr pDest, uint szDestSize, int bLoop )
+               {
+                       var ms_out = new MemoryStream();
+                       var bw_out = new BinaryWriter(ms_out);
+
+                       #region [ decode ]
+                       int LEN = 65536;
+                       byte[] data = new byte[LEN]; // 2 x 16-bit and length in is bytes
+                       int len = 0;
+                       do
+                       {
+                               len = Bass.BASS_ChannelGetData(stream_in, data, LEN);
+                               if (len < 0)
+                               {
+                                       BASSError be = Bass.BASS_ErrorGetCode();
+                                       Trace.TraceInformation("Cmp3: BASS_ChannelGetData Error: " + be.ToString());
+                               }
+                               bw_out.Write(data, 0, len);
+                       } while (len == LEN);
+                       #endregion
+
+                       wavdata = ms_out.ToArray();
+
+                       bw_out.Dispose(); bw_out = null;
+                       ms_out.Dispose(); ms_out = null;
+
+                       Marshal.Copy(wavdata, 0, pDest, wavdata.Length);
+
+//SaveWav(filename);
+
+                       return 0;
+               }
+
+               public override void Close( int nHandle )
+               {
+                       Bass.BASS_StreamFree(stream_in);
+                       Bass.BASS_Free();
+                       wavdata = null;
+               }
+
+               /// <summary>
+               /// save wav file (for debugging)
+               /// </summary>
+               /// <param name="filename">input mp3/xa filename</param>
+               private void SaveWav(string filename)
+               {
+                       string outfile = Path.GetFileName(filename);
+                       var fs = new FileStream(outfile + ".wav", FileMode.Create);
+                       var st = new BinaryWriter(fs);
+
+                       st.Write(new byte[] { 0x52, 0x49, 0x46, 0x46 });      // 'RIFF'
+                       st.Write((int)(_TotalPCMSize + 44 - 8));      // filesize - 8 [byte];今は不明なので後で上書きする。
+                       st.Write(new byte[] { 0x57, 0x41, 0x56, 0x45 });      // 'WAVE'
+                       st.Write(new byte[] { 0x66, 0x6D, 0x74, 0x20 });      // 'fmt '
+                       st.Write(new byte[] { 0x10, 0x00, 0x00, 0x00 });      // chunk size 16bytes
+                       st.Write(new byte[] { 0x01, 0x00 }, 0, 2);                  // formatTag 0001 PCM
+                       st.Write((short)_wfx.nChannels);                              // channels
+                       st.Write((int)_wfx.nSamplesPerSec);                             // samples per sec
+                       st.Write((int)_wfx.nAvgBytesPerSec);          // avg bytesper sec
+                       st.Write((short)_wfx.nBlockAlign);                        // blockalign = 16bit * mono/stereo
+                       st.Write((short)_wfx.wBitsPerSample);                  // bitspersample = 16bits
+
+                       st.Write(new byte[] { 0x64, 0x61, 0x74, 0x61 });      // 'data'
+                       st.Write((int) _TotalPCMSize);      // datasize 
+                       
+                       st.Write(wavdata);
+Trace.TraceInformation($"wrote ({outfile}.wav) fsLength=" + fs.Length + ", TotalPCMSize=" + _TotalPCMSize + ", diff=" + (fs.Length - _TotalPCMSize));
+                       st.Dispose();
+                       fs.Dispose();
+               }
+       }
+}
diff --git a/FDK/コード/03.サウンド/Cogg.cs b/FDK/コード/03.サウンド/Cogg.cs
deleted file mode 100644 (file)
index c99b9eb..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-using System.IO;
-using System.Diagnostics;
-using System.Threading;
-
-
-namespace FDK
-{
-       public unsafe class Cogg : SoundDecoder
-       {
-               static byte[] FOURCC = Encoding.ASCII.GetBytes( "SggO" );       // OggS の little endian
-
-
-               #region [ SoundDecoder.dll インポート(ogg 関連)]
-               //-----------------
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern void oggClose( int nHandle );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int oggDecode( int nHandle, IntPtr pDest, uint szDestSize, int bLoop );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int oggGetFormat( int nHandle, ref CWin32.WAVEFORMATEX wfx );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern uint oggGetTotalPCMSize( int nHandle );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int oggOpen( string fileName );
-               [DllImport( "SoundDecoder.dll" )]
-               private static extern int oggSeek( int nHandle, uint dwPosition );
-               //-----------------
-               #endregion
-
-
-               public override int Open( string filename )
-               {
-                       return oggOpen( filename );
-               }
-               public override int GetFormat( int nHandle, ref CWin32.WAVEFORMATEX wfx )
-               {
-                       return oggGetFormat( nHandle, ref wfx );
-               }
-               public override uint GetTotalPCMSize( int nHandle )
-               {
-                       return oggGetTotalPCMSize( nHandle );
-               }
-               public override int Seek( int nHandle, uint dwPosition )
-               {
-                       return oggSeek( nHandle, dwPosition );
-               }
-               public override int Decode( int nHandle, IntPtr pDest, uint szDestSize, int bLoop )
-               {
-                       return oggDecode( nHandle, pDest, szDestSize, bLoop );
-               }
-
-               public override void Close( int nHandle )
-               {
-                       oggClose( nHandle );
-               }
-
-       }
-}
index 302d362..df810a4 100644 (file)
@@ -17,6 +17,8 @@ namespace FDK
 
                private string filename;
                private byte[] srcBuf = null;
+               private short[] pcmbuf = null;
+
                //private int nHandle = -1;
                private bjxa.Decoder bjxa = new bjxa.Decoder();
                private bjxa.Format format = null;
@@ -106,7 +108,7 @@ namespace FDK
                {
                        #region [ Decodig xa data ]
                        srcBuf = new byte[format.Blocks * format.BlockSizeXa];
-                       var pcmbuf = new short[format.Blocks * format.BlockSizePcm];
+                       pcmbuf = new short[format.Blocks * format.BlockSizePcm];
 
                        if (fs.Read(srcBuf, 0, srcBuf.Length) != srcBuf.Length)
                        {
@@ -132,7 +134,8 @@ namespace FDK
                        //string shortpath = Path.GetFileName(filename);
                        //Trace.TraceInformation($"libbjxa: decode succeeded: {shortpath} = {szDestSize}");
 
-                       srcBuf = null;
+//SaveWav(filename);
+
                        pcmbuf = null;
 
                        #region [ Debug info ]
@@ -148,11 +151,60 @@ namespace FDK
                }
                public override void Close(int nHandle)
                {
+                       srcBuf = null;
                        fs.Close();
                }
 
 
 
+
+               private void SaveWav(string filename)
+               {
+                       long _TotalPCMSize = (uint)format.DataLengthPcm;
+                       CWin32.WAVEFORMATEX _wfx = waveformatex;
+
+                       string outfile = Path.GetFileName(filename);
+                       var fs2 = new FileStream(outfile + ".wav", FileMode.Create);
+                       var st = new BinaryWriter(fs2);
+
+                       st.Write(new byte[] { 0x52, 0x49, 0x46, 0x46 }, 0, 4);      // 'RIFF'
+                       st.Write((int)_TotalPCMSize + 44 - 8);      // filesize - 8 [byte];今は不明なので後で上書きする。
+                       st.Write(new byte[] { 0x57, 0x41, 0x56, 0x45 }, 0, 4);      // 'WAVE'
+                       st.Write(new byte[] { 0x66, 0x6D, 0x74, 0x20 }, 0, 4);      // 'fmt '
+                       st.Write(new byte[] { 0x10, 0x00, 0x00, 0x00 }, 0, 4);      // chunk size 16bytes
+                       st.Write(new byte[] { 0x01, 0x00 }, 0, 2);                  // formatTag 0001 PCM
+                       st.Write((short)_wfx.nChannels);                              // channels
+                       st.Write((int)_wfx.nSamplesPerSec);                             // samples per sec
+                       st.Write((int)_wfx.nAvgBytesPerSec);          // avg bytesper sec
+                       st.Write((short)_wfx.nBlockAlign);                        // blockalign = 16bit * mono/stereo
+                       st.Write((short)_wfx.wBitsPerSample);                  // bitspersample = 16bits
+
+                       st.Write(new byte[] { 0x64, 0x61, 0x74, 0x61 }, 0, 4);      // 'data'
+                       st.Write((int)_TotalPCMSize);      // datasize 
+
+
+                       //var pcmbuf = new short[format.Blocks * format.BlockSizePcm];
+                       //if (fs.Read(srcBuf, 0, srcBuf.Length) != srcBuf.Length)
+                       //{
+                       //      string s = Path.GetFileName(filename);
+                       //      throw new Exception($"Failed to load xa data: {s}");
+                       //}
+                       //int ret = bjxa.Decode(srcBuf, pcmbuf, out long pcmBufLength);
+
+                       int shortsize = (int)(format.Blocks * format.BlockSizePcm);
+                       var pcmbuf_bytes = new byte[shortsize * 2];
+                       for (int i = 0; i < shortsize; i++)
+                       {
+                               var b = BitConverter.GetBytes(pcmbuf[i]);
+                               pcmbuf_bytes[i * 2] = b[0];
+                               pcmbuf_bytes[i * 2 + 1] = b[1];
+                       }
+                       st.Write(pcmbuf_bytes);
+                       Trace.TraceInformation($"wrote ({outfile}.wav) " + fs2.Length);
+                       st.Dispose();
+                       fs2.Dispose();
+               }
+
                #region [ IDisposable implementatitons ]
                //-----------------
                private bool bDisposed = false;
diff --git a/RuntimeResources/dll/SoundDecoder.dll b/RuntimeResources/dll/SoundDecoder.dll
deleted file mode 100644 (file)
index f872911..0000000
Binary files a/RuntimeResources/dll/SoundDecoder.dll and /dev/null differ
diff --git a/RuntimeResources/dll/xadec.dll b/RuntimeResources/dll/xadec.dll
deleted file mode 100644 (file)
index a415cdb..0000000
Binary files a/RuntimeResources/dll/xadec.dll and /dev/null differ