Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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;
            }
        }