Commit 12d4103

Nick Faro committed on
WIP gbt noise import
commit 12d41030d7605e81dc5c6c72f5c2431f271edae0 parent e16dba8
1 changed files +45−1
Modifiedmodimport.pas +45−1
@@ -80,6 +80,15 @@ const
80 ($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$00,$00), 80 ($FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$00,$00,$00,$00,$00,$00,$00,$00),
81 ($79,$BC,$DE,$EF,$FF,$EE,$DC,$B9,$75,$43,$21,$10,$00,$11,$23,$45)); 81 ($79,$BC,$DE,$EF,$FF,$EE,$DC,$B9,$75,$43,$21,$10,$00,$11,$23,$45));
82 82
83 // https://github.com/RichardULZ/gb-studio/blob/master/buildTools/win32-ia32/mod2gbt/mod2gbt.c#L169
84 GBT_NOISE: array of Integer = (
85 // 7 bit
86 $5F,$4E,$3E,$2F,$2E,$2C,$1F,$0F,
87 // 15 bit
88 $64,$54,$44,$24,$00,
89 $67,$56,$46
90 );
91
83 var 92 var
84 PeriodToCodeMap: TPeriodToCodeMap; 93 PeriodToCodeMap: TPeriodToCodeMap;
85 94
@@ -175,6 +184,41 @@ begin
175 end; 184 end;
176 end; 185 end;
177 186
187 // https://github.com/RichardULZ/gb-studio/blob/master/buildTools/win32-ia32/mod2gbt/mod2gbt.c#L827
188
189 procedure TranscribeColumnCh4(MP: TMODPattern; Pat: PPattern);
190 var
191 MR: TMODRow;
192 Instrument: Byte;
193 NoiseBreak: Byte;
194 Noise: Byte;
195 begin
196 MR := MP[I, 4];
197 Instrument = GBT_NOISE[((MR.Instrument - 16) and $1F)]; // Only 0 - 0xF implemented
198
199 // Rulz writes:
200 // This makes a smooth Ramp of every noise type, inspired by Pigu-A's Cherry Blossom Dive
201 // SSSS WDDD, preserve Width bit, combine Shift + Divisor (ignore bit 0100), add pitch.
202 // Divisor 4,5,6,7 can make any noise found in 0,1,2,3 unless with 0 Clock Shift.
203 // Solution, add 4, add note, if less than 4, set bit 0x04 to 0, and remove 4 again.
204 // Notes will pitch correctly using C D# F# A# C, scale has been divided by 3.
205 if (MR.Instrument < 32) and (MR.Instrument > 16) then begin
206 NoiseBreak := ((Instrument and $03) or (((Instrument and $F0) shr 2) + 4));
207 NoiseBreak := NoiseBreak - (((MR.Note + 1) / 3) - 8);
208 Noise := ((NoiseBreak and $03) or
209 ((((NoiseBreak - 4) < 0 ? $0 : (NoiseBreak - 4)) and $3C) shl 2) or
210 (NoiseBreak > 3 ? $04 : $0) ) or (Instrument and $08);
211 end;
212 if (samplenum < 32 && samplenum > 16) // Noise
213 {
214 noise_break = ( (instrument & 0x03) | (((instrument & 0xF0) >> 2) + 4) );
215 noise_break = noise_break - (((note_index + 1) / 3) - 8);
216 noise = ( (noise_break & 0x03) |
217 ((((noise_break - 4) < 0 ? 0x0 : (noise_break - 4)) & 0x3C) << 2) |
218 (noise_break > 3 ? 0x04 : 0x0) ) | (instrument & 0x08);
219 }
220 end;
221
178 function LoadSongFromModStream(Stream: TStream): TSong; 222 function LoadSongFromModStream(Stream: TStream): TSong;
179 var 223 var
180 ModFile: TMODFile; 224 ModFile: TMODFile;
@@ -231,7 +275,7 @@ begin
231 TranscribeColumn(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 0), 1); 275 TranscribeColumn(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 0), 1);
232 TranscribeColumn(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 1), 2); 276 TranscribeColumn(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 1), 2);
233 TranscribeColumn(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 2), 3); 277 TranscribeColumn(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 2), 3);
234 TranscribeColumn(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 3), 4); 278 TranscribeColumnCh4(ModFile.Patterns[I], Result.Patterns.GetOrCreateNew(I*10 + 3));
235 end; 279 end;
236 280
237 // Import the order table. Uses a weird numbering scheme because hUGE has 281 // Import the order table. Uses a weird numbering scheme because hUGE has