Originally Posted by
Adak
change this line:
Code:
else(velocity == 0)
//to
else if(velocity == 0)
how many states can velocity have? If it can only be > 0 or 0, then you can eliminate the code in blue.
If the velocity can be less than 0, then you may need to add an else onto this if statement, to handle
that state, as well.
velocity in midi can be 0-127. a velocity of '0' is treated as a 'note-off' msg. at the mo my synthesizer is looking like this:
Code:
#include <stdio.h>
#include "aservelibs/aservelib.h"
#include <math.h>
// function declarations
float mtof(int note);
float mtoamp(int velocity);
void processNote(int note);
int main()
{
int notes[16];
int index, note, velocity;
for(index = 0; index < 16; index ++)
{
note = aserveGetNote();
velocity = aserveGetVelocity();
notes[index] = note;
printf("Note %d\n", index);
processNote(note);
}
return 0;
}
void processNote(int note)
{
static int lastnote = -1;
int velocity;
float frequency, amp;
if(velocity > 0)
{
frequency = mtof(note);
amp = mtoamp(velocity);
printf("Note %3d = %3.2fHz\n", note, frequency);
aserveOscillator(0, frequency, amp, 0);
}
else if ( velocity == 0)
{
aserveOscillator(0, 0.0, 0.0, 0);
}
}
float mtof(int note)
{
float frequency = 440.0 * pow(2.0, (note - 69.0) / 12.0);
return frequency;
}
float mtoamp(int velocity) // note velocity to amplitude conversion
{
float amp = velocity * (1.0 / 127);
return amp;
}
its turning the osc on and off fine, but only actually synthesizing 8 notes instead of the 16.
v.