예제 #1
0
        public static WaveLibSample Serdes(int i, WaveLibSample w, ISerializer s)
        {
            w ??= new WaveLibSample();
            s.Begin();
            w.IsValid    = s.Int32(nameof(IsValid), w.IsValid);
            w.Instrument = s.Int32(nameof(Instrument), w.Instrument);
            w.Type2      = s.Int32(nameof(Type2), w.Type2);
            w.Offset     = s.UInt32(nameof(Offset), w.Offset);
            w.Length     = s.UInt32(nameof(Length), w.Length);
            w.Unk14      = s.Int32(nameof(Unk14), w.Unk14);
            w.Unk18      = s.Int32(nameof(Unk18), w.Unk18);
            w.SampleRate = s.Int32(nameof(SampleRate), w.SampleRate);

            // Check for new patterns
            ApiUtil.Assert(w.IsValid == 0 || w.IsValid == -1);
            ApiUtil.Assert(new[] { 119, 120, 121, 122, 123, 124, 125, 126, 127, -1 }.Contains(w.Instrument));
            ApiUtil.Assert(new[] { 56, 58, 60, 62, 63, 64, 66, 69, 76, 80 }.Contains(w.Type2));
            ApiUtil.Assert(w.Unk14 == 0);
            ApiUtil.Assert(w.Unk18 == 0);
            ApiUtil.Assert(w.SampleRate == 11025 || w.SampleRate == -1);

            if (w.SampleRate == -1)
            {
                w.SampleRate = 11025;
            }
            s.End();
            return(w);
        }
예제 #2
0
파일: WaveLib.cs 프로젝트: lucorp/ualbion
        public static WaveLib Serdes(WaveLib w, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            w ??= new WaveLib();
            w.Samples ??= new WaveLibSample[512];
            uint offset = WaveLibSample.SizeInBytes * MaxSamples;

            s.List(nameof(w.Samples), w.Samples, 512, (_, x, s2) => WaveLibSample.Serdes(x, s2, ref offset));

            foreach (var header in w.Samples.Where(x => x.Active))
            {
                header.Samples = s.Bytes(nameof(header.Samples), header.Samples, header.Samples.Length);
            }

            return(w);
        }
예제 #3
0
        public static WaveLibSample Serdes(WaveLibSample w, ISerializer s, ref uint nextBufferOffset)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            w ??= new WaveLibSample();
            w.Active     = s.Int32(nameof(Active), w.Active ? 0 : -1) == 0;    // 0
            w.Instrument = s.Int32(nameof(Instrument), w.Instrument);          // 4
            w.Type       = s.Int32(nameof(Type), w.Type);                      // 8

            uint offset = s.UInt32("Offset", w.Active ? nextBufferOffset : 0); // c
            int  length = s.Int32("Length", w.Samples.Length);                 // 10

            if (w.Samples.Length == 0 && length > 0)
            {
                w.Samples = new byte[length];
            }

            if (length > 0)
            {
                ApiUtil.Assert(offset == nextBufferOffset);
            }
            nextBufferOffset += (uint)length;

            int zeroed = s.Int32(null, 0); // 14

            zeroed += s.Int32(null, 0);    // 18
            if (zeroed != 0)
            {
                throw new FormatException("Expected header fields 14/18 to be 0");
            }

            w.SampleRate = s.Int32(nameof(SampleRate), w.SampleRate); // 1c

            // Check for new patterns
            ApiUtil.Assert(new[] { 119, 120, 121, 122, 123, 124, 125, 126, 127, -1 }.Contains(w.Instrument));
            ApiUtil.Assert(new[] { 56, 58, 60, 62, 63, 64, 66, 69, 76, 80 }.Contains(w.Type));
            ApiUtil.Assert(w.SampleRate == 11025 || w.SampleRate == -1);

            return(w);
        }