"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.",
<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" />
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
{
}
catch (Exception e)
{
- Trace.TraceWarning("xaファイルの作成に失敗しました。({0})", e.Message);
+ string s = Path.GetFileName(strファイル名);
+ Trace.TraceWarning($"directsoundサウンドの作成に失敗しました。({s}: {e.Message})");
Trace.TraceWarning("続けて、他のデコーダでの作成を試みます。");
}
}
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データ書き込み
}
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
{
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]
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
{
+++ /dev/null
-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 );
- }
-
- }
-}
--- /dev/null
+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();
+ }
+ }
+}
+++ /dev/null
-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 );
- }
-
- }
-}
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;
{
#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)
{
//string shortpath = Path.GetFileName(filename);
//Trace.TraceInformation($"libbjxa: decode succeeded: {shortpath} = {szDestSize}");
- srcBuf = null;
+//SaveWav(filename);
+
pcmbuf = null;
#region [ Debug info ]
}
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;