C 从文件中读入方程
C Reading from file into an equation
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 个数字,将它们添加到等式的 'note' 部分以将它们转换为音高,然后将其发送到播放 16 个音符的 serveOscillator设定的间距。 Aserve sleep 指示每个音符播放多长时间(500 毫秒),但第 16 个音符不会停止响起,我需要它在 500 毫秒后停止!
而不是测试 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
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 个数字,将它们添加到等式的 'note' 部分以将它们转换为音高,然后将其发送到播放 16 个音符的 serveOscillator设定的间距。 Aserve sleep 指示每个音符播放多长时间(500 毫秒),但第 16 个音符不会停止响起,我需要它在 500 毫秒后停止!
而不是测试 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