Exemplo n.º 1
0
        /// <summary>
        ///     Applies all changes to the underlying ObjectPropertyList
        /// </summary>
        public void Apply()
        {
            if (Opl == null || _Buffer.Count == 0)
            {
                _Buffer.Clear();
                return;
            }

            while (_Buffer.Count > 0)
            {
                var info = Lookup(Index++);

                if (info == null)
                {
                    break;
                }

                if (!info.HasArgs)
                {
                    continue;
                }

                var final = String.Empty;

                var take = 0;

                for (var i = 0; i < _Buffer.Count; i++)
                {
                    var s = _Buffer[i];

                    if (i > 0)
                    {
                        final += '\n';
                    }

                    if (String.IsNullOrWhiteSpace(s))
                    {
                        s = " ";
                    }

                    final += s;

                    if (++take >= LineBreak || final.Length >= ClilocThreshold)
                    {
                        break;
                    }
                }

                if (take == 0)
                {
                    break;
                }

                _Buffer.RemoveRange(0, take);

                Opl.Add(info.Index, info.ToString(final));
            }

            _Buffer.Clear();
        }
Exemplo n.º 2
0
        public bool NextEmpty(out ClilocInfo info)
        {
            info = null;

            if (IsDisposed || Opl == null)
            {
                return(false);
            }

            for (int i = 0, index; i < EmptyClilocs.Length; i++)
            {
                index = EmptyClilocs[i];

                if (!Opl.Contains(index))
                {
                    info = ClilocLNG.NULL.Lookup(index);

                    if (info != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public bool Update()
        {
            if (notenum >= songlen)
            {
                songend = true;
                notenum = last = 0;
            }

            for (var c = 0; c < 9; c++)
            {
                if (music[notenum * 9 + c] != music[last * 9 + c])
                {
                    Opl.WriteReg(0xb0 + c, 0);
                }
            }

            for (var c = 0; c < 9; c++)
            {
                if (music[notenum * 9 + c] != 0)
                {
                    PlayNote(c, music[notenum * 9 + c] % 12, music[notenum * 9 + c] / 12);
                }
                else
                {
                    PlayNote(c, 0, 0);
                }
            }

            last = notenum;
            notenum++;
            return(!songend);
        }
Exemplo n.º 4
0
        private void Rewind(int subsong)
        {
            // set basic variables
            _songend = 0; _ord = 0; _crow = 0; _tempo = _header.it;
            _speed   = _header.@is; _del = 0; _loopstart = 0; _loopcnt = 0;

            Opl.WriteReg(1, 32);          // Go to ym3812 mode
        }
Exemplo n.º 5
0
 public override void _Ready()
 {
     base._Ready();
     AudioStreamPlayer = new AudioStreamPlayer();
     Opl.Init((int)AudioStreamGenerator.MixRate);
     AudioStreamPlayer.Play();
     FillBuffer();
 }
Exemplo n.º 6
0
 public AdlPlayer SetInstrument()
 {
     for (uint i = 0; i < Adl.InstrumentPorts.Length; i++)
     {
         Opl.WriteReg(Adl.InstrumentPorts[i], Adl.Instrument[i]);
     }
     Opl.WriteReg(0xC0, 0); // Wolf3D's code ignores this value in its sound data, always setting it to zero instead.
     return(this);
 }
Exemplo n.º 7
0
        private void SetVolume(byte chan)
        {
            byte op = OplHelper.op_table[chan], insnr = _channel[chan]._inst;

            Opl.WriteReg(0x43 + op, (int)(63 - ((63 - (_inst[insnr].d03 & 63)) / 63.0) * _channel[chan].vol) + (_inst[insnr].d03 & 192));
            if ((_inst[insnr].d0a & 1) != 0)
            {
                Opl.WriteReg(0x40 + op, (int)(63 - ((63 - (_inst[insnr].d02 & 63)) / 63.0) * _channel[chan].vol) + (_inst[insnr].d02 & 192));
            }
        }
Exemplo n.º 8
0
        private void PlayNote(int c, int note, int octv)
        {
            int freq = OplHelper.note_table[note];

            if (note == 0 && octv == 0)
            {
                freq = 0;
            }
            Opl.WriteReg(0xa0 + c, freq & 0xff);
            Opl.WriteReg(0xb0 + c, (freq / 0xff) | 32 | (octv * 4));
        }
Exemplo n.º 9
0
 private void SetFreq(byte chan)
 {
     Opl.WriteReg(0xa0 + chan, _channel[chan].freq & 255);
     if (_channel[chan].key != 0)
     {
         Opl.WriteReg(0xb0 + chan, (((_channel[chan].freq & 768) >> 8) + (_channel[chan].oct << 2)) | 32);
     }
     else
     {
         Opl.WriteReg(0xb0 + chan, ((_channel[chan].freq & 768) >> 8) + (_channel[chan].oct << 2));
     }
 }
Exemplo n.º 10
0
        public bool Update()
        {
            while (iPos < iLength)
            {
                int iIndex = data[iPos++];
                int iValue = data[iPos++];

                // Short delay
                if (iIndex == iCmdDelayS)
                {
                    iDelay = iValue + 1;
                    return(true);

                    // Long delay
                }
                else if (iIndex == iCmdDelayL)
                {
                    iDelay = (iValue + 1) << 8;
                    return(true);

                    // Normal write
                }
                else
                {
                    if ((iIndex & 0x80) != 0)
                    {
                        // High bit means use second chip in dual-OPL2 config
                        // TODO:?
                        //Opl.setchip(1);
                        iIndex &= 0x7F;
                    }
                    else
                    {
                        // TODO:?
                        //Opl.Setchip(0);
                    }
                    if (iIndex >= iConvTableLen)
                    {
                        Console.WriteLine("DRO2: Error - index beyond end of codemap table!  Corrupted .dro?\n");
                        return(false); // EOF
                    }
                    int iReg = piConvTable[iIndex];
                    Opl.WriteReg(iReg, iValue);
                }
            }

            // This won't result in endless-play using Adplay, but IMHO that code belongs
            // in Adplay itself, not here.
            return(iPos < iLength);
        }
Exemplo n.º 11
0
        public OplPlayer FillBuffer()
        {
            int toFill = AudioStreamGeneratorPlayback.GetFramesAvailable() * (Opl.IsStereo ? 2 : 1);

            if (Buffer.Length < toFill)
            {
                Buffer = new short[toFill];
            }
            Opl.ReadBuffer(Buffer, 0, toFill);
            for (uint i = 0; i < toFill; i++)
            {
                float soundbite = Buffer[i] / 32767f; // Convert from 16 bit signed integer audio to 32 bit signed float audio
                Vector2.Set(soundbite, soundbite);
                AudioStreamGeneratorPlayback.PushFrame(Vector2);
            }
            return(this);
        }
Exemplo n.º 12
0
        public override string GenerateNewLabel()
        {
            string baseLabel = this.Label + "(";

            if (Opl != null)
            {
                baseLabel += Opl.GetDisplayValue() + " in ";
            }

            if (Opr != null)
            {
                baseLabel += Opr.GetDisplayValue();
            }

            baseLabel += ")";

            return(baseLabel);
        }
Exemplo n.º 13
0
        public bool Update()
        {
            while (_pos < _data.Length)
            {
                int iIndex = _data[_pos++];
                int iValue;
                if (iIndex == iCmdDelayS)
                {
                    // Short delay
                    iValue = _data[_pos++];
                    _delay = iValue + 1;
                    return(true);
                }
                if (iIndex == iCmdDelayL)
                {
                    // Long delay
                    iValue = _data[_pos] | (_data[_pos + 1] << 8);
                    _pos  += 2;
                    _delay = (iValue + 1);
                    return(true);
                }
                else if (iIndex == 0x02 || iIndex == 0x03)
                {
                    // Bank switching
                    // TODO:?
                    //_opl.SetChip(iIndex - 0x02);

                    // Normal write
                }
                else
                {
                    if (iIndex == 0x04)
                    {
                        iIndex = _data[_pos++];
                    }
                    iValue = _data[_pos++];
                    Opl.WriteReg(iIndex, iValue);
                }
            }

            // This won't result in endless-play using Adplay, but IMHO that code belongs
            // in Adplay itself, not here.
            return(_pos < _data.Length);
        }
Exemplo n.º 14
0
 private void Rewind(int subsong)
 {
     notenum = last = 0;
     songend = false;
     Opl.WriteReg(1, 32);
     for (var i = 0; i < 9; i++)
     {
         Opl.WriteReg(0x20 + OplHelper.op_table[i], inst[i].value[0]);
         Opl.WriteReg(0x23 + OplHelper.op_table[i], inst[i].value[1]);
         Opl.WriteReg(0x40 + OplHelper.op_table[i], inst[i].value[2]);
         Opl.WriteReg(0x43 + OplHelper.op_table[i], inst[i].value[3]);
         Opl.WriteReg(0x60 + OplHelper.op_table[i], inst[i].value[4]);
         Opl.WriteReg(0x63 + OplHelper.op_table[i], inst[i].value[5]);
         Opl.WriteReg(0x80 + OplHelper.op_table[i], inst[i].value[6]);
         Opl.WriteReg(0x83 + OplHelper.op_table[i], inst[i].value[7]);
         Opl.WriteReg(0xe0 + OplHelper.op_table[i], inst[i].value[8]);
         Opl.WriteReg(0xe3 + OplHelper.op_table[i], inst[i].value[9]);
         Opl.WriteReg(0xc0 + OplHelper.op_table[i], inst[i].value[10]);
     }
 }
Exemplo n.º 15
0
 public AdlPlayer PlayNote()
 {
     if (Adl.Notes[CurrentNote] == 0)
     {
         Note = false;
     }
     else
     {
         if (!Note)
         {
             Note = true;
         }
         Opl.WriteReg(Adl.NotePort, Adl.Notes[CurrentNote]);
     }
     CurrentNote++;
     if (CurrentNote >= Adl.Notes.Length)
     {
         Adl = null;
     }
     return(this);
 }
Exemplo n.º 16
0
        public bool Update()
        {
            do
            {
                Opl.WriteReg(_data[_pos].reg, _data[_pos].val);
                _del = _data[_pos].time;
                _pos++;
            } while (_del == 0 && _pos < _size);

            if (_pos >= _size)
            {
                _pos     = 0;
                _songend = true;
            }
            else
            {
                RefreshRate = _rate / _del;
            }

            return(!_songend);
        }
Exemplo n.º 17
0
        protected override string GeneratePropertiesLabel()
        {
            bool   isFirstChild = (this.Node == null || this.Node.Attachments.Count == 0 || this.Node.Attachments[0] == this);
            string baseLabel    = string.Empty;

            if (Opl != null)
            {
                baseLabel += Opl.GetDisplayValue() + " ";
            }

            System.Reflection.FieldInfo fi = Operator.GetType().GetField(Operator.ToString());
            Attribute[] attributes         = (Attribute[])fi.GetCustomAttributes(typeof(EnumMemberDescAttribute), false);
            if (attributes.Length > 0)
            {
                baseLabel += ((EnumMemberDescAttribute)attributes[0]).DisplayName;
            }

            if (Opr != null)
            {
                baseLabel += " " + Opr.GetDisplayValue();
            }

            string propertiesLabel = string.Empty;

            if (isFirstChild)
            {
                propertiesLabel = baseLabel;
            }
            else
            {
                fi         = BinaryOperator.GetType().GetField(BinaryOperator.ToString());
                attributes = (Attribute[])fi.GetCustomAttributes(typeof(EnumMemberDescAttribute), false);
                if (attributes.Length > 0)
                {
                    propertiesLabel = ((EnumMemberDescAttribute)attributes[0]).DisplayName + "(" + baseLabel + ")";
                }
            }

            return(propertiesLabel);
        }
Exemplo n.º 18
0
        private void Rewind(int subsong)
        {
            _delay = 0;
            _pos   = 0;

            // DRO v1 assumes all registers are initialized to 0.
            // Registers not initialized to 0 will be corrected
            //  in the data stream.
            // opl->setchip(0);
            for (var i = 0; i < 256; i++)
            {
                Opl.WriteReg(i, 0);
            }

            // opl->setchip(1);
            for (var i = 0; i < 256; i++)
            {
                Opl.WriteReg(i, 0);
            }

            // opl->setchip(0);
        }
Exemplo n.º 19
0
        /// <summary>
        ///     Applies all changes to the underlying ObjectPropertyList
        /// </summary>
        public void Apply()
        {
            if (Opl == null || Count == 0)
            {
                return;
            }

            for (; _Index < EmptyClilocs.Length + EmptyMultiClilocs.Length; _Index++)
            {
                var range = GetCurrentRange();

                if (range.Count == 0)
                {
                    break;
                }

                if (_Index < EmptyClilocs.Length)
                {
                    Opl.Add(EmptyClilocs[_Index], String.Join("\n", range));
                }
                else
                {
                    int index  = _Index - EmptyClilocs.Length;
                    var args   = new object[EmptyMultiClilocs[index, 1]];
                    var format = new string[args.Length];

                    args.For(
                        i =>
                    {
                        args[i]   = i == 0 ? String.Join("\n", range) : String.Empty;
                        format[i] = "{" + i + "}";
                    });

                    Opl.Add(EmptyMultiClilocs[index, 0], String.Join("\t", format), args);
                }
            }

            _Index = 0;
        }
Exemplo n.º 20
0
        private void PlayNote(byte chan)
        {
            byte op = OplHelper.op_table[chan], insnr = _channel[chan]._inst;

            Opl.WriteReg(0xb0 + chan, 0); // stop old note

            // set instrument data
            Opl.WriteReg(0x20 + op, _inst[insnr].d00);
            Opl.WriteReg(0x23 + op, _inst[insnr].d01);
            Opl.WriteReg(0x40 + op, _inst[insnr].d02);
            Opl.WriteReg(0x43 + op, _inst[insnr].d03);
            Opl.WriteReg(0x60 + op, _inst[insnr].d04);
            Opl.WriteReg(0x63 + op, _inst[insnr].d05);
            Opl.WriteReg(0x80 + op, _inst[insnr].d06);
            Opl.WriteReg(0x83 + op, _inst[insnr].d07);
            Opl.WriteReg(0xe0 + op, _inst[insnr].d08);
            Opl.WriteReg(0xe3 + op, _inst[insnr].d09);
            Opl.WriteReg(0xc0 + chan, _inst[insnr].d0a);

            // set frequency & play
            _channel[chan].key = 1;
            SetFreq(chan);
        }
Exemplo n.º 21
0
 public ImfPlayer PlayNotes(float delta)
 {
     TimeSinceLastPacket += delta;
     while (CurrentPacket < Song.Length && TimeSinceLastPacket >= CurrentPacketDelay)
     {
         TimeSinceLastPacket -= CurrentPacketDelay;
         do
         {
             CurrentPacket++;
             if (CurrentPacket < Song.Length)
             {
                 Opl.WriteReg(Song[CurrentPacket].Register, Song[CurrentPacket].Data);
             }
         }while (CurrentPacket < Song.Length && Song[CurrentPacket].Delay == 0);
         CurrentPacketDelay = CurrentPacket < Song.Length ?
                              Delay(Song[CurrentPacket].Delay)
             : 0;
     }
     if (CurrentPacket >= Song.Length)
     {
         Song = Mute && Loop ? Song : null;
     }
     return(this);
 }
Exemplo n.º 22
0
        /// <summary>
        ///     Applies all changes to the underlying ObjectPropertyList
        /// </summary>
        public void Apply()
        {
            if (Opl == null || Count == 0)
            {
                Clear();
                TrimExcess();
                return;
            }

            while (Count > 0)
            {
                if (!EmptyClilocs.InBounds(Index))
                {
                    break;
                }

                var info = Lookup(Index++);

                if (info == null || !info.HasArgs)
                {
                    continue;
                }

                int r = 0, l = 0;

                foreach (var entry in this)
                {
                    if (!String.IsNullOrEmpty(entry))
                    {
                        if (r > 0 && l + entry.Length >= ClilocThreshold)
                        {
                            break;
                        }

                        l += entry.Length;
                    }

                    if (++r >= LineBreak || l >= ClilocThreshold)
                    {
                        break;
                    }
                }

                if (r <= 0)
                {
                    break;
                }

                if (r == 1)
                {
                    Opl.Add(info.Index, info.ToString(Dequeue()));
                    continue;
                }

                var range = new string[Math.Min(r, Count)];

                this.DequeueRange(ref range);

                Opl.Add(info.Index, info.ToString(String.Join("\n", range)));
            }

            Clear();
            TrimExcess();
        }
Exemplo n.º 23
0
 public override void _Ready()
 {
     base._Ready();
     Opl.WriteReg(1, 0x20); // Enable different wave type selections
 }
Exemplo n.º 24
0
        /// <summary>
        ///     Applies all changes to the underlying ObjectPropertyList
        /// </summary>
        public void Apply()
        {
            if (Opl == null || _Buffer.Count == 0)
            {
                _Buffer.Clear();
                return;
            }

            ClilocInfo info;
            string     final;
            int        take;

            while (_Buffer.Count > 0)
            {
                if (!NextEmpty(out info))
                {
                    break;
                }

                if (!info.HasArgs || Opl.Contains(info.Index))
                {
                    continue;
                }

                final = String.Empty;
                take  = 0;

                for (var i = 0; i < _Buffer.Count; i++)
                {
                    var s = _Buffer[i];

                    if (i > 0)
                    {
                        final += '\n';
                    }

                    if (String.IsNullOrWhiteSpace(s))
                    {
                        s = " ";
                    }

                    final += s;

                    if (++take >= LineBreak || final.Length >= ClilocThreshold)
                    {
                        break;
                    }
                }

                if (take == 0)
                {
                    break;
                }

                _Buffer.RemoveRange(0, take);

                Opl.Add(info.Index, info.ToString(final));
            }

            _Buffer.Clear();
        }
Exemplo n.º 25
0
        public bool Load(Stream stream)
        {
            var  br = new BinaryReader(stream);
            long fsize, flsize, mfsize = 0;
            uint i;

            // file validation section
            {
                var header  = new string(br.ReadChars(5));
                var version = br.ReadByte();

                if (header != "ADLIB" || version != 1)
                {
                    stream.Seek(0, SeekOrigin.Begin); // It's a normal IMF file
                }
                else
                {
                    // It's a IMF file with header
                    track_name = ReadString(br);
                    game_name  = ReadString(br);
                    br.ReadByte();
                    mfsize = stream.Position + 2;
                }
            }

            // load section
            if (mfsize > 0)
            {
                fsize = br.ReadInt32();
            }
            else
            {
                fsize = br.ReadInt16();
            }
            flsize = stream.Length;
            if (fsize == 0)
            {       // footerless file (raw music data)
                if (mfsize != 0)
                {
                    stream.Seek(-4, SeekOrigin.Current);
                }
                else
                {
                    stream.Seek(-2, SeekOrigin.Current);
                }
                _size = (flsize - mfsize) / 4;
            }
            else        // file has got a footer
            {
                _size = fsize / 4;
            }

            _data = new Sdata[_size];
            for (i = 0; i < _size; i++)
            {
                _data[i].reg  = br.ReadByte(); _data[i].val = br.ReadByte();
                _data[i].time = br.ReadUInt16();
            }

            // read footer, if any
            if (fsize != 0 && (fsize < flsize - 2 - mfsize))
            {
                if (br.ReadByte() == 0x1a)
                {
                    // Adam Nielsen's footer format
                    track_name  = ReadString(br);
                    author_name = ReadString(br);
                    remarks     = ReadString(br);
                }
                else
                {
                    // Generic footer
                    long footerlen = flsize - fsize - 2 - mfsize;

                    _footer = ReadString(br, footerlen);
                }
            }

            _pos = 0; _del = 0; RefreshRate = _rate; _songend = false;
            Opl.WriteReg(1, 32);    // go to OPL2 mode

            return(true);
        }
Exemplo n.º 26
0
 // Write a byte to the OPL "chip" and update the current record of register states
 private void writeOPL(byte iRegister, byte iValue)
 {
     Opl.WriteReg(iRegister, iValue);
     iCurrentRegs[iRegister] = iValue;
 }