Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua_FFI Example Issue #1

Open
AstralTraveller opened this issue Apr 27, 2020 · 0 comments
Open

lua_FFI Example Issue #1

AstralTraveller opened this issue Apr 27, 2020 · 0 comments

Comments

@AstralTraveller
Copy link

Hi people,
I have a problem running the lua_FFI Example. I am running OS X Catalina and I am using the code provided here. In order to get past the error message that luajit couldn't find the csound64 library I add libcsnd6.6.0.dylib to "local csoundApi = ffi.load('libcsnd6.6.0.dylib').

After this step the example completes fine, but without any sound coming form Csound.
The score gets compiled and everything but Csound doesn't output sound, it seems to shutdown after like 1 second.

attached is the output of the console after I run following command.

I don't know what I am doing wrong.

Best,

luajit Untitled-1.lua
U S I N G   C S O U N D   6   V I A   L U A   F F I
Copyright (C) 2013 by Michael Gogins.
This software is licensed under the terms of the
GNU Lesser General Public License.
This script requires either LuaJIT from luajit.org, or regular Lua with the
luaffi module. The script demonstrates how to generate a Csound score in Lua,
and then realize the score using Csound 6 via the Csound API accessed through
the  foreign function interface (FFI).
The code prints comments to explain every step.

Local variables should be used whenever possible with LuaJIT.
Importing the foreign function interface namespace...
Declaring the Csound API functions we need to LuaJIT's FFI...
MYFLT must be replaced with its actual type.
CSOUND * would be tough to do and is replaced by void *.
Loading the Csound shared library...
Csound version:  6.14
Csound API version:  4.00
Calling csoundInitialize...
Creating an instance of Csound...
0dBFS level = 32768.0
--Csound version 6.14 (double samples) Jan 26 2020
[commit: 0ce67f7c105ed2aee98d0e7f43558d62357c769b]
libsndfile-1.0.28
Configuring Csound for performance (change output filename as required)...
Compiling the Csound orchestra (note multi-line text in double brackets)...
Defining a difference equation for the logistic map...
Iterating a loop to generate score events and send them to Csound...
i 1    0.6250    0.5000   92.0000   80.0000
i 1    0.7500    0.5000   49.0000   80.0000
i 1    0.8750    0.5000   74.0000   80.0000
i 1    1.0000    0.5000   88.0000   80.0000
i 1    1.1250    0.5000   61.0000   80.0000
i 1    1.2500    0.5000   91.0000   80.0000
i 1    1.3750    0.5000   52.0000   80.0000
i 1    1.5000    0.5000   80.0000   80.0000
i 1    1.6250    0.5000   78.0000   80.0000
i 1    1.7500    0.5000   82.0000   80.0000
i 1    1.8750    0.5000   75.0000   80.0000
i 1    2.0000    0.5000   86.0000   80.0000
i 1    2.1250    0.5000   64.0000   80.0000
i 1    2.2500    0.5000   92.0000   80.0000
i 1    2.3750    0.5000   49.0000   80.0000
i 1    2.5000    0.5000   74.0000   80.0000
i 1    2.6250    0.5000   87.0000   80.0000
i 1    2.7500    0.5000   63.0000   80.0000
i 1    2.8750    0.5000   91.0000   80.0000
i 1    3.0000    0.5000   50.0000   80.0000
i 1    3.1250    0.5000   76.0000   80.0000
i 1    3.2500    0.5000   84.0000   80.0000
i 1    3.3750    0.5000   70.0000   80.0000
i 1    3.5000    0.5000   91.0000   80.0000
i 1    3.6250    0.5000   52.0000   80.0000
i 1    3.7500    0.5000   81.0000   80.0000
i 1    3.8750    0.5000   77.0000   80.0000
i 1    4.0000    0.5000   83.0000   80.0000
i 1    4.1250    0.5000   72.0000   80.0000
i 1    4.2500    0.5000   89.0000   80.0000
i 1    4.3750    0.5000   56.0000   80.0000
i 1    4.5000    0.5000   86.0000   80.0000
i 1    4.6250    0.5000   65.0000   80.0000
i 1    4.7500    0.5000   92.0000   80.0000
i 1    4.8750    0.5000   49.0000   80.0000
i 1    5.0000    0.5000   74.0000   80.0000
i 1    5.1250    0.5000   87.0000   80.0000
i 1    5.2500    0.5000   62.0000   80.0000
i 1    5.3750    0.5000   91.0000   80.0000
i 1    5.5000    0.5000   51.0000   80.0000
i 1    5.6250    0.5000   79.0000   80.0000
i 1    5.7500    0.5000   80.0000   80.0000
i 1    5.8750    0.5000   79.0000   80.0000
i 1    6.0000    0.5000   81.0000   80.0000
i 1    6.1250    0.5000   77.0000   80.0000
i 1    6.2500    0.5000   83.0000   80.0000
i 1    6.3750    0.5000   72.0000   80.0000
i 1    6.5000    0.5000   89.0000   80.0000
i 1    6.6250    0.5000   58.0000   80.0000
i 1    6.7500    0.5000   88.0000   80.0000
i 1    6.8750    0.5000   60.0000   80.0000
i 1    7.0000    0.5000   90.0000   80.0000
i 1    7.1250    0.5000   56.0000   80.0000
i 1    7.2500    0.5000   86.0000   80.0000
i 1    7.3750    0.5000   66.0000   80.0000
i 1    7.5000    0.5000   92.0000   80.0000
i 1    7.6250    0.5000   49.0000   80.0000
i 1    7.7500    0.5000   74.0000   80.0000
i 1    7.8750    0.5000   87.0000   80.0000
i 1    8.0000    0.5000   62.0000   80.0000
i 1    8.1250    0.5000   91.0000   80.0000
i 1    8.2500    0.5000   51.0000   80.0000
i 1    8.3750    0.5000   78.0000   80.0000
i 1    8.5000    0.5000   82.0000   80.0000
i 1    8.6250    0.5000   74.0000   80.0000
i 1    8.7500    0.5000   87.0000   80.0000
i 1    8.8750    0.5000   62.0000   80.0000
i 1    9.0000    0.5000   91.0000   80.0000
i 1    9.1250    0.5000   51.0000   80.0000
i 1    9.2500    0.5000   79.0000   80.0000
i 1    9.3750    0.5000   80.0000   80.0000
i 1    9.5000    0.5000   79.0000   80.0000
i 1    9.6250    0.5000   80.0000   80.0000
i 1    9.7500    0.5000   79.0000   80.0000
i 1    9.8750    0.5000   80.0000   80.0000
i 1   10.0000    0.5000   78.0000   80.0000
i 1   10.1250    0.5000   82.0000   80.0000
i 1   10.2500    0.5000   75.0000   80.0000
i 1   10.3750    0.5000   86.0000   80.0000
i 1   10.5000    0.5000   65.0000   80.0000
i 1   10.6250    0.5000   92.0000   80.0000
i 1   10.7500    0.5000   49.0000   80.0000
i 1   10.8750    0.5000   74.0000   80.0000
i 1   11.0000    0.5000   87.0000   80.0000
i 1   11.1250    0.5000   62.0000   80.0000
i 1   11.2500    0.5000   91.0000   80.0000
i 1   11.3750    0.5000   52.0000   80.0000
i 1   11.5000    0.5000   80.0000   80.0000
i 1   11.6250    0.5000   79.0000   80.0000
i 1   11.7500    0.5000   80.0000   80.0000
i 1   11.8750    0.5000   79.0000   80.0000
i 1   12.0000    0.5000   81.0000   80.0000
i 1   12.1250    0.5000   76.0000   80.0000
i 1   12.2500    0.5000   84.0000   80.0000
i 1   12.3750    0.5000   70.0000   80.0000
i 1   12.5000    0.5000   91.0000   80.0000
i 1   12.6250    0.5000   52.0000   80.0000
i 1   12.7500    0.5000   81.0000   80.0000
i 1   12.8750    0.5000   78.0000   80.0000
i 1   13.0000    0.5000   83.0000   80.0000
i 1   13.1250    0.5000   73.0000   80.0000
i 1   13.2500    0.5000   88.0000   80.0000
i 1   13.3750    0.5000   60.0000   80.0000
i 1   13.5000    0.5000   90.0000   80.0000
i 1   13.6250    0.5000   55.0000   80.0000
i 1   13.7500    0.5000   84.0000   80.0000
i 1   13.8750    0.5000   69.0000   80.0000
i 1   14.0000    0.5000   91.0000   80.0000
i 1   14.1250    0.5000   52.0000   80.0000
i 1   14.2500    0.5000   80.0000   80.0000
i 1   14.3750    0.5000   79.0000   80.0000
i 1   14.5000    0.5000   80.0000   80.0000
i 1   14.6250    0.5000   78.0000   80.0000
i 1   14.7500    0.5000   82.0000   80.0000
i 1   14.8750    0.5000   74.0000   80.0000
i 1   15.0000    0.5000   87.0000   80.0000
i 1   15.1250    0.5000   62.0000   80.0000
i 1   15.2500    0.5000   91.0000   80.0000
i 1   15.3750    0.5000   51.0000   80.0000
i 1   15.5000    0.5000   79.0000   80.0000
i 1   15.6250    0.5000   81.0000   80.0000
i 1   15.7500    0.5000   77.0000   80.0000
i 1   15.8750    0.5000   84.0000   80.0000
i 1   16.0000    0.5000   70.0000   80.0000
i 1   16.1250    0.5000   91.0000   80.0000
i 1   16.2500    0.5000   53.0000   80.0000
i 1   16.3750    0.5000   81.0000   80.0000
i 1   16.5000    0.5000   76.0000   80.0000
i 1   16.6250    0.5000   85.0000   80.0000
i 1   16.7500    0.5000   69.0000   80.0000
i 1   16.8750    0.5000   91.0000   80.0000
i 1   17.0000    0.5000   51.0000   80.0000
i 1   17.1250    0.5000   79.0000   80.0000
i 1   17.2500    0.5000   80.0000   80.0000
i 1   17.3750    0.5000   78.0000   80.0000
i 1   17.5000    0.5000   82.0000   80.0000
i 1   17.6250    0.5000   75.0000   80.0000
i 1   17.7500    0.5000   86.0000   80.0000
i 1   17.8750    0.5000   65.0000   80.0000
i 1   18.0000    0.5000   92.0000   80.0000
i 1   18.1250    0.5000   49.0000   80.0000
i 1   18.2500    0.5000   74.0000   80.0000
i 1   18.3750    0.5000   88.0000   80.0000
i 1   18.5000    0.5000   62.0000   80.0000
i 1   18.6250    0.5000   91.0000   80.0000
i 1   18.7500    0.5000   52.0000   80.0000
i 1   18.8750    0.5000   80.0000   80.0000
i 1   19.0000    0.5000   79.0000   80.0000
i 1   19.1250    0.5000   81.0000   80.0000
i 1   19.2500    0.5000   77.0000   80.0000
i 1   19.3750    0.5000   83.0000   80.0000
i 1   19.5000    0.5000   72.0000   80.0000
i 1   19.6250    0.5000   89.0000   80.0000
i 1   19.7500    0.5000   56.0000   80.0000
i 1   19.8750    0.5000   86.0000   80.0000
i 1   20.0000    0.5000   65.0000   80.0000
i 1   20.1250    0.5000   92.0000   80.0000
i 1   20.2500    0.5000   49.0000   80.0000
i 1   20.3750    0.5000   74.0000   80.0000
i 1   20.5000    0.5000   87.0000   80.0000
i 1   20.6250    0.5000   62.0000   80.0000
i 1   20.7500    0.5000   91.0000   80.0000
i 1   20.8750    0.5000   51.0000   80.0000
i 1   21.0000    0.5000   79.0000   80.0000
i 1   21.1250    0.5000   80.0000   80.0000
i 1   21.2500    0.5000   78.0000   80.0000
i 1   21.3750    0.5000   82.0000   80.0000
i 1   21.5000    0.5000   74.0000   80.0000
i 1   21.6250    0.5000   87.0000   80.0000
i 1   21.7500    0.5000   62.0000   80.0000
i 1   21.8750    0.5000   91.0000   80.0000
i 1   22.0000    0.5000   51.0000   80.0000
i 1   22.1250    0.5000   79.0000   80.0000
i 1   22.2500    0.5000   81.0000   80.0000
i 1   22.3750    0.5000   77.0000   80.0000
i 1   22.5000    0.5000   84.0000   80.0000
i 1   22.6250    0.5000   71.0000   80.0000
i 1   22.7500    0.5000   90.0000   80.0000
i 1   22.8750    0.5000   54.0000   80.0000
i 1   23.0000    0.5000   83.0000   80.0000
i 1   23.1250    0.5000   72.0000   80.0000
i 1   23.2500    0.5000   89.0000   80.0000
i 1   23.3750    0.5000   56.0000   80.0000
i 1   23.5000    0.5000   86.0000   80.0000
i 1   23.6250    0.5000   65.0000   80.0000
i 1   23.7500    0.5000   92.0000   80.0000
i 1   23.8750    0.5000   49.0000   80.0000
i 1   24.0000    0.5000   74.0000   80.0000
i 1   24.1250    0.5000   87.0000   80.0000
i 1   24.2500    0.5000   62.0000   80.0000
i 1   24.3750    0.5000   91.0000   80.0000
i 1   24.5000    0.5000   52.0000   80.0000
i 1   24.6250    0.5000   80.0000   80.0000
i 1   24.7500    0.5000   79.0000   80.0000
i 1   24.8750    0.5000   80.0000   80.0000
i 1   25.0000    0.5000   79.0000   80.0000
i 1   25.1250    0.5000   81.0000   80.0000
i 1   25.2500    0.5000   77.0000   80.0000
i 1   25.3750    0.5000   84.0000   80.0000
i 1   25.5000    0.5000   71.0000   80.0000
Having sent the entire score, starting the Csound performance...
rtaudio: PortAudio module enabled ...
using callback interface
rtmidi: PortMIDI module enabled
displays suppressed
0dBFS level = 32768.0
orch now loaded
audio buffered in 1024 sample-frame blocks
PortAudio V19-devel (built Feb 12 2010 09:42:54)
   0: dac0 (C32JG5x [Core Audio])
   1: dac1 (Built-in Output [Core Audio])
   2: dac2 (Built-in Digital [Core Audio])
   3: dac3 (Scarlett 2i2 USB [Core Audio])
   4: dac4 (Soundflower (2ch) [Core Audio])
   5: dac5 (Soundflower (64ch) [Core Audio])
PortAudio: selected output device 'Built-in Output'
writing 2048 sample blks of 64-bit floats to dac
SECTION 1:
Print iterating the performance loop until it returns "completed"...
This enables the Lua code to send data to Csound during performance
via control channels. And Csound could also send data back to Lua this way.
Score finished in csoundPerformKsmps() with 2.
Resetting Csound to clean up after performance...
resetting Csound instance
inactive allocs returned to freespace
end of score.		   overall amps:      0.0      0.0
0 errors in performance
Elapsed time at end of performance: real: 0.052s, CPU: 0.029s
c

losing device
0 2048 sample blks of 64-bit floats written to dac
0dBFS level = 32768.0
--Csound version 6.14 (double samples) Jan 26 2020
[commit: 0ce67f7c105ed2aee98d0e7f43558d62357c769b]
libsndfile-1.0.28
end of score.		   overall amps:      0.0
	   overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.256s, CPU: 0.001s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant