1. Write a C programming code that is equivalent to the following C programming
ID: 3570162 • Letter: 1
Question
1. Write a C programming code that is equivalent to the following C programming Code.
void upateTables(int note)
{
updatingNoteTable(note);
updatingFrequencyTable();
updatingPeriodTable();
}
void updateNoteTable(int note)
{
int pattern[14] = { 2, 2, 1, 2, 2, 2, 1, 2, 2, 1 ,2 ,2, 2, 1 };
int i;
int pos = 0;
noteNumber[1] = note;
for (i=2; 16 >= i ; i++)
{
int new_note;
new_note = note + pattern[pos];
if (i == 8)
{
noteNumber[i] = 0;
}
else {
noteNumber[i] = new_note;
note = new_note;
pos++;
}
}
}
void updatingPeriodTable()
{
int i;
for ( i=1; i < 17; i++ )
{
if (i == 8)
{
period[i] = 0;
}
else {
uint16_t num = SystemClockSpeed / ( frequency[i] );
period[i] = num;
}
}
}
void updatingFrequencyTable()
{
float updatedFrequency;
int i;
for( i=1; 16 >= i; i++)
{
if( i == 8)
{
frequency[i] = 0;
} else {
updatedFrequency = gettingSmartFrequency(noteNumber[i]);
frequency[i] = updatedFrequency;
}
}
}
float gettingSmartFrequency(int note)
{
static int lastNote = 21;
static float last_frequency = 27.5;
int dif = note_lastNote;
float newFrequency = lastFrequency;
int i;
if (dif> 0)
{
for(i=0; dif > i; i++)
{
newFrequency = newFrequency * 1.059;
}
lastNote = note;
lastFrequency = newFrequency;
}
if (diff < 0)
{
dif = -1 * dif;
for(i=0; dif > i; i++)
{
newfreq = newfrequency / 1.059;
}
last_noteote = note;
lastFrequency = newFrequency;
}
return newfreq;
}
Explanation / Answer
void upateTables(int note)
{
updatingNoteTable(note);
updatingFrequencyTable();
updatingPeriodTable();
}
void updateNoteTable(int note)
{
int pattern[14] = { 2, 2, 1, 2, 2, 2, 1, 2, 2, 1 ,2 ,2, 2, 1 };
int i;
int pos = 0;
noteNumber[1] = note;
for (i=2; 16 >= i ; i++)
{
int new_note;
new_note = note + pattern[pos];
if (i == 8)
{
noteNumber[i] = 0;
}
else {
noteNumber[i] = new_note;
note = new_note;
pos++;
}
}
}
void updatingPeriodTable()
{
int i;
for ( i=1; i < 17; i++ )
{
if (i == 8)
{
period[i] = 0;
}
else {
uint16_t num = SystemClockSpeed / ( frequency[i] );
period[i] = num;
}
}
}
void updatingFrequencyTable()
{
float updatedFrequency;
int i;
for( i=1; i<17; i++)
{
if( i == 8)
{
frequency[i] = 0;
} else {
updatedFrequency = gettingSmartFrequency(noteNumber[i]);
frequency[i] = updatedFrequency;
}
}
}
float gettingSmartFrequency(int note)
{
static int lastNote = 21;
static float last_frequency = 27.5;
int dif = note_lastNote;
float newFrequency = lastFrequency;
int i;
if (dif> 0)
{
for(i=0; i < dif; i++)
{
newFrequency = newFrequency * 1.059;
}
lastNote = note;
lastFrequency = newFrequency;
}
if (diff < 0)
{
dif = -1 * dif;
for(i=0; i < dif; i++)
{
newfreq = newfrequency / 1.059;
}
last_noteote = note;
lastFrequency = newFrequency;
}
return n
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.