typedef struct
{
float frequency;
float amplitude;
} OscData;
typedef struct
{
int notenumber;
int velocity;
} NoteData;
OscData noteToOsc (NoteData note);
int main()
{
/*declare integer to store midi note value*/
int note;
int velo;
NoteData notedata[8];
int sequenceposition;
float frequency, x, y;
float amplitude;
OscData oscdata[2];
/*get user to input a midi value*/
printf("press 8 keys on the Axion MIDI keyboard to create a loop\n");
/*recording starts here*/
sequenceposition = 0;
do
{
note = aserveGetNote();
velo = aserveGetVelocity();
if (velo != 0)
{
notedata[sequenceposition].notenumber = note;
notedata[sequenceposition].velocity = velo;
printf("note number = %d\n", notedata[sequenceposition].notenumber);
printf("velocity = %d\n", notedata[sequenceposition].velocity);
sequenceposition++;
}
}
while (sequenceposition < 8);
/*recording ends here*/
while(true)
{
/*playback starts here*/
for(sequenceposition = 0; sequenceposition < 8; sequenceposition++)
{
oscdata[0].frequency = frequency;
oscdata[1].amplitude = amplitude;
oscdata = noteToOsc(notedata[sequenceposition]);
/*display frequency*/
printf("Starting oscillator at %5.2fHz\n", oscdata[0].frequency);
printf("Amplitude = %f\n", oscdata[1].amplitude);
/*start oscillator*/
aserveOscillator(0, oscdata[0].frequency, oscdata[1].amplitude, 0);
aserveSleep(200);
}
}
return 0;
/*end*/
OscData noteToOsc (NoteData note);
{
float frequency, x, y, amplitude;
oscdata[0].frequency = frequency;
oscdata[1].amplitude = amplitude;
/*convert midi value to frequency and velocity to amplitude*/
x = 2;
y = (notedata[sequenceposition].notenumber-69.0)/12.0;
oscdata[0].frequency = 440 * pow(x, y);
amplitude = notedata[sequenceposition].velocity / 127.0;
}
}
这是一个8步音序器的代码,用于扫描midi键盘输入的8个音符。在main中调用的函数应该将音符编号转换为频率和速度到幅度但是有一个错误'数组类型'OscData [2]不可分配'我应该用其他东西代替Oscdata吗? 感谢
答案 0 :(得分:0)
在C
数组不可分配。
你在这里这样做
oscdata = noteToOsc(notedata[sequenceposition]);
oscdata
是一个数组,oscdata[sequenceposition]
是数组的元素,因此您可以为元素赋值
答案 1 :(得分:0)
此:
oscdata[0].frequency = frequency;
oscdata[1].amplitude = amplitude;
oscdata = noteToOsc(notedata[sequenceposition]);
没有任何意义。你不能分配给数组,但你也不想“想要”。它应该是这样的:
oscdata[sequenceposition] = noteToOsc(notedata[sequenceposition]);