简体   繁体   English

8步音序器功能

[英]Function in 8 step sequencer

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;

}

}

This is code for an 8 step sequencer that scans for the input of 8 notes from a midi keyboard. 这是一个8步音序器的代码,它扫描来自Midi键盘的8个音符的输入。 The function called in main is supposed to do the conversion of note number to frequency and velocity to amplitude but there is an error 'Array type 'OscData[2] is not assignable' Am I supposed to be putting something else in place of Oscdata? main中调用的函数应该将音符编号转换为频率,将速度转换为幅度,但是会出现错误“数组类型'OscData [2]无法分配”我是否应该在Oscdata上放置其他内容? Thanks 谢谢

In C 在C中

Arrays are not assignable . 数组不可分配。

You are doing this here 你在这里做

oscdata = noteToOsc(notedata[sequenceposition]);

oscdata is an array and oscdata[sequenceposition] is an element of the array so you can assign value to an element oscdata是一个数组,而oscdata[sequenceposition]是该数组的一个元素,因此您可以将值分配给一个元素

This: 这个:

oscdata[0].frequency = frequency;
oscdata[1].amplitude = amplitude;

oscdata = noteToOsc(notedata[sequenceposition]);

doesn't make any sense. 没有任何意义。 You can't assign to arrays, but you don't "want" to either. 您不能分配给数组,但是您也不希望“分配”给任何一个。 It should just be something like: 它应该像这样:

oscdata[sequenceposition] = noteToOsc(notedata[sequenceposition]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM