<commit_before>
package ibxm;

public class Module {
	public String songName = "Blank";
	public int numChannels = 4, numInstruments = 1;
	public int numPatterns = 1, sequenceLength = 1, restartPos = 0;
	public int defaultGVol = 64, defaultSpeed = 6, defaultTempo = 125, c2Rate = Sample.C2_PAL, gain = 64;
	public boolean linearPeriods = false, fastVolSlides = false;
	public int[] defaultPanning = { 51, 204, 204, 51 };
	public int[] sequence = { 0 };
	public Pattern[] patterns = { new Pattern( 4, 64 ) };
	public Instrument[] instruments = { new Instrument(), new Instrument() };

	public Module() {}
	
	public Module( java.io.InputStream inputStream ) throws java.io.IOException {
		this( new Data( inputStream ) );
	}

	public Module( Data moduleData ) throws java.io.IOException {
		if( moduleData.strLatin1( 0, 17 ).equals( "Extended Module: " ) ) {
			loadXM( moduleData );
		} else if( moduleData.strLatin1( 44, 4 ).equals( "SCRM" ) ) {
			loadS3M( moduleData );
		} else {
			loadMod( moduleData );
		}
	}

	public Module( byte[] moduleData ) throws java.io.IOException {
		this( new Data( moduleData ) );
	}

	private void loadMod( Data moduleData ) throws java.io.IOException {
		songName = moduleData.strLatin1( 0, 20 );
		sequenceLength = moduleData.uByte( 950 ) & 0x7F;
		restartPos = moduleData.uByte( 951 ) & 0x7F;
		if( restartPos >= sequenceLength ) restartPos = 0;
		sequence = new int[ 128 ];
		for( int seqIdx = 0; seqIdx < 128; seqIdx++ ) {
			int patIdx = moduleData.uByte( 952 + seqIdx ) & 0x7F;
			sequence[ seqIdx ] = patIdx;
			if( patIdx >= numPatterns ) numPatterns = patIdx + 1;
		}
		switch( moduleData.ubeShort( 1082 ) ) {
			case 0x4b2e: /* M.K. */
			case 0x4b21: /* M!K! */
			case 0x5434: /* FLT4 */
				numChannels = 4;
				c2Rate = Sample.C2_PAL;
				gain = 64;
				break;
			case 0x484e: /* xCHN */
				numChannels = moduleData.uByte( 1080 ) - 48;
				c2Rate = Sample.C2_NTSC;
				gain = 32;
				break;
			case 0x4348: /* xxCH */
				numChannels  = ( moduleData.uByte( 1080 ) - 48 ) * 10;
				numChannels += moduleData.uByte( 1081 ) - 48;
				c2Rate = Sample.C2_NTSC;
				gain = 32;
				break;
			default:
				throw new IllegalArgumentException( "MOD Format not recognised!" );
		}
		defaultGVol = 64;
		defaultSpeed = 6;
		defaultTempo = 125;
		defaultPanning = new int[ numChannels ];
		for( int idx = 0; idx < numChannels; idx++ ) {
			defaultPanning[ idx ] = 51;
			if( ( idx & 3 ) == 1 || ( idx & 3 ) == 2 )
				defaultPanning[ idx ] = 204;
		}
		int moduleDataIdx = 1084;
		patterns = new Pattern[ numPatterns ];
		for( int patIdx = 0; patIdx < numPatterns; patIdx++ ) {
			Pattern pattern = patterns[ patIdx ] = new Pattern( numChannels, 64 );
			for( int patDataIdx = 0; patDataIdx < pattern.data.length; patDataIdx += 5 ) {
				int key = ( moduleData.uByte( moduleDataIdx ) & 0xF ) << 8;
				key = ( key | moduleData.uByte( moduleDataIdx + 1 ) ) * 4;
				key = -12 * Channel.log2( ( key << Sample.FP_SHIFT ) / 29021 );
				key = ( key >> Sample.FP_SHIFT ) + ( key & ( Sample.FP_ONE >> 1 ) );
				if( key < 97 ) pattern.data[ patDataIdx ] = ( byte ) key;
				int ins = ( moduleData.uByte( moduleDataIdx + 2 ) & 0xF0 ) >> 4;
				ins = ins | moduleData.uByte( moduleDataIdx ) & 0x10;
				pattern.data[ patDataIdx + 1 ] = ( byte ) ins;
				int effect = moduleData.uByte( moduleDataIdx + 2 ) & 0x0F;
				int param  = moduleData.uByte( moduleDataIdx + 3 );
				if( param == 0 && ( effect < 3 || effect == 0xA ) ) effect = 0;
				if( param == 0 && ( effect == 5 || effect == 6 ) ) effect -= 2;
				if( effect == 8 && numChannels == 4 ) effect = param = 0;
				pattern.data[ patDataIdx + 3 ] = ( byte ) effect;
				pattern.data[ patDataIdx + 4 ] = ( byte ) param;
				moduleDataIdx += 4;
			}
		}
		numInstruments = 31;
		instruments = new Instrument[ numInstruments + 1 ];
		instruments[ 0 ] = new Instrument();
		for( int instIdx = 1; instIdx <= numInstruments; instIdx++ ) {
			Instrument instrument = instruments[ instIdx ] = new Instrument();
			Sample sample = instrument.samples[ 0 ];
			instrument.name = moduleData.strLatin1( instIdx * 30 - 10, 22 );
			int sampleLength = moduleData.ubeShort( instIdx * 30 + 12 ) * 2;<commit_msg>Fix rounding.<commit_after>
package ibxm;

public class Module {
	public String songName = "Blank";
	public int numChannels = 4, numInstruments = 1;
	public int numPatterns = 1, sequenceLength = 1, restartPos = 0;
	public int defaultGVol = 64, defaultSpeed = 6, defaultTempo = 125, c2Rate = Sample.C2_PAL, gain = 64;
	public boolean linearPeriods = false, fastVolSlides = false;
	public int[] defaultPanning = { 51, 204, 204, 51 };
	public int[] sequence = { 0 };
	public Pattern[] patterns = { new Pattern( 4, 64 ) };
	public Instrument[] instruments = { new Instrument(), new Instrument() };

	public Module() {}
	
	public Module( java.io.InputStream inputStream ) throws java.io.IOException {
		this( new Data( inputStream ) );
	}

	public Module( Data moduleData ) throws java.io.IOException {
		if( moduleData.strLatin1( 0, 17 ).equals( "Extended Module: " ) ) {
			loadXM( moduleData );
		} else if( moduleData.strLatin1( 44, 4 ).equals( "SCRM" ) ) {
			loadS3M( moduleData );
		} else {
			loadMod( moduleData );
		}
	}

	public Module( byte[] moduleData ) throws java.io.IOException {
		this( new Data( moduleData ) );
	}

	private void loadMod( Data moduleData ) throws java.io.IOException {
		songName = moduleData.strLatin1( 0, 20 );
		sequenceLength = moduleData.uByte( 950 ) & 0x7F;
		restartPos = moduleData.uByte( 951 ) & 0x7F;
		if( restartPos >= sequenceLength ) restartPos = 0;
		sequence = new int[ 128 ];
		for( int seqIdx = 0; seqIdx < 128; seqIdx++ ) {
			int patIdx = moduleData.uByte( 952 + seqIdx ) & 0x7F;
			sequence[ seqIdx ] = patIdx;
			if( patIdx >= numPatterns ) numPatterns = patIdx + 1;
		}
		switch( moduleData.ubeShort( 1082 ) ) {
			case 0x4b2e: /* M.K. */
			case 0x4b21: /* M!K! */
			case 0x5434: /* FLT4 */
				numChannels = 4;
				c2Rate = Sample.C2_PAL;
				gain = 64;
				break;
			case 0x484e: /* xCHN */
				numChannels = moduleData.uByte( 1080 ) - 48;
				c2Rate = Sample.C2_NTSC;
				gain = 32;
				break;
			case 0x4348: /* xxCH */
				numChannels  = ( moduleData.uByte( 1080 ) - 48 ) * 10;
				numChannels += moduleData.uByte( 1081 ) - 48;
				c2Rate = Sample.C2_NTSC;
				gain = 32;
				break;
			default:
				throw new IllegalArgumentException( "MOD Format not recognised!" );
		}
		defaultGVol = 64;
		defaultSpeed = 6;
		defaultTempo = 125;
		defaultPanning = new int[ numChannels ];
		for( int idx = 0; idx < numChannels; idx++ ) {
			defaultPanning[ idx ] = 51;
			if( ( idx & 3 ) == 1 || ( idx & 3 ) == 2 )
				defaultPanning[ idx ] = 204;
		}
		int moduleDataIdx = 1084;
		patterns = new Pattern[ numPatterns ];
		for( int patIdx = 0; patIdx < numPatterns; patIdx++ ) {
			Pattern pattern = patterns[ patIdx ] = new Pattern( numChannels, 64 );
			for( int patDataIdx = 0; patDataIdx < pattern.data.length; patDataIdx += 5 ) {
				int key = ( moduleData.uByte( moduleDataIdx ) & 0xF ) << 8;
				key = ( key | moduleData.uByte( moduleDataIdx + 1 ) ) * 4;
				key = -12 * Channel.log2( ( key << Sample.FP_SHIFT ) / 29021 );
				key = ( key + ( key & ( Sample.FP_ONE >> 1 ) ) ) >> Sample.FP_SHIFT;
				if( key < 97 ) pattern.data[ patDataIdx ] = ( byte ) key;
				int ins = ( moduleData.uByte( moduleDataIdx + 2 ) & 0xF0 ) >> 4;
				ins = ins | moduleData.uByte( moduleDataIdx ) & 0x10;
				pattern.data[ patDataIdx + 1 ] = ( byte ) ins;
				int effect = moduleData.uByte( moduleDataIdx + 2 ) & 0x0F;
				int param  = moduleData.uByte( moduleDataIdx + 3 );
				if( param == 0 && ( effect < 3 || effect == 0xA ) ) effect = 0;
				if( param == 0 && ( effect == 5 || effect == 6 ) ) effect -= 2;
				if( effect == 8 && numChannels == 4 ) effect = param = 0;
				pattern.data[ patDataIdx + 3 ] = ( byte ) effect;
				pattern.data[ patDataIdx + 4 ] = ( byte ) param;
				moduleDataIdx += 4;
			}
		}
		numInstruments = 31;
		instruments = new Instrument[ numInstruments + 1 ];
		instruments[ 0 ] = new Instrument();
		for( int instIdx = 1; instIdx <= numInstruments; instIdx++ ) {
			Instrument instrument = instruments[ instIdx ] = new Instrument();
			Sample sample = instrument.samples[ 0 ];
			instrument.name = moduleData.strLatin1( instIdx * 30 - 10, 22 );
			int sampleLength = moduleData.ubeShort( instIdx * 30 + 12 ) * 2;
{'fraction_non_alphanumeric': 0.1386695381670256, 'fraction_numerical': 0.05001196458482891, 'mean_word_length': 3.032320308731307, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3344035', 'n_tokens_mistral': 3592, 'n_tokens_neox': 2867, 'n_words': 840}