CsoundObject *CsoundObject_new(char *csdPath, size_t analysisSegmentFramesCount)
{
    CsoundObject *self = calloc(1, sizeof(CsoundObject));
    self->analysisSegmentFramesCount = analysisSegmentFramesCount;
    self->csound = csoundCreate(NULL);
    self->frameTimes = calloc(analysisSegmentFramesCount, sizeof(Float32));
    
    for (size_t i = 0; i < analysisSegmentFramesCount; ++i) {
        
        self->frameTimes[i] = ((1. / 44100) * 256) * i;
    }
    
    csoundPreCompile(self->csound);
    csoundSetHostImplementedAudioIO(self->csound, 1, 0);
    csoundSetHostData(self->csound, self);
    self->channelsCount = 2;
    char *parserFlag = "--new-parser";
    char *argv[3] = {
        "csound",
        parserFlag,
        csdPath
    };
    
    self->csoundResult = csoundCompile(self->csound, 3, argv);
    
    if (self->csoundResult == 0) {
        printf("success\n");
    }
    
    return self;
}
예제 #2
0
void CsoundObj_compileCSD(CsoundObj *self,
                          char *filePath,
                          uint32_t samplerate)
{
    char samplerateArgument[20] = {0};
    char controlrateArgument[20] = {0};
    char bufferSizeArgument[20] = {0};
    double controlRate = (double)samplerate/(double)self->frameCount;
    sprintf((char *)&samplerateArgument, "-r %d", samplerate);
    sprintf((char *)&controlrateArgument, "-k %f", controlRate);
    sprintf((char *)&bufferSizeArgument, "-b %d", 256);

    char *argv[5] = {
        "csound",
        samplerateArgument,
        controlrateArgument,
        bufferSizeArgument,
        filePath
    };

    int result = csoundCompile(self->csound, 5, argv);

    if (result != 0) {

        printf("compilation failed\n");
    }
}
예제 #3
0
    TamTamSound(log_t * ll, char * orc, int framerate )
        : ThreadID(NULL), PERF_STATUS(STOP), csound(NULL),
        music(),
        ticks_per_period(0.0),
        tick_adjustment(0.0), 
        tick_total(0.0),
        csound_frame_rate(framerate),           //must agree with the orchestra file
        ll( ll )
    {
        csound = csoundCreate(NULL);
        int argc=4;
        const char  **argv = (const char**)malloc(argc*sizeof(char*));
        argv[0] = "csound";
        argv[1] = "-m0";
        argv[2] = "-+rtaudio=alsa";
        argv[3] = orc;

        ll->printf(1,  "loading csound orchestra file %s\n", orc);
        //csoundInitialize(&argc, &argv, 0);
        csoundPreCompile(csound);
        int result = csoundCompile(csound, argc, (char**)argv);
        if (result)
        {
            csound = NULL;
            ll->printf( "ERROR: csoundCompile of orchestra %s failed with code %i\n", orc, result);
        }
        free(argv);
        csound_period_size = csoundGetOutputBufferSize(csound);
        csound_period_size /= 2; /* channels */
        setTickDuration(0.05);
    }
예제 #4
0
void test_line_breakpoint_orc_file(void)
{
    FILE *f = fopen("debug.orc", "w");
    CU_ASSERT_PTR_NOT_NULL(f);

    const char *orc = "\n"
                      "instr 1\n"
                      "Svar init \"hello\"\n"
                      "ksig line 0, p3, 1\n"
                      "ksig2 line 1, p3, 0\n"
                      "asig3 oscils 0.5, 440, 0.5\n"
                      "endin\n";
    fprintf(f, "%s", orc);
    fclose(f);
    f = fopen("debug.sco", "w");
    CU_ASSERT_PTR_NOT_NULL(f);

    const char *sco = "i 1 0 1\n";
    fprintf(f, "%s", sco);
    fclose(f);
    count = 0;
    CSOUND* csound = csoundCreate(NULL);

    csoundCreateMessageBuffer(csound, 0);
    const char* argv[] = {"csound", "debug.orc", "debug.sco"};
    csoundCompile(csound, 3, (char **) argv);

    csoundDebuggerInit(csound);
    int line = 5;
    csoundSetBreakpointCallback(csound, brkpt_cb7, &line);
    csoundSetBreakpoint(csound, line, 0, 0);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
    csoundRemoveBreakpoint(csound, line, 0);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);

    line = 6;
    csoundSetBreakpoint(csound, line, 0, 0);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
//    csoundPerformKsmps(csound);

    csoundDebuggerClean(csound);
    CU_ASSERT_EQUAL(count, 2);
    csoundDestroy(csound);
}
예제 #5
0
파일: pvsbus.c 프로젝트: BlakeJarvis/csound
int main(int argc, char **argv)
{
    CSOUND  *csound;
    char    *fname = NULL;
    int     k, result;
    PVSDATEXT dataout, datain;

    /* initialise PVSATEXT data */
    datain.N = 1024;
    datain.format = 0;
    datain.overlap = 256;
    datain.winsize = 1024;
    datain.frame = (float *) calloc(sizeof(float),(datain.N+2));

    dataout.N = 1024;
    dataout.format = 0;
    dataout.overlap = 256;
    dataout.winsize = 1024;
    dataout.frame = (float *) calloc(sizeof(float),(dataout.N+2));

    /*  Create Csound. */
    csound = csoundCreate(NULL);

    /*  One complete performance cycle. */
    result = csoundCompile(csound, argc, argv);
    while (!result){

      /* copy data from pvs out to pvs in bus */
      for(k=0; k < 1026; k++)
          datain.frame[k] = dataout.frame[k];
      datain.framecount = dataout.framecount;
      /* send in the pvs in bus data */
      csoundSetPvsChannel(csound, &datain, "0");
      /* one ksmps pass */
      result = csoundPerformKsmps(csound);
      /* receive the pvs out bus data */
      csoundGetPvsChannel(csound, &dataout, "0");
    }
    /* delete Csound instance */
    csoundDestroy(csound);
    free(datain.frame);
    free(dataout.frame);
    return (result >= 0 ? 0 : result);
}
예제 #6
0
파일: main.c 프로젝트: BlakeJarvis/csound
PUBLIC int csoundCompileCsd(CSOUND *csound, char *str) {

  if((csound->engineStatus & CS_STATE_COMP) == 0) {
    char *argv[2] = { "csound", (char *) str };
    int argc = 2;
    return csoundCompile(csound, argc, argv);
  }
  else {
    int res = read_unified_file2(csound, (char *) str);
   if(res) {
    res = csoundCompileOrc(csound, NULL);
    if(res == CSOUND_SUCCESS){
      csoundLockMutex(csound->API_lock);
      char *sc = scsortstr(csound, csound->scorestr);
      csoundInputMessageInternal(csound, (const char *) sc);
      free(sc);
      csoundUnlockMutex(csound->API_lock);
      return CSOUND_SUCCESS;
    }
   }
   return res;
  }
}
void test_create_buffer(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    int argc = 2;
    char *argv[] = {"csound", "-v"};
    csoundCreateMessageBuffer(csound, 0);
    int result = csoundCompile(csound, argc, argv);

    int cnt = csoundGetMessageCnt(csound);
    CU_ASSERT(cnt > 0);
    const char * msg = csoundGetFirstMessage(csound);
    CU_ASSERT_PTR_NOT_NULL(msg);
    int newcnt = csoundGetMessageCnt(csound);
    CU_ASSERT_EQUAL(cnt, newcnt);
    csoundPopFirstMessage(csound);
    newcnt = csoundGetMessageCnt(csound);
    CU_ASSERT_EQUAL(cnt - 1, newcnt);

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
예제 #8
0
void CsoundObj_compileCSD(CsoundObj *self,
		char *filePath,
		uint32_t samplerate,
		double controlrate,
		uint32_t bufferSize)
{ 
	char samplerateArgument[10] = {0};
	char controlrateArgument[10] = {0};
	char bufferSizeArgument[10] = {0};
	sprintf((char *)&samplerateArgument, "-r %d", samplerate);
	sprintf((char *)&controlrateArgument, "-k %f", controlrate);
	sprintf((char *)&bufferSizeArgument, "-b %d", bufferSize);

	char *argv[5] = {
		"csound",
		samplerateArgument,
		controlrateArgument,
		bufferSizeArgument,
		filePath
	};

	printf("File name is %s\n", filePath);

	int result = csoundCompile(self->csound, 5, argv);

	if (result == 0) {

		printf("success\n");
		self->csoundIn = csoundGetSpin(self->csound);
		self->csoundOut = csoundGetSpout(self->csound);
		self->zerodBFS = csoundGet0dBFS(self->csound);
	}
	else {

		printf("compilation failed\n");
	}
}
예제 #9
0
int main(int argc, char **argv)
{
    CSOUND  *csound;
    char    *fname = NULL;
    int     i, result, nomessages=0;
#ifdef GNU_GETTEXT
    const char* lang;
#endif
    install_signal_handler();
    csoundInitialize(CSOUNDINIT_NO_SIGNAL_HANDLER);

    /* set stdout to non buffering if not outputing to console window */
    if (!isatty(fileno(stdout))) {
#if !defined(WIN32)
      setvbuf(stdout, (char*) NULL, _IONBF, 0);
#endif
    }

#ifdef GNU_GETTEXT
    /* We need to set the locale for the translations to work */
    lang = csoundGetEnv(NULL, "CS_LANG");
    /* If set, use that. Otherwise use the system locale */
    if(lang == NULL)
        lang = setlocale(LC_MESSAGES, "");
    else
        lang = setlocale(LC_MESSAGES, lang);
    /* Should we warn if we couldn't set the locale (lang == NULL)? */
    /* If the strings for this binary are ever translated,
     * the textdomain should be set here */
#endif

    /* Real-time scheduling on Linux by Istvan Varga (Jan 6 2002) */
#ifdef LINUX
    if (set_rt_priority(argc, argv) != 0)
      return -1;

#endif
    /* open log file if specified */
    for (i = 1; i < argc; i++) {
      if (strncmp(argv[i], "-O", 2) == 0 && (int) strlen(argv[i]) > 2)
        fname = argv[i] + 2;
      else if (strncmp(argv[i], "--logfile=", 10) == 0 &&
               (int) strlen(argv[i]) > 10)
        fname = argv[i] + 10;
      else if (i < (argc - 1) && strcmp(argv[i], "-O") == 0)
        fname = argv[i + 1];
    }
    if (fname != NULL) {
      if (!strcmp(fname, "NULL") || !strcmp(fname, "null"))
               nomessages = 1;
      else if ((logFile = fopen(fname, "w")) == NULL) {
        fprintf(stderr, "Error opening log file '%s': %s\n",
                        fname, strerror(errno));
        return -1;
      }
    }
    /* if logging to file, set message callback */
    if (logFile != NULL)
      csoundSetDefaultMessageCallback(msg_callback);
    else if (nomessages)
      csoundSetDefaultMessageCallback(nomsg_callback);

    /*  Create Csound. */
    csound = csoundCreate(NULL);
    _csound = csound;

    /*  One complete performance cycle. */
    result = csoundCompile(csound, argc, argv);

     if(!result) csoundPerform(csound);

    /* delete Csound instance */
     csoundDestroy(csound);
     _csound = NULL;
    /* close log file */
    if (logFile != NULL)
      fclose(logFile);

    if(result == 0 && _result != 0) result = _result;
    // printf("csound returned with value: %d \n", result);
#if 0
    /* remove global configuration variables, if there are any */
    csoundDeleteAllGlobalConfigurationVariables();
#endif
    return (result >= 0 ? 0 : result);
}