Csound Csound-dev Csound-tekno Search About

[Csnd] Terra and Lua calling the Csound API

Date2018-09-30 23:53
FromJohann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE>
Subject[Csnd] Terra and Lua calling the Csound API
Dear all, 

I recently found "Terra " and, after a few tests, i could make some basic
calls to the API :
"Terra is a low-level system programming language that is embedded in and
meta-programmed by the Lua programming language." It uses LLVM and Clang.
It's well sustained - and providing a complete documentation.
The complete description - documentation are here http://terralang.org/ 

With Terra i could finally use the csoundCreateThread API function i was
unsucessful to run with luajit. 
Here two files ".t" (terra extension), both calling the API. The csnd.t just
plays a sine. The csnd_PerfThread.t do the same, with calling the
csoundCreateThread function. Both were running on Windows 10 - using the
last Terra pre compiled binaries - csound 6.10 x64 binaries - and visual
studio 2017 packages for the C standard lib.

I didn't have time to try it with my IUP / LUA user interface to see if the
separate threads are efficient in my case, i'll do the test soon. 
I'll continue to run some tests to see what is possible to do with it. 

Best regards

csnd.t   
csnd_PerfThread.t
  





--
Sent from: http://csound.1045644.n5.nabble.com/Csound-General-f1093014.html

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2018-10-10 22:08
FromJohann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Terra and Lua calling the Csound API
Hi all,

I'm having some issues trying to implement callbacks from Csound outvalue inside my program.

To sum up, there is a main GUI - programmed in Lua with IUP binaries, and Lua triggers some Terra low-level functions to call csound API.
 The csoundPerformKsmps performs well, also with the "Master" control volume slider (using csoundGetChannelPtr in the csound thread).
But, if i activate the callbacks, moving the volume slider make all the app crash. The callbacks i use are an outvalue (triggering for each Csound "beat" a refreshment on a GUI matrix), and two viewmeters refreshing every 256 k-pass (also tried less, it's not really the problem here).

The terra callback function (called with csoundGetOutputChannelCallback) refers to different Lua functions, according to the channel name. Those Lua functions don't do a big job, only refreshing some IUP objects.
So, I tried to lock the UserData with a mutex, it's better than without, but still if i move the slider the app crashes. I also tried to remove only the content of the Terra callback function (replacing with printf("Hello \n"), and it works well, even while moving the slider.

Also, i tried to make run all the callbacks in a different thread, and it doesn't seem better. 
After those tests, i'm not sure what is crashing :
-Refreshing the GUI with callbacks functions might need some "security" ?
-Maybe mutex is not used well ?
-Maybe i would rather need the SpinLocks, but i'm not sure how to use it ?


If anyone wants to check in, the full project is here (currently just for windows) - with explanations.

If anyone has even a small idea, it can be useful !

Thanks in advance

Johann





Le lundi 1 octobre 2018 à 00:53:37 UTC+2, Johann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE> a écrit :


Dear all,

I recently found "Terra " and, after a few tests, i could make some basic
calls to the API :
"Terra is a low-level system programming language that is embedded in and
meta-programmed by the Lua programming language." It uses LLVM and Clang.
It's well sustained - and providing a complete documentation.
The complete description - documentation are here http://terralang.org/

With Terra i could finally use the csoundCreateThread API function i was
unsucessful to run with luajit.
Here two files ".t" (terra extension), both calling the API. The csnd.t just
plays a sine. The csnd_PerfThread.t do the same, with calling the
csoundCreateThread function. Both were running on Windows 10 - using the
last Terra pre compiled binaries - csound 6.10 x64 binaries - and visual
studio 2017 packages for the C standard lib.

I didn't have time to try it with my IUP / LUA user interface to see if the
separate threads are efficient in my case, i'll do the test soon.
I'll continue to run some tests to see what is possible to do with it.

Best regards

csnd_PerfThread.t





--

Csound mailing list
Send bugs reports to
Discussions of bugs and features can be posted here