Exemplo n.º 1
0
        public override void ReadHeaderFromStream(Stream stream, ref uint orderNumber)
        {
            this.orderNumber = orderNumber;
            name             = ModuleUtils.ReadString0(stream, 22);
            length           = (uint)ModuleUtils.ReadWordSwap(stream) * 2; // Length
            sizeInBytes      = length;

            fineTune = stream.ReadByte() & 0xF; // finetune Value>7 means negative 8..15= -8..-1
            fineTune = (fineTune > 7) ? fineTune - 16 : fineTune;

            int vol = stream.ReadByte(); // volume 64 is maximum

            volume = (vol > 64) ? 1.0f : (float)vol / 64.0f;

            //// Repeat start and stop
            repeatStart  = (uint)ModuleUtils.ReadWordSwap(stream) * 2;
            repeatLength = (uint)ModuleUtils.ReadWordSwap(stream) * 2;
            repeatStop   = repeatStart + repeatLength;

            if (length < 4)
            {
                length = 0;
            }

            if (length > 0)
            {
                if (repeatStart > length)
                {
                    repeatStart = length;
                }

                if (repeatStop > length)
                {
                    repeatStop = length;
                }

                if (repeatStart >= repeatStop || repeatStop <= 8 || (repeatStop - repeatStart) <= 4)
                {
                    repeatStart = repeatStop = 0;
                    loopType    = 0;
                }

                if (repeatStart < repeatStop)
                {
                    loopType = ModuleConst.LOOP_ON;
                }
            }
            else
            {
                loopType = 0;
            }

            repeatLength = (uint)(repeatStop - repeatStart);
        }
Exemplo n.º 2
0
        public string InstrumentsToString()
        {
            string res = "Instruments info : \n";
            uint   i   = 1;

            foreach (XM_Instrument inst in Instruments.List)
            {
                res += ModuleUtils.GetAsDec((int)i++, 3) + " : " + inst.ToString().Trim() + "\n";
            }
            return(res);
        }
Exemplo n.º 3
0
        public string InstrumentsToString()
        {
            string res = "Samples info : \n";
            int    i   = 0;

            foreach (MOD_Instrument inst in Instruments.List)
            {
                res += ModuleUtils.GetAsHex((uint)i++, 2) + ':' + inst.ToString() + "\n";
            }
            return(res);
        }
Exemplo n.º 4
0
 public override void ReadSampleDataFromStream(Stream stream)
 {
     sampleData.Clear();
     if (length > 0)
     {
         for (int s = 0; s < length; s++)
         {
             float sampleValue = ModuleUtils.ReadSignedByte(stream) * 0.0078125f; // 0.0078125f = 1/128
             sampleData.Add(sampleValue * ModuleConst.SOUND_AMP);
         }
     }
 }
Exemplo n.º 5
0
 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);
         }
     }
 }
Exemplo n.º 6
0
        public string SamplesToString()
        {
            string res = "Samples info : \n";
            uint   i   = 1;

            foreach (XM_Instrument inst in Instruments.List)
            {
                foreach (XM_Sample sample in inst.samples)
                {
                    res += ModuleUtils.GetAsDec((int)i++, 3) + " : " + sample.ToString().Trim() + "\n";
                }
            }
            return(res);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public override bool ReadFromStream(Stream stream)
        {
            if (!CheckFormat(stream))
            {
                return(false);
            }

            fileLength = stream.Length;
            baseVolume = 1.0f;
            BPM        = 125;
            tempo      = 6;

            stream.Seek(0, SeekOrigin.Begin);
            moduleID            = ModuleUtils.ReadString0(stream, 17);
            songName            = ModuleUtils.ReadString0(stream, 20);
            XM_1A_Byte          = (byte)stream.ReadByte();
            trackerName         = ModuleUtils.ReadString0(stream, 20);
            version             = ModuleUtils.ReadWord(stream);
            headerSize          = (uint)ModuleUtils.ReadDWord(stream);
            songLength          = ModuleUtils.ReadWord(stream);
            songRepeatPosition  = ModuleUtils.ReadWord(stream);
            numberOfChannels    = ModuleUtils.ReadWord(stream);
            numberOfPatterns    = ModuleUtils.ReadWord(stream);
            numberOfInstruments = ModuleUtils.ReadWord(stream);
            XM_Flags            = (uint)ModuleUtils.ReadWord(stream);
            tempo = ModuleUtils.ReadWord(stream);
            BPM   = ModuleUtils.ReadWord(stream);

            ReadArrangement(stream);        // read pattern order
            ReadPatterns(stream);           // read patterns
            ReadInstruments(stream);        // read instruments

            DebugMes(InstrumentsToString());
            DebugMes(SamplesToString());

            mixer = new XM_Mixer(this);
            return(true);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        public override string ToString()
        {
            string res = ModuleConst.GetNoteNameToIndex((int)noteIndex);

            res += ((period == 0 && noteIndex != 0) || (period != 0 && noteIndex == 0)) ? "!" : " ";
            res += (instrumentIndex != 0) ? ModuleUtils.GetAsHex(instrumentIndex, 2) : "..";
            res += " ";
            res += ((effekt != 0) || (effektOp != 0)) ? ModuleUtils.GetAsHex(effekt, 1) + ModuleUtils.GetAsHex(effektOp, 2) : "...";
            return(res);
        }
Exemplo n.º 11
0
        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;
            }
        }
Exemplo n.º 12
0
        // NOTE : this function load regular delta packed sample data
        // TODO : need to do loading of AD = 4-bit ADPCM-compressed sample data
        public void readSampleDataFromStream(Stream stream)
        {
            sampleData.Clear();
            float ampDivider = ((type & 0x10) != 0) ? 0.000030517578125f /* 1/32768 */ : 0.0078125f /* 1/128 */;

            if (length > 0)
            {
                float oldValue = 0;
                for (uint i = 0; i < length; i++)
                {
                    float sampleValue;
                    sampleValue = ((type & 0x10) != 0) ? ModuleUtils.ReadSignedWordSwap(stream) : ModuleUtils.ReadSignedByte(stream);
                    oldValue   += sampleValue * ampDivider;
                    if (oldValue < -1)
                    {
                        oldValue += 2;
                    }
                    else if (oldValue > 1)
                    {
                        oldValue -= 2;
                    }
                    sampleData.Add(oldValue * ModuleConst.SOUND_AMP);
                }
            }
        }