else if(choice == 'p')
{
textFilePointer = fopen("/Users/jonnymaguire/Documents/Uni Work/Audio Programming /iap/iapProj/Builds/MacOSX/build/Debug/textp15.txt", "r");
if(textFilePointer == NULL)
{
printf("!Error Opening File!");
}
while(!feof(textFilePointer))
{
float frequency;
fscanf(textFilePointer, " %d\n", ¬e);
printf(" %d\n\n", note);
frequency = 440 * pow(2, (note-69) /12.0);
aserveOscillator(0, frequency, 1, 0);
aserveSleep(500);
}
我程序的这一部分从txt文件中读取16个数字,将它们添加到等式的“音符”部分,将它们转换为音高,然后将其发送到serveOscillator,它以设定音高播放16个音符。 Aserve睡眠决定了每个音符的播放时间(500ms),但是16日不会停止振铃,我需要它在500ms后停止!
答案 0 :(得分:0)
您应该测试文件字段是否已正确读取,而不是测试feof
(请参阅上面的注释)。你用另一个电话关掉了振荡器。
int note;
float frequency;
while(1 == fscanf(textFilePointer, " %d\n", ¬e)) {
printf(" %d\n\n", note);
frequency = 440 * pow(2, (note-69) /12.0);
aserveOscillator(0, frequency, 1, 0);
aserveSleep(500);
}
aserveOscillator(0, 0, 0, 0); // turn off osc