here's the code: // Helper functions for music
#include <cs50.h>
#include <stdlib.h>
#include<stdio.h>
#include<string.h>
#include "helpers.h"
#include <math.h>
#include<ctype.h>
// Converts a fraction formatted as X/Y to eighths
int duration(string fraction)
{
int numerator;
int denominator;
int duration;
numerator = fraction[0];
denominator = fraction[2];
if(denominator==8)
{
duration = numerator / 1; //the "duration" represents the
number of eighths, each eighth is a musical representation
} //of a period of time.
else if(denominator!=8)
{
duration = 8 / denominator;
}
return 0;
}
// Calculates frequency (in Hz) of a note
int frequency(string note)
{
int octave = 0;
int n = 0;
char noteAndAcc[2];
noteAndAcc[0] = note[0];
if(note[1]=='#' || note[1]=='b')
{
noteAndAcc[1] = note[1];
octave = atoi(¬e[2]);
}
else
{
octave = atoi(¬e[1]);
}
switch(noteAndAcc[0]) //default n values are at octave = 4
{
case 'B':
n = 2;
break;
case 'A':
n = 0;
break;
case 'G':
n = -2;
break;
case 'F':
n = -4;
break;
case 'E':
n = -5;
break;
case 'D':
n = -7;
break;
case 'C':
n = -9;
break;
}
if(noteAndAcc[1]=='#')
{
n = n + 1;
}
if(noteAndAcc[1]=='b')
{
n = n - 1;
}
if(octave == 5)
{
n = n + 12;
}
else if(octave == 6)
{
n = n + 24;
}
else if(octave == 7)
{
n = n + 36;
}
else if(octave == 8)
{
n = n + 48;
}
else if(octave == 3)
{
n = n - 12;
}
else if(octave == 2)
{
n = n - 24;
}
else if(octave == 1)
{
n = n - 36;
}
else if(octave == 0)
{
n = n - 48;
}
else if(octave ==4)
{
n = n + 0;
}
float freqWithDecimals = 0.00;
int frequency = 0;
freqWithDecimals = pow(2, (n/12.0))*440;
frequency = round(freqWithDecimals);
return 0;
}
// Determines whether a string represents a rest
bool is_rest(string s)
{
if(s[0]=='\0')
{
return true;
}
else
{
return false;
}
return 0;
}
and here's what i get in the terminal after compiling both notes and synthesize using "make", and attempting to synthesize jeopardy.wav from jeopardy.txt :
~/workspace/pset3/music/ $ make
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -
O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow -o notes
helpers.c notes.c wav.c -lcrypt -lcs50 -lm
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -
O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow -o
synthesize helpers.c synthesize.c wav.c -lcrypt -lcs50 -lm
~/workspace/pset3/music/ $ ./synthesize jeopardy.wav <
songs/jeopardy.txt
Segmentation fault
~/workspace/pset3/music/ $
As you can see, i'm getting a segmentation fault. Is something wrong with my is_rest function? Looking forward to your help. Thank you.