Exemplo n.º 1
0
void test_string_channel(void)
{
    const char orcS[] = "chn_S \"strchan1\",1\n chn_S \"strchan2\",2\n chn_S \"strchan3\",3\n instr 1\n  endin\n";

    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=NULL");
    csoundCompileOrc(csound, orcS);
    int err = csoundStart(csound);
    CU_ASSERT(err == CSOUND_SUCCESS);

    csoundSetStringChannel(csound, "testing", "ttt");
    int len = csoundGetChannelDatasize(csound, "testing");
    char string[len];
    csoundGetStringChannel(csound, "testing", string);
    CU_ASSERT_STRING_EQUAL(string, "ttt");

    csoundSetStringChannel(csound, "strchan1", "strchan1_val");
    csoundSetStringChannel(csound, "strchan2", "strchan2_val");
    csoundSetStringChannel(csound, "strchan3", "strchan3_val");

    csoundGetStringChannel(csound, "strchan1", string);
    CU_ASSERT_STRING_EQUAL(string, "strchan1_val");

    csoundGetStringChannel(csound, "strchan2", string);
    CU_ASSERT_STRING_EQUAL(string, "strchan2_val");

    csoundGetStringChannel(csound, "strchan3", string);
    CU_ASSERT_STRING_EQUAL(string, "strchan3_val");

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 2
0
void test_control_channel_params(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=NULL");
    //int argc = 2;
    csoundCompileOrc(csound, orc1);
    CU_ASSERT(csoundStart(csound) == CSOUND_SUCCESS);
    controlChannelHints_t hints;
    hints.behav = CSOUND_CONTROL_CHANNEL_INT;
    hints.dflt = 5;
    hints.min = 1;
    hints.max = 10;
    hints.attributes = NULL;
    csoundSetControlChannelHints(csound, "testing", hints);

    controlChannelHints_t hints2;
    csoundGetControlChannelHints(csound, "testing", &hints2);
    CU_ASSERT(hints2.behav == CSOUND_CONTROL_CHANNEL_INT);
    CU_ASSERT(hints2.dflt == 5);
    CU_ASSERT(hints2.min == 1);
    CU_ASSERT(hints2.max == 10);

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 3
0
void test_chn_hints(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=null");
    csoundCompileOrc(csound, orc6);
    (void)csoundStart(csound);
//    err = csoundPerformKsmps(csound); //Need this to load instr 0
    controlChannelHints_t hints;
    hints.attributes = 0;
    CU_ASSERT_EQUAL(0, csoundGetControlChannelHints(csound, "chan", &hints));
    CU_ASSERT_EQUAL(hints.x, 10);
    CU_ASSERT_EQUAL(hints.y, 10);
    CU_ASSERT_EQUAL(hints.width, 50);
    CU_ASSERT_EQUAL(hints.height, 100);
    CU_ASSERT_EQUAL(hints.attributes, 0);
    CU_ASSERT_EQUAL(0, csoundGetControlChannelHints(csound, "chan2", &hints));
    CU_ASSERT_EQUAL(hints.x, 10);
    CU_ASSERT_EQUAL(hints.y, 10);
    CU_ASSERT_EQUAL(hints.width, 50);
    CU_ASSERT_EQUAL(hints.height, 100);
    CU_ASSERT_STRING_EQUAL(hints.attributes, "testattr");

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 4
0
void test_pvs_opcodes(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=null");
    int err = csoundCompileOrc(csound, orc5);
    CU_ASSERT(err == CSOUND_SUCCESS);
    err = csoundStart(csound);
    PVSDATEXT pvs_data, pvs_data2;
    memset(&pvs_data,0,sizeof(PVSDATEXT));
    memset(&pvs_data2,0,sizeof(PVSDATEXT));
    pvs_data.N = 16;
    pvs_data.winsize = 32;
    err = csoundSetPvsChannel(csound, &pvs_data, "1");
    err = csoundGetPvsChannel(csound, &pvs_data2, "1");
    CU_ASSERT_EQUAL(pvs_data.N, pvs_data2.N);
    MYFLT pFields[] = {1.0, 0.0, 1.0};
    err = csoundScoreEvent(csound, 'i', pFields, 3);
    err = csoundPerformKsmps(csound);
    CU_ASSERT_EQUAL(32.0, csoundGetControlChannel(csound, "winsize", NULL));
    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 5
0
int main(int arg, char** argv) {
    random_line *amp, *freq;

    /* initialize random seed: */
    srand (time(NULL));

    csoundInitialize(CSOUNDINIT_NO_ATEXIT);

    CSOUND* csound = csoundCreate(NULL);

    /* Using SetOption() to configure Csound 
    Note: use only one commandline flag at a time */
    csoundSetOption(csound, "-odac");

    /* Compile the Csound Orchestra string */
    csoundCompileOrc(csound, orc);

    /* Read in the Score from loop-generated String */
    csoundReadScore(csound, "i1 0 60");

    /* When compiling from strings, this call is necessary 
    * before doing any performing */
    csoundStart(csound);

    /* Create a random_line for use with Amplitude */
    amp = random_line_create(0.4, 0.2);

    /* Create a random_line for use with Frequency */
    freq = random_line_create(400.0, 80.0);

    
    /* Initialize channel values before running Csound */
    csoundSetControlChannel(csound, "amp", random_line_tick(amp));
    csoundSetControlChannel(csound, "freq", random_line_tick(freq));

    /* The following is our main performance loop. We will perform one 
    * block of sound at a time and continue to do so while it returns 0, 
    * which signifies to keep processing.  
    */
    while (csoundPerformKsmps(csound) == 0) {
        /* Update Channel Values */
        csoundSetControlChannel(csound, "amp", random_line_tick(amp));
        csoundSetControlChannel(csound, "freq", random_line_tick(freq));
    }

    csoundStop(csound);
    return 0;
}
Exemplo n.º 6
0
void test_control_channel(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=null");
    //int argc = 2;
    csoundCompileOrc(csound, orc1);
    CU_ASSERT(csoundStart(csound) == CSOUND_SUCCESS);
    csoundSetControlChannel(csound, "testing", 5.0);
    CU_ASSERT_EQUAL(5.0, csoundGetControlChannel(csound, "testing", NULL));

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 7
0
void test_invalid_channel(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=null");
    csoundCompileOrc(csound, orc5);

    int err;
    CU_ASSERT_EQUAL(0.0, csoundGetControlChannel(csound, "nonexistent_channel", &err));
    CU_ASSERT_EQUAL(err, CSOUND_SUCCESS);

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);

}
Exemplo n.º 8
0
int main(int arg, char** argv) {

    /* initialize random seed: */
    srand (time(NULL));

    csoundInitialize(CSOUNDINIT_NO_ATEXIT);

    CSOUND* csound = csoundCreate(NULL);

    /* Using SetOption() to configure Csound 
    Note: use only one commandline flag at a time */
    csoundSetOption(csound, "-odac");

    /* Compile the Csound Orchestra string */
    csoundCompileOrc(csound, orc);

    /* Read in the Score from pre-written String */
    /*csoundReadScore(csound, (char*)sco);*/

    /* Read in the Score from loop-generated String */
    /*csoundReadScore(csound, generate_example2());*/

    /* Read in the Score from loop-generated String */
    csoundReadScore(csound, generate_example3());

    /* When compiling from strings, this call is necessary 
    * before doing any performing */
    csoundStart(csound);

    /* The following is our main performance loop. We will perform one 
    * block of sound at a time and continue to do so while it returns 0, 
    * which signifies to keep processing.  We will explore this loop 
    * technique in further examples. 
    */

    while (csoundPerformKsmps(csound) == 0) {
      /* pass for now */
    }

    csoundStop(csound);

    return 0;
}
Exemplo n.º 9
0
int main(int arg, char** argv) {
  void* thread;

  csoundInitialize(CSOUNDINIT_NO_ATEXIT);

  CSOUND* csound = csoundCreate(NULL);

  /* Using SetOption() to configure Csound 
  Note: use only one commandline flag at a time */
  csoundSetOption(csound, "-odac");

  /* Compile the Csound Orchestra string */
  csoundCompileOrc(csound, orc);

  /* Compile the Csound SCO String */
  csoundReadScore(csound, (char*)sco);

  /* When compiling from strings, this call is necessary 
   * before doing any performing */
  csoundStart(csound);

  /* Create a new thread that will use our performance function and 
   * pass in our CSOUND structure. This call is asynchronous and 
   * will immediately return back here to continue code execution
   */
  thread = csoundCreateThread(&performance_function, (void*)csound);
 
  /* Join will wait for the other thread to complete. If we did not 
   * call csoundJoinThread(), after csoundCreateThread() returns we 
   * would immediately move to the next line, csoundStop().  That 
   * would stop Csound without really giving it time to run.
   */
  csoundJoinThread(thread);

  csoundStop(csound);

  /* clean up Csound; this is useful if you're going to reuse a Csound 
   * instance 
   */
  csoundCleanup(csound);

  return 0;
}
Exemplo n.º 10
0
void test_channel_list(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=null");
    //int argc = 2;
    csoundCompileOrc(csound, orc2);
    CU_ASSERT(csoundStart(csound) == CSOUND_SUCCESS);
    controlChannelInfo_t *lst;
    int numchnls = csoundListChannels(csound, &lst);
    CU_ASSERT(numchnls == 2);
    CU_ASSERT_STRING_EQUAL(lst->name, "testing");
    CU_ASSERT_EQUAL(lst->type, CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL
                      | CSOUND_OUTPUT_CHANNEL | CSOUND_CONTROL_CHANNEL_INT)
    CU_ASSERT_STRING_EQUAL(lst[1].name, "testing2");

    csoundDeleteChannelList(csound, lst);
    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 11
0
void test_channel_callbacks(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=null");
    csoundCompileOrc(csound, orc3);
    csoundSetInputChannelCallback(csound, (channelCallback_t) inputCallback);
    csoundSetOutputChannelCallback(csound, (channelCallback_t) outputCallback);
    int err = csoundStart(csound);
    CU_ASSERT(err == CSOUND_SUCCESS);
    MYFLT pFields[] = {1.0, 0.0, 1.0};
    err = csoundScoreEvent(csound, 'i', pFields, 3);
    MYFLT pFields2[] = {2.0, 0.0, 1.0};
    err += csoundScoreEvent(csound, 'i', pFields2, 3);
    CU_ASSERT(err == CSOUND_SUCCESS);
    err = csoundPerformKsmps(csound);
    CU_ASSERT(err == CSOUND_SUCCESS);
    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 12
0
void test_channel_opcodes(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    csoundCreateMessageBuffer(csound, 0);
    csoundSetOption(csound, "--logfile=null");
    csoundCompileOrc(csound, orc4);
    csoundSetInputChannelCallback(csound, (channelCallback_t) inputCallback2);
    csoundSetOutputChannelCallback(csound, (channelCallback_t) outputCallback2);
    int err = csoundStart(csound);
    CU_ASSERT(err == CSOUND_SUCCESS);
    csoundGetControlChannel(csound, "1", &err);
    CU_ASSERT(err == CSOUND_SUCCESS)
    csoundSetControlChannel(csound, "1", 5.0);
    MYFLT pFields[] = {1.0, 0.0, 1.0};
    err = csoundScoreEvent(csound, 'i', pFields, 3);
    err = csoundPerformKsmps(csound);
    CU_ASSERT(err == CSOUND_SUCCESS);
    CU_ASSERT_EQUAL(5.0, csoundGetControlChannel(csound, "2", NULL));
    MYFLT pFields2[] = {2.0, 0.0, 1.0};
    err = csoundScoreEvent(csound, 'i', pFields2, 3);
    CU_ASSERT(err == CSOUND_SUCCESS);
    err = csoundPerformKsmps(csound);
    CU_ASSERT(err == CSOUND_SUCCESS);
    CU_ASSERT_EQUAL(6.0, csoundGetControlChannel(csound, "3", NULL));
    MYFLT pFields3[] = {3.0, 0.0, 1.0};
    err = csoundScoreEvent(csound, 'i', pFields3, 3);
    CU_ASSERT(err == CSOUND_SUCCESS);
    err = csoundPerformKsmps(csound);
    CU_ASSERT(err == CSOUND_SUCCESS);
    CU_ASSERT_EQUAL(7.0, csoundGetControlChannel(csound, "4", NULL));

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Exemplo n.º 13
0
int main (int argc, char *argv[])
{
    // Program banner
    printf(
            "----------------------------------\n"
            "---  Vocli Speech Synthesizer  ---\n"
            "----------------------------------\n"
            "- Version: %s%*c\n"
            "- Email: [email protected]   -\n"
            "----------------------------------\n\n",
            VOCLI_VERSION,
            abs(23 - strlen(VOCLI_VERSION)), '-');

    // Initialize resources
    printf("Initializing CMU dictionary...\n");
    CMUDict dictionary;
    cmu_init(CMU_PATH, &dictionary);

    printf("Creating Csound instance...\n");
    CSOUND *csound = csoundCreate(NULL);
    csoundSetOption(csound, "-odac");    // Real time output
    if (csound == NULL)
    {
        cmu_destroy(&dictionary);
        return error(FAIL, "Unable to create Csound");
    }

    printf("Initializing Vocli orchestra...\n");
    int res = orc_init(csound, ORC_PATH);
    if (res != SUCCESS)
    {
        csoundDestroy(csound);
        cmu_destroy(&dictionary);
        return error(FAIL, "FATAL: Unable to initialize Vocli orchestra\n");
    }

    // Special character whitelist
    char ok[] = "'_-";
    size_t oklen = strlen(ok);

    // Input loop
    bool running = true;
    char input[512];
    printf("\nType '!help' for a list of commands.\n\n");
    while (running)
    {
        // Prompt string
        printf("Enter some text> ");

        // Read text from input
        fgets(input, 512, stdin);
        strchomp(input);

        // Handle commands
        if (input[0] == '!')
        {
            if (strncmp(&input[1], "quit", strlen("quit")) == 0)
            {
                putchar('\n');
                running = false;
            }
            else
                for (int i = 0; i < num_cmds; i++)
                {
                    const char *name = Commands[i].name;
                    if (strncmp(&input[1], name, strlen(name)) == 0)
                        Commands[i].callback(&input[1]);
                }

            // Skip further input processing
            continue; 
        }

        // Reformat string to match the dictionary
        for (int i = 0, len = strlen(input); i < len; i++)
        {
            if (isalnum(input[i]))
                input[i] = toupper(input[i]);
            else
                for (int j = 0; j < oklen; j++)
                    if (input[i] == ok[j])
                        break;
                    else if (j == oklen - 1)
                        input[i] = ' ';
        }

        // Look up and print each word
        int i;
        char *word = strtok(input, " ");
        for (i = 0; word != NULL; i++)
        {
            CMUDef *def = cmu_find_word(word, &dictionary);
            if (def != NULL)
            {
                for (int j = 0; j < def->num_phonemes; j++)
                {
                    // Pass score event
                    char start = i ? '0' : '+';

                    const ARPAsym *sym = &ARPAbet[def->phonIDs[j]];
                    printf("%s", sym->name);

                    // Vowel stress
                    if (sym->type == PHON_MONO || sym->type == PHON_DIPTHO)
                        putchar(def->stress[j] + '0');

                    putchar(' ');
                }
            }

            // Separate each word
            if ((word = strtok(NULL, " ")) != NULL)
                printf(" - ");
        }

        putchar('\n');
    }

    // Clean up
    csoundDestroy(csound);       // Destroy Csound
    cmu_destroy(&dictionary);    // Destroy CMU dictionary

    return SUCCESS;
}