<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Julia has a C-API so you can embed Julia the julia interpreter/compiler/runtime into other applications by linking against libjulia.so. It would be pretty doable to write a PD external that took a julia module as an argument and called an agreed-to method (like "process")<br></div>
<div> </div>
<div>So you could define a julia module<br></div>
<div> </div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">module CoolNoise</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">    function process{T <: Real}(out::Vector{Vector{T}}, in::Vector{Vector{T}}</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">        for outvec in out</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">            for i in 1:length(outvec)</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">                outvec[i] = rand() * 2 - 1</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">            end</span><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"><br></span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">        end</span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">    end</span></div>
<div><span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">end</span><br></div>
<div> </div>
<div>and maybe the object would be called <span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;">[jl~]</span> so you could instantiate<span class="font" style="font-family: menlo, consolas, "courier new", monospace, sans-serif;"> [jl~ CoolNoise]</span> and it would use your julia code to process blocks of audio.<br></div>
<div> </div>
<div>I haven't thought much about whether this is the <i>best</i> way to do it, but it would work. You'd need some other stuff in there to report back the number and type of inlets/outlets, and probably some other stuff.<br></div>
<div> </div>
<div>There are a few gotchas to writing latency-sensitive code in Julia, particularly because it's garbage-collected so you want to be careful not to write code that ends up doing a lot of heap allocation, but there's been some work on the GC to speed it up, and in particular an incremental GC that will yield control if the GC exceeds a time limit. I've talked a bit to the guy working on it and while the current version doesn't include his incremental code I think that with a little encouragement (maybe a bottle of nice whiskey) he could be persuaded to make it a reality. Aside from GC the other issue is that that JIT compiler is a double-edged sword. Once things are compiled they're really fast, but the process of compiling happens the first time a method is called, so you need to make<br></div>
<div>sure that any audio methods you define get compiled before the main audio loop starts up. Julia is also not thread-safe yet, though there are folks working on it, so calling into julia code from multiple threads is a recipe for segfaults.</div>
<div> </div>
<div>I wrote and maintain the <a href="https://github.com/ssfrr/audioio.jl">AudioIO.jl</a> package which is an interactive signal processing framework for Julia so I've spent some time thinking about some of this. The project has lagged a bit while I've been finishing up my (unrelated) masters thesis but this fall I'm going to be digging much more deeply into it. I've actually considered implementing the PD C API so I can pull PD externals into Julia,  basically the inverse of this.<br></div>
<div> </div>
<div>-s</div>
<div> </div>
<div> </div>
<div>On Mon, Aug 17, 2015, at 02:38 PM, Forrest Curo wrote:<br></div>
<blockquote type="cite"><div dir="ltr">Any chances of adding Julia to the available languages for writing pd extensions? It seems to combine much of the writability of python with the specificity & machine-concreteness of C...<br></div>
<div><u>_______________________________________________</u><br></div>
<div><a href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br></div>
<div>UNSUBSCRIBE and account-management -> <a href="http://lists.puredata.info/listinfo/pd-list">http://lists.puredata.info/listinfo/pd-list</a><br></div>
</blockquote><div> </div>
</body>
</html>