timning debug

This commit is contained in:
2026-01-13 21:46:33 -06:00
parent 1121dedcee
commit a9f474f397
6 changed files with 27 additions and 4 deletions

View File

@@ -45,7 +45,8 @@ void KeyboardController::handleKeyPress(QKeyEvent* e) {
queue_.push({
NoteEventType::NoteOn,
it->second,
0.8f
0.8f,
std::chrono::high_resolution_clock::now()
});
}
@@ -59,6 +60,7 @@ void KeyboardController::handleKeyRelease(QKeyEvent* e) {
queue_.push({
NoteEventType::NoteOff,
it->second,
0.8f
0.8f,
std::chrono::high_resolution_clock::now()
});
}

View File

@@ -68,7 +68,8 @@ void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
noteQueue_.push({
NoteEventType::NoteOn,
static_cast<uint8_t>(note),
vel / 127.0f
vel / 127.0f,
std::chrono::high_resolution_clock::now()
});
}
// Note Off (or Note On with velocity 0)
@@ -76,7 +77,10 @@ void MidiController::handleMessage(const std::vector<unsigned char>& msg) {
noteQueue_.push({
NoteEventType::NoteOff,
static_cast<uint8_t>(note),
0.0f
0.0f,
std::chrono::high_resolution_clock::now()
});
}
std::cout << "MidiHandleMessage start (0)" << std::endl;
}

View File

@@ -1,5 +1,6 @@
#include "NoteQueue.h"
#include <iostream>
bool NoteQueue::push(const NoteEvent& event) {
size_t head = head_.load(std::memory_order_relaxed);
@@ -9,6 +10,9 @@ bool NoteQueue::push(const NoteEvent& event) {
buffer_[head] = event;
head_.store(next, std::memory_order_relaxed);
std::cout << "Notequeue::push: " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - event.timestamp) << std::endl;
return true;
}
@@ -19,5 +23,8 @@ bool NoteQueue::pop(NoteEvent& event) {
event = buffer_[tail];
tail_.store((tail + 1) % SIZE, std::memory_order_release);
std::cout << "Notequeue::pop: " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - event.timestamp) << std::endl;
return true;
}

View File

@@ -4,6 +4,7 @@
#include <array>
#include <atomic>
#include <cstdint>
#include <chrono>
enum class NoteEventType {
NoteOn,
@@ -14,6 +15,7 @@ struct NoteEvent {
NoteEventType type; // noteOn or noteOff
uint8_t note; // 0-128, a keyboard goes 0-87
float velocity; // 0-1, from a midi instrument its 0-127 though
std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;
};
// the queue is to keep track of note events from the UI/input thread to the audio engine thread

View File

@@ -31,6 +31,10 @@ inline float Synth::getParam(ParamId id) {
}
void Synth::handleNoteEvent(const NoteEvent& event) {
std::cout << "Synth::handleNoteEvent: " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - event.timestamp) << std::endl;
lastTime = event.timestamp;
if(event.type == NoteEventType::NoteOn) {
// TODO: find quietest voice and assign a note to it instead of just the first inactive one
@@ -106,4 +110,6 @@ void Synth::process(float* out, uint32_t nFrames, uint32_t sampleRate) {
}
}
//std::cout << "Notequeue::push: " << std::chrono::high_resolution_clock::now() - lastTime << std::endl;
}

View File

@@ -52,4 +52,6 @@ private:
// for the scope
ScopeBuffer* scope_ = nullptr;
std::chrono::time_point<std::chrono::high_resolution_clock> lastTime;
};