The faders (see previous log) now work perfectly! They are controlling the sound of the instruments, in real time.
The next big thing that's to be connected to the GUI, and work in real time is the metronome. Give the architecture of eXaDrums, it was a lot easier than expected. The metronome is going to be a class that generate a signal that depends on the chosen tempo, and add that sound to the sound bank. The sound only contains one bar, as the sound class will allow sounds to be played in a loop!
The prototyping (using Octave) looks quite promising. Here's the output what's going to become the GenerateSine function of the metronome class.
Since I usually share my code, here's the octave code (it even plays the sound!):
clear all; % Metronome parameters rhythm = 2; timeSig = 4; tempo = 120; beatsPerMeasure = 4; % Alsa parameters sampleRate = 48000; %bufferSize = 160; % Calculate number of samples beatsPerSecond = rhythm * tempo/60; measureTime = beatsPerMeasure / beatsPerSecond; numSamples = measureTime * sampleRate; %nPeriods = numSamples / bufferSize %offset = nPeriods - floor(nPeriods) %correction = round(offset * bufferSize) data = zeros(1, numSamples); beatsFreq = 1/beatsPerSecond; beatsRate = floor(sampleRate*beatsFreq); % Sine parameters fSineHz = 880; radiansPerSample = fSineHz * 2*pi/sampleRate; clickDuration = 10/1000; clickSamples = sampleRate*clickDuration; n = 0; phase = 0; for i = 1:length(data) click = n * beatsRate; % + correction if (i > click) && (i < click + clickSamples) if(mod(n+1, timeSig) == 1) mul = 2; else mul = 1; end phase += mul*radiansPerSample; data(i) = sin(phase); else data(i) = 0; phase = 0; if i == (click + clickSamples) n++; end end end sound(data, sampleRate); plot(data)
Note that you can change the time signature, rhythm, and tempo.
Full C++ code to be found on Github pretty soon ;).
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.