public void readHeaderFromStream(Stream stream) { long startSamplePosition = stream.Position; sizeInBytes = ModuleUtils.ReadDWord(stream); loopStart = ModuleUtils.ReadDWord(stream); loopLength = ModuleUtils.ReadDWord(stream); byte vol = ModuleUtils.ReadByte(stream); volume = (vol >= 64) ? 1.0f : (float)vol / 64.0f; finetune = (sbyte)ModuleUtils.ReadSignedByte(stream); type = ModuleUtils.ReadByte(stream); panning = ModuleUtils.ReadByte(stream); relativeNoteNumber = (sbyte)ModuleUtils.ReadSignedByte(stream); packedType = ModuleUtils.ReadByte(stream); name = ModuleUtils.ReadString0(stream, 22); length = ((type & 0x10) != 0) ? sizeInBytes >> 1 : sizeInBytes; loopType = (byte)(type & 0x03); is16Bits = (type & 0x10) != 0; loopStart = is16Bits ? loopStart >> 1 : loopStart; loopLength = is16Bits ? loopLength >> 1 : loopLength; loopEnd = loopStart + loopLength; loopEnd = (loopEnd > length) ? length : loopEnd; loopStart = (loopStart > length) ? length : loopStart; relativeNoteNumber = 0; //stream.Seek(startSamplePosition + 40, SeekOrigin.Begin); }
private void ReadArrangement(Stream stream) { arrangement.Clear(); for (int i = 0; i < 256; i++) { byte patNum = ModuleUtils.ReadByte(stream); if (i < songLength) { arrangement.Add(patNum); } } }
private XM_PatternChannel CreateNewPatternChannel(Stream stream, uint numberOfSamples) { XM_PatternChannel channel = new XM_PatternChannel(); byte b0 = ModuleUtils.ReadByte(stream); if ((b0 & 0x80) != 0) { if ((b0 & 0x01) != 0) { channel.noteIndex = ModuleUtils.ReadByte(stream); } if ((b0 & 0x02) != 0) { channel.instrumentIndex = ModuleUtils.ReadByte(stream); } if ((b0 & 0x04) != 0) { channel.volumeEffect = ModuleUtils.ReadByte(stream); } if ((b0 & 0x08) != 0) { channel.effekt = ModuleUtils.ReadByte(stream); } if ((b0 & 0x10) != 0) { channel.effektOp = ModuleUtils.ReadByte(stream); } } else { channel.noteIndex = (byte)(b0 & 0x7F); channel.instrumentIndex = ModuleUtils.ReadByte(stream); channel.volumeEffect = ModuleUtils.ReadByte(stream); channel.effekt = ModuleUtils.ReadByte(stream); channel.effektOp = ModuleUtils.ReadByte(stream); } if (channel.noteIndex > 0 && channel.noteIndex < 97 && channel.volumeEffect == 0) { channel.volumeEffect = 0x50; } return(channel); }
public void ReadPatternData(Stream stream, string moduleID, uint numberOfChannels, uint numberOfSamples) { headerLength = ModuleUtils.ReadDWord(stream); packingType = ModuleUtils.ReadByte(stream); numberOfRows = ModuleUtils.ReadWord(stream); packedSize = ModuleUtils.ReadWord(stream); long patternEndPosition = stream.Position + packedSize; patternRows.Clear(); for (int row = 0; row < numberOfRows; row++) { ModulePatternRow pRow = new ModulePatternRow(); for (int channel = 0; channel < numberOfChannels; channel++) { pRow.patternChannels.Add(CreateNewPatternChannel(stream, numberOfSamples)); } patternRows.Add(pRow); } stream.Seek(patternEndPosition, SeekOrigin.Begin); }
public void ReadFromStream(Stream stream, ref uint sampleOrder) { long startInstrumentPosition = stream.Position; instrumentSize = ModuleUtils.ReadDWord(stream); name = ModuleUtils.ReadString0(stream, 22); instrumentType = ModuleUtils.ReadByte(stream); // Length samplesNumber = ModuleUtils.ReadWord(stream); samples.Clear(); if (samplesNumber > 0) { headerSize = ModuleUtils.ReadDWord(stream); for (uint i = 0; i < 96; i++) { keymapAssignements.Add(ModuleUtils.ReadByte(stream)); } for (uint i = 0; i < 24; i++) { pointsForVolumeEnvelope.Add(ModuleUtils.ReadWord(stream)); } for (uint i = 0; i < 24; i++) { pointsForPanningEnvelope.Add(ModuleUtils.ReadWord(stream)); } numberOfVolumePoints = ModuleUtils.ReadByte(stream); numberOfPanningPoints = ModuleUtils.ReadByte(stream); volumeSustainPoint = ModuleUtils.ReadByte(stream); volumeLoopStartPoint = ModuleUtils.ReadByte(stream); volumeLoopEndPoint = ModuleUtils.ReadByte(stream); panningSustainPoint = ModuleUtils.ReadByte(stream); panningLoopStartPoint = ModuleUtils.ReadByte(stream); panningLoopEndPoint = ModuleUtils.ReadByte(stream); volumeType = ModuleUtils.ReadByte(stream); // bit 0: On; 1: Sustain; 2: Loop; panningType = ModuleUtils.ReadByte(stream); // bit 0: On; 1: Sustain; 2: Loop; vibratoType = ModuleUtils.ReadByte(stream); vibratoSweep = ModuleUtils.ReadByte(stream); vibratoDepth = ModuleUtils.ReadByte(stream); vibratoRate = ModuleUtils.ReadByte(stream); volumeFadeout = ModuleUtils.ReadWord(stream); //for (uint i = 0; i < 22; i++) reserved.Add(ModuleUtils.ReadByte(stream)); //System.Diagnostics.Debug.WriteLine("Seek : " + stream.Position + " " + (instrumentSize - 243) + "\n"); stream.Seek(instrumentSize - 241, SeekOrigin.Current); long sampleDataLength = 0; for (uint i = 0; i < samplesNumber; i++) { var sample = new XM_Sample(); sample.readHeaderFromStream(stream); sample.orderNumber = sampleOrder++; samples.Add(sample); sampleDataLength += sample.sizeInBytes; } long startSampleDataPosition = stream.Position; foreach (XM_Sample sample in samples) { sample.readSampleDataFromStream(stream); } stream.Seek(startSampleDataPosition + sampleDataLength, SeekOrigin.Begin); } else { stream.Seek(startInstrumentPosition + instrumentSize, SeekOrigin.Begin); } sample = (samples.Count > 0) ? samples[0] : null; if (sample != null) { volume = sample.volume; } }