Hii mates,
I need your help with a programming issue .
I want to implement an equation on my arduino sketch with 4 parameters, A, B and C and D.
What I want is to be able to change the value of those parameters depending of the chosen selection of a SoundProfile.
Parameters present are: global volume, mixing factor for each wav file, silence for each wav (for eg : if velocity of bike is low, silence is low it means (sample - silence for long time - sample- silence....)) and velocity is high silence is for short time and last parameter is speed of wav file means velocity of bike is low it will read each sample in wave table else if velocity is high it reads every 10th sample.
These are Sound Profile I have created .
Sound Profile 1 : x.wav, volume will increase or decrease corresponding to velocity of bike
Sound Profile 2 : y.wav, speed and silence are modified other parameters are constant
sound Profile 3 : z.wav , Silence is modified and other parameters are constant.
Note: All parameters ranges from (0 to 1) for eg : 0 low vol and 1 high vol except silence ranges from 0 to 10.
Now My issue is I want to create such an equation which should be universal to all sound profiles.
I had created a code which will make you understand more clearly. I am getting the output but problem the coding approach is not good because for every switching between sound profile ,code changes which is not good only change parameter according to speed of bike.
My skill in coding are basics. Thanks in advance.
switch (currentSoundProfile) {
case 1: {
// Sound Profile 1 : Only Volume modification other parameter constant
if (currentSoundProfile != oldProfile) {
for (int i = 0 ; i < samplernumber ; i++) {
sampler[i].sstop();
}
sampler[0].init();
sampler[0].load("/SoundP~1/1.wav");
sampler[0].splay();
sampler[0].buffill();
oldProfile = currentSoundProfile;
Serial.println(F("Sound Profile ? "));
} else {
sampler[0].splay();
sampler[0].buffill();
oldProfile = currentSoundProfile;
}
// Set Silence
sampler[0].setSil(SIL_MAX);
// Set Speed
sampler[0].setSpeed1(SPEED_MAX);
// MIX factor of 1.wav
m1 = MIX_1;
// Modification Volume
v0 = log(kph);
sampler[0].setVol(v0);
// Can load any sound Profile in sampler0
while (Serial.available() == 0) {
loop();
}
currentSoundProfile = Serial.parseInt();
Serial.println(currentSoundProfile);
break;
}
case 2 : {
// Speed and silence Modification and other parameters constant
if (currentSoundProfile != oldProfile) {
for (int i = 0 ; i < samplernumber ; i++) {
sampler[i].sstop();
}
sampler[1].init();
sampler[1].load("/SoundP~1/2.wav");
sampler[1].splay();
sampler[1].buffill();
oldProfile = currentSoundProfile;
Serial.println(F("Sound Profile ? "));
} else {
sampler[1].splay();
sampler[1].buffill();
oldProfile = currentSoundProfile;
}
// Modification of Silence
s1 = sqrt(kph);
sampler[1].setSil(s1);
// modification of speed of wav file
//n1 = log(kph);
kph = kph / MAX_VEHICLE_SPEED; // Smooth sound
n1 = exp(kph);
sampler[1].setSpeed1(n1);
//Set Volume
sampler[1].setVol(VOL_MAX);
m2 = MIX_2;
// Serial.println(F("Sound Profile ? "));
while (Serial.available() == 0) {
loop();
}
currentSoundProfile = Serial.parseInt();
// Serial.print("Sound Profile : ");
Serial.println(currentSoundProfile);
break;
}