Skip to content

Polyphony Handling #5

@JoshuaStorm

Description

@JoshuaStorm

Putting this up for my own sanity

New Design for Polyphony Handling:

  • Maintain an array of doubly linked list nodes spanning all 128 MIDI notes
  • The linked list nodes will compose two distinct linked lists
    • OFF list - similar to a free list, these notes are off. Order is unimportant
      • Keep a pointer to the last off list node.
    • ON list - a list of notes currently depressed. Order is important
      • Keep a pointer to the last and first on list node

Depressing a note O(1)

  • Stitch the OFF list to exclude this note. O(1) runtime
  • Add note to end of ON list Add note to front of ON list. O(1) runtime

Releasing a note O(1)

  • Stitch the ON list to exclude this note. O(1) runtime
  • Add note to end of OFF list. O(1) runtime

Reading the current notes to play O(numVoices)

  • Traverse ON list to get the note at this voice index. O(numVoices)

Reading the current notes to play could be sped up to O(1) by significantly increasing complexity (maintaining an array of currently playing voices indices), may actually be necessary since this will need numVoices calls per noteOn/noteOff => O(numvoices^2) = 16384 but we'll see

Also, a great benefit of this O(numVoices) solution is that it allows arbitrary scaling of the number of voices. We won't actually need to declare anywhere in MemConfig or the initializer a number of voices, a client can just arbitrarily use this for any number of voices they want

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions