shiyangw Then it shows that: no matching function for call to 'Bela_createAuxiliaryTask'.
this is because the first argument to Bela_createAuxiliaryTask()
should be a function pointer (similar to what you'd pass to pthread_create()
or std::thread()
), whereas what you are doing there is calling the playchirp()
function passing it an argument context
. The following would therefore be the correct syntax:
if((gFillBufferTask2 = Bela_createAuxiliaryTask(playchirp, 90, "playchirp", context)) == 0) {
However, this will not yield the expected result: you are not supposed to cache the BelaContext*
passed to setup()
, render()
or cleanup()
for longer than the lifetime of the function that it was passed to. This is because its content (the pointers to the input/output audio, analog, digital data among other things) will change at every call to each of these functions. Even assuming that the pointers remained constant and that your playchirp()
function would therefore know the correct memory location where to write the output data, you would still have the issue that you would not know WHEN to write to it and you'd be writing at random times which means part of your data may make it to the audio output (replacing whatever was set by render()
) and part would not. While it's OK to have a separate thread for reading from disk, you should not try to write to the audio output from that thread, but you should pass the data to the audio thread where they can be safely and correctly written to disk. See the examples Audio/sample-streamer
and Audio/sample-streamer-multi
for reference.