Cabbage Logo
Back to Cabbage Site

Do I need to use CsoundPerformanceThread...?

Maybe you can paste the code where you create your Csound object? Could be something there perhaps.

CsoundTest::~CsoundTest(){
//free Csound object
delete csound;
}

bool CsoundTest::init() {
    cout << "Init CsoundTest" << endl;
    csound = new Csound();
    cout << csound << endl;
    cout << "version:" << csound->GetVersion() << endl;
    cout << "api version:" << csound->GetAPIVersion() << endl;

//compile instance of csound.
csCompileResult = csound->Compile("/Users/boonier/Downloads/test8.csd");
csound->SetHostImplementedAudioIO(1, 0);

if (csCompileResult == 0) { // compiled OK...
    //access Csound's input/output buffer
    spout = csound->GetSpout();
    spin  = csound->GetSpin();

    //start Csound performance
    csound->Start();
    cout << "Successful CSD compile, starting..." << endl;
    return true;
} else {
    cout << "CSD did not compile:" << csCompileResult << endl;
    return false;
}

}

mm I think that formatted ok. That’s the main setup code, otherwise not much else in the hpp

cheers

Can you paste the .csd file?

sorry yes of course

<CsoundSynthesizer>
<CsOptions>

</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 64
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1
aOutL = oscili:a(scale(oscili:k(1, 0.25, -1, 0), 0.2, 1), 400 * p4 + oscili:k(2, 3))
aOutR = oscili:a(scale(oscili:k(1, 0.25, -1, 0.5), 0.2, 1), 200 * p4 + oscili:k(4, 1.5))
outs aOutL/8, aOutR/8
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
i1 0 z 0.25
i1 0 z 0.5
i1 0 z 0.75
i1 0 z 1
i1 0 z 1.25
i1 0 z 1.5
i1 0 z 1.75
i1 0 z 2
</CsScore>
</CsoundSynthesizer>

Can you try adding -n to your CsOptions?

I think that might have solved it… I ran the plugin for a whole 2 minutes without a hiccup!

-n is --no-sound right? No sound. Do all processing, but bypass writing of sound to disk.
– what exactly would it be writing to disk?

Thank you though, I think that might have done the trick. Now on to my next world of pain…

:slight_smile: Speaking of which, I want to move the csd into the bundle, now it resides in Resources:

image
image

but I just can’t successfully reference it from CsoundTest.cpp; what would be the correct path?

thanks!

If you don’t add -n Csound will try to output sound using it’s own audio drivers. You should be able to pass the .csd file to compile using a relative path, if it’s in the resource folder, you should be able to do ../Resources/CsoundTest.csd, so up one from the binary directory, and then into the Resources folder…

See, that is so obvious - the relative path to the .csd must be one up/into resources - but for some reason I was second guessing myself and thinking it was on the same level as the executable. Goes to show take stack overflow with a pinch of salt sometimes…any way I digress! For some reason the .csd doesn’t compile successfully. Does that mean that it can’t locate it?

It might do, but it’s hard to say. You might want to check the Csound output buffer. There are some classes you can use to access the output from Csound. They are really invaluable at this stage of development.

Yes! output buffer helps a bunch:

CSOUND_MESSAGE:WARNING: 
CSOUND_MESSAGE:could not open library '/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/libstdutil.dylib' (-1)
WARNING: could not open library '/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Resources/Opcodes64/librtjack.dylib' (-1)
CSOUND_MESSAGE:

CSOUND_MESSAGE:UnifiedCSD:  ../Resources/test8.csd

CSOUND_MESSAGE:Reading CSD failed (No such file or directory)... stopping
CSOUND_MESSAGE:

CSD did not compile:-1

so it can’t find it :thinking:

Can you screenshot the folder structure of your bundle?

It could be that the current working directory is not what you think it is when the plugin is loading, or that the host has changed it. In this case the relative path no longer makes sense. You can instead find the path to the executable and you this to form an absolute path to the .csd file. The SDK you are using might have some methods to do this, otherwise take a look at how I do it here. :+1:

huh I read something to that effect also; getting the path to the bundle. Will investigate thanks :+1:

…is what work for me, Mac only though:

// get the local bundle CSD from Resources...
CFBundleRef mainBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.boonier.CsoundTest"));
CFURLRef csdURL = CFBundleCopyResourceURL(mainBundle, CFSTR("test8.csd"), NULL, NULL);
string path = CFStringGetCStringPtr(CFURLGetString(csdURL), kCFStringEncodingMacRoman );
string sub = "file://";
string::size_type i = path.find(sub);
if (i != string::npos)
   path.erase(i, sub.length());

Thanks for sharing this. I might need it myself some day.

No worries, glad I could give something back.

It seems verbose to me, but C++ can be verbose for seemingly simple things. It makes you appreciate what the higher level languages are doing for you under the hood!