0

I made a simple portamento function:

  func portamento(oldNote:Double, newNote:Double){
     if oldNote < newNote {
     while oldNote < newNote {
          oldNote += 1
     }
     } else {
     while oldNote > newNote {
           oldNote -= 1
     }
 }

}

this works but after pressing a few notes theres is major delay/lag time and it continues to perform until the number of times I pressed the note is complete. How can I avoid lag/delay in processing this function in realtime?

Jonny123
  • 59
  • 5
  • when and how do you call this function? – mahal tertin Jun 18 '18 at 07:40
  • I call it when the note is pressed during “receivedNoteOn”. – Jonny123 Jun 18 '18 at 10:17
  • and when do you call noteOff? – mahal tertin Jun 18 '18 at 11:36
  • @mahaltertin when I call “receivedNoteOff” – Jonny123 Jun 18 '18 at 13:08
  • @mahaltertin Do you think I should set the portamento function as a background process? – Jonny123 Jun 18 '18 at 13:16
  • no, but you'll have to call noteOff for exactly the note you sent noteOn. I still don't really get how your function works. What happens if oldNote and newNote are equal? Infinite Loop? And what is done with the result of your calculation? – mahal tertin Jun 18 '18 at 13:50
  • the function basically increases/decreases the current note until it equals the new note (creating a sliding/portamento effect). "What happens if oldNote and newNote are equal? Infinite Loop?" that doesn't happen because pressed notes are added to an array and removed from the array when released. I suspect that the while loop is executed and runs until it completes the calculation and THEN moves onto the next even (such as note off) which is why there is a lag. But how can I interrupt the while loop? – Jonny123 Jun 18 '18 at 14:00
  • Use Instruments to measure where most of the time is spent in your "major delay". Please update your question with the code how you call the function (with the array handling). Also use the green checkmark on left hand side on answers of your previous questions to motivate us answer your questions. At the moment the question is lacking relevant information to get a good answer. – mahal tertin Jun 18 '18 at 15:39

0 Answers0