gogins / csound-ac

A C++ library for algorithmic composition, designed to be used with Csound, with both C++ and Python interfaces.
GNU Lesser General Public License v2.1
6 stars 0 forks source link

Check out the zig programming language #24

Closed gogins closed 3 months ago

gogins commented 4 months ago

Seems to cross-compile to WASM.

gogins commented 3 months ago

The question for me is, can I write a piece in zig that links with both WASM and native builds of Csound and CsoundAC?

gogins commented 3 months ago

My prompt for ChatGPT:

I write musical compositions by programming them. I have just discovered the programming language zig, and I have a question. Zig claims to compile transparently to WebAssembly. The compositions that I write depend on Csound and also on CsoundAC, a C++ library for algorithmic composition. My question is, can I write a composition in the zig language that will link with the native Csound and CsoundAC for a native program, and will link with the WASM Csound and CsoundAC for a WebAssembly program?

Summary of the response:

Challenges and Considerations

  • ABI Compatibility: Ensure that the ABI (Application Binary Interface) used by the WebAssembly version of Csound and CsoundAC is compatible with how you call these functions from Zig.
  • Memory Management: WebAssembly has its own memory management model which may differ from native platforms. You might need to handle this in your Zig code.
  • Performance: WebAssembly might have different performance characteristics compared to native code, so test thoroughly.

Conclusion

Writing a composition in Zig that links with Csound and CsoundAC natively and for WebAssembly is feasible but requires careful handling of the differences between native and WebAssembly environments. By leveraging Zig's ability to interoperate with C libraries and its support for WebAssembly, you can achieve your goal with appropriate setup and configuration.

The issue for me would be the ABI interface for CsoundAudioNode, as I use a layer of messaging middleware that presents the Csound API and calls into CsoundAudioProcessor.js.

gogins commented 3 months ago

I am closing this but may take it up again.