修订版 | f6c981f0ff47bc7c8f77d902ec9f69616cc6dccb (tree) |
---|---|
时间 | 2021-10-17 03:30:13 |
作者 | yyagi <yyagi.dtxmania@gmai...> |
Commiter | yyagi |
@@ -2172,7 +2172,7 @@ Debug.WriteLine("更に再生に失敗: " + Path.GetFileName(this.strファイ | ||
2172 | 2172 | bw.Close(); |
2173 | 2173 | ms.Close(); |
2174 | 2174 | |
2175 | - for ( int i = 0; i < bs.Length; i++ ) | |
2175 | + for ( int i = 0; i < bs.Length; i++ ) // copying header | |
2176 | 2176 | { |
2177 | 2177 | buffer[ i ] = bs[ i ]; |
2178 | 2178 | } |
@@ -27,21 +27,25 @@ namespace FDK | ||
27 | 27 | { |
28 | 28 | BASSError be = Bass.BASS_ErrorGetCode(); |
29 | 29 | Trace.TraceInformation("Cmp3: StreamCreateFile error: " + be.ToString()); |
30 | - return 0; | |
30 | + return -1; | |
31 | 31 | } |
32 | 32 | nTotalPCMSize = Bass.BASS_ChannelGetLength(stream_in); |
33 | 33 | |
34 | 34 | #region [ Getting WAVEFORMEX info ] |
35 | 35 | var chinfo = Bass.BASS_ChannelGetInfo(stream_in); |
36 | + int wBitsPerSample = (chinfo.origres==0)? 16 : chinfo.origres; // for no3, origres might be zero | |
37 | + | |
36 | 38 | wfx = new CWin32.WAVEFORMATEX( |
37 | 39 | (ushort)1, // wFormatTag |
38 | 40 | (ushort)chinfo.chans, // nChannels |
39 | 41 | (uint)chinfo.freq, // nSamplesPerSec |
40 | - (uint)(chinfo.freq * 2 * chinfo.chans), // nAvgBytesPerSec | |
41 | - (ushort)(2 * chinfo.chans), // nBlockAlign | |
42 | - 16, // wBitsPerSample | |
43 | - 0 // cbSize | |
42 | + (uint)(chinfo.freq * chinfo.chans * wBitsPerSample / 8 ), // nAvgBytesPerSec == SampleRate(freq) * NumChannels(chans) * BitsPerSample/8 | |
43 | + (ushort)(chinfo.chans * wBitsPerSample / 8), // nBlockAlign== NumChannels * BitsPerSample/8 | |
44 | + (ushort)( wBitsPerSample ), // wBitsPerSample (8, 16, ...) | |
45 | + (ushort)0 // cbSize | |
44 | 46 | ); |
47 | + Trace.TraceInformation($"chans={chinfo.chans}, freq={chinfo.freq}, chinfo.origres={chinfo.origres}, BitsPerSample={wBitsPerSample}, nAvgBytePerSec={wfx.nAvgBytesPerSec}, nBlockAlign={wfx.nBlockAlign}"); | |
48 | + Trace.TraceInformation( $"totalPCMSize={nTotalPCMSize}:{nTotalPCMSize.ToString("x8")}" ); | |
45 | 49 | #endregion |
46 | 50 | |
47 | 51 | //string fn = Path.GetFileName(filename); |
@@ -55,8 +59,14 @@ namespace FDK | ||
55 | 59 | #region [ decode ] |
56 | 60 | int LEN = 65536; |
57 | 61 | byte[] data = new byte[LEN]; // 2 x 16-bit and length in is bytes |
62 | + | |
63 | + for (int i = 0; i < offset; i++ ) | |
64 | + { | |
65 | + Dest[ i ] = 0; | |
66 | + } | |
67 | + | |
58 | 68 | long len = 0; |
59 | - long p = 0; | |
69 | + long p = offset; | |
60 | 70 | do |
61 | 71 | { |
62 | 72 | len = Bass.BASS_ChannelGetData(stream_in, data, LEN); |
@@ -64,14 +74,15 @@ namespace FDK | ||
64 | 74 | { |
65 | 75 | BASSError be = Bass.BASS_ErrorGetCode(); |
66 | 76 | Trace.TraceInformation("Cmp3: BASS_ChannelGetData Error: " + be.ToString()); |
77 | + break; | |
67 | 78 | } |
68 | - if (p + len > nTotalPCMSize) | |
79 | + if (p + len > nTotalPCMSize + offset) | |
69 | 80 | { |
70 | - len = nTotalPCMSize - p; | |
81 | + len = nTotalPCMSize - p + offset; | |
71 | 82 | } |
72 | 83 | Array.Copy(data, 0, Dest, p, len); |
73 | 84 | p += len; |
74 | - } while (p < nTotalPCMSize); | |
85 | + } while (p < nTotalPCMSize + offset); | |
75 | 86 | #endregion |
76 | 87 | |
77 | 88 | //SaveWav(filename, Dest); |