Mercurial > hg > svapp
comparison audio/AudioGenerator.cpp @ 615:755fc02a1565
Associate a note-on time with each pending note-off as well, so we can check whether a rewind action (or looping) has caused us to jump to before the note began. Also improve implementation of note-off structure comparator
author | Chris Cannam |
---|---|
date | Mon, 13 Aug 2018 14:13:38 +0100 |
parents | 88f9266e0417 |
children | 7d3a6357ce64 |
comparison
equal
deleted
inserted
replaced
614:0aee6ff48018 | 615:755fc02a1565 |
---|---|
566 } | 566 } |
567 | 567 |
568 std::vector<ClipMixer::NoteStart> starts; | 568 std::vector<ClipMixer::NoteStart> starts; |
569 std::vector<ClipMixer::NoteEnd> ends; | 569 std::vector<ClipMixer::NoteEnd> ends; |
570 | 570 |
571 while (noteOffs.begin() != noteOffs.end() && | |
572 noteOffs.begin()->onFrame > reqStart) { | |
573 | |
574 // We must have jumped back in time, as there is a | |
575 // note-off pending for a note that hasn't begun yet. Emit | |
576 // the note-off now and discard | |
577 | |
578 off.frameOffset = 0; | |
579 off.frequency = noteOffs.begin()->frequency; | |
580 | |
581 #ifdef DEBUG_AUDIO_GENERATOR | |
582 cerr << "mixModel [clip]: adding rewind-caused note-off at frame offset 0 frequency " << off.frequency << endl; | |
583 #endif | |
584 | |
585 ends.push_back(off); | |
586 noteOffs.erase(noteOffs.begin()); | |
587 } | |
588 | |
571 for (NoteList::const_iterator ni = notes.begin(); | 589 for (NoteList::const_iterator ni = notes.begin(); |
572 ni != notes.end(); ++ni) { | 590 ni != notes.end(); ++ni) { |
573 | 591 |
574 sv_frame_t noteFrame = ni->start; | 592 sv_frame_t noteFrame = ni->start; |
575 sv_frame_t noteDuration = ni->duration; | 593 sv_frame_t noteDuration = ni->duration; |
593 #endif | 611 #endif |
594 continue; | 612 continue; |
595 } | 613 } |
596 | 614 |
597 while (noteOffs.begin() != noteOffs.end() && | 615 while (noteOffs.begin() != noteOffs.end() && |
598 noteOffs.begin()->frame <= noteFrame) { | 616 noteOffs.begin()->offFrame <= noteFrame) { |
599 | 617 |
600 sv_frame_t eventFrame = noteOffs.begin()->frame; | 618 sv_frame_t eventFrame = noteOffs.begin()->offFrame; |
601 if (eventFrame < reqStart) eventFrame = reqStart; | 619 if (eventFrame < reqStart) eventFrame = reqStart; |
602 | 620 |
603 off.frameOffset = eventFrame - reqStart; | 621 off.frameOffset = eventFrame - reqStart; |
604 off.frequency = noteOffs.begin()->frequency; | 622 off.frequency = noteOffs.begin()->frequency; |
605 | 623 |
620 cout << "mixModel [clip]: adding note at frame " << noteFrame << ", frame offset " << on.frameOffset << " frequency " << on.frequency << ", level " << on.level << endl; | 638 cout << "mixModel [clip]: adding note at frame " << noteFrame << ", frame offset " << on.frameOffset << " frequency " << on.frequency << ", level " << on.level << endl; |
621 #endif | 639 #endif |
622 | 640 |
623 starts.push_back(on); | 641 starts.push_back(on); |
624 noteOffs.insert | 642 noteOffs.insert |
625 (NoteOff(on.frequency, noteFrame + noteDuration)); | 643 (NoteOff(on.frequency, noteFrame + noteDuration, noteFrame)); |
626 } | 644 } |
627 | 645 |
628 while (noteOffs.begin() != noteOffs.end() && | 646 while (noteOffs.begin() != noteOffs.end() && |
629 noteOffs.begin()->frame <= reqStart + m_processingBlockSize) { | 647 noteOffs.begin()->offFrame <= |
630 | 648 reqStart + m_processingBlockSize) { |
631 sv_frame_t eventFrame = noteOffs.begin()->frame; | 649 |
650 sv_frame_t eventFrame = noteOffs.begin()->offFrame; | |
632 if (eventFrame < reqStart) eventFrame = reqStart; | 651 if (eventFrame < reqStart) eventFrame = reqStart; |
633 | 652 |
634 off.frameOffset = eventFrame - reqStart; | 653 off.frameOffset = eventFrame - reqStart; |
635 off.frequency = noteOffs.begin()->frequency; | 654 off.frequency = noteOffs.begin()->frequency; |
636 | 655 |