Пример #1
0
    int TransposeNote(int direction, int data)
    {
        if (data < 0)
        {
            return(data);
        }

        int note = (int)VirtualKeyboard.GetNote(data) - 1;

        if (note + 1 == ( int )VirtualKeyboard.Note.NoteOff)
        {
            return(data);
        }

        int octave = VirtualKeyboard.GetOctave(data);

        int offset = note + direction;

        if (offset > 11)
        {
            octave++;
        }
        if (offset < 0)
        {
            octave--;
            offset = offset + 12;
        }

        offset = System.Math.Abs(offset) % 12 + 1;

        return(VirtualKeyboard.EncodeNoteInfo(offset, octave));
    }
Пример #2
0
    private void ParsePSGData(byte data)
    {
        bool first = (data & 128) != 0;

        if (first)
        {
            m_CurrReg  = (data >> 5) & 3;
            m_CurrType = (data >> 4) & 1;
        }

        if (m_CurrType != 0)
        {
            m_LastVol[m_CurrReg] = 0x0f - (data & 0x0f);
            this.data.SetData(m_CurrReg, m_CurrRow, 2, m_LastVol[m_CurrReg]);
        }
        else if (first && m_CurrReg == 3)
        {
            //set noise
            int noise = (data & 7);
            int nf    = noise & 3;
            m_NoiseCH2   = nf == 3;
            m_NoiseMode  = (m_NoiseCH2 ? 1 : 0);
            m_NoiseMode |= ((noise >> 2) & 1) << 4;

            if (!m_NoiseCH2)
            {
                this.data.SetData(3, m_CurrRow, 3, 0x20);
                this.data.SetData(3, m_CurrRow, 4, m_NoiseMode);
                this.data.SetData(3, m_CurrRow, 0, (int)VirtualKeyboard.EncodeNoteInfo(1 + nf, 3));
                this.data.SetData(3, m_CurrRow, 1, 1);
                this.data.SetData(m_CurrReg, m_CurrRow, 2, m_LastVol[3]);
            }
        }
        else if (first)
        {
            m_CurrFreq = (data & 0x0f);
        }
        else
        {
            m_CurrFreq = (m_CurrFreq & 0x0f) | ((data & 0x3f) << 4);
            byte noteData = GetEncodedNoteData(m_CurrFreq);
            if (m_CurrReg != 2 || !m_NoiseCH2)
            {
                this.data.SetData(m_CurrReg, m_CurrRow, 0, noteData);
                this.data.SetData(m_CurrReg, m_CurrRow, 1, 0);
                this.data.SetData(m_CurrReg, m_CurrRow, 2, m_LastVol[m_CurrReg]);
            }
            else
            {
                this.data.SetData(3, m_CurrRow, 3, 0x20);
                this.data.SetData(3, m_CurrRow, 4, m_NoiseMode);
                this.data.SetData(3, m_CurrRow, 0, noteData);
                this.data.SetData(3, m_CurrRow, 1, 1);
                this.data.SetData(3, m_CurrRow, 2, m_LastVol[3]);
            }
        }
    }
Пример #3
0
    private byte GetEncodedNoteData(int div)
    {
        if (div == 0)
        {
            return(VirtualKeyboard.EncodeNoteInfo(1, 12));
        }
        int invRelativenote;
        int freq    = (int)SN76489.Clock.PAL / (2 * div * 16);
        int relNote = Mathf.RoundToInt(Mathf.Log(freq * 440) / Mathf.Log(Mathf.Pow(2, 1f / 12f))) + 12 * 3 + 2;

        int note   = (relNote % 12) + 1;
        int octave = relNote / 12;

        return(VirtualKeyboard.EncodeNoteInfo(note, octave));
    }