Question

How can I play and synthesize custom waves in Lazarus/Free Pascal? The solution has to be realtime-friendly, as it is for a game engine. It should be also multi-platform, so it can be used on win32, Linux and Mac. FMOD/BASS are out (even if aplicable) as I don't want to pay fees if I will want to use it commercially.

Was it helpful?

Solution

There are solutions to that. My favourite library is Steinberg's ASIO. It is a very simple API, it's got wrappers for Linux, Windows, MAC and i guess some other platforms as well. It is a professional API for low-latency recording / playback. You usually need a soundcard that supports it, but recently some drivers emerged, using native platform API to emulate ASIO device (e.g. ASIO4ALL in windows).

ASIO's got a simple function in which buffers are swapped, where you can generate your wavefrom procedurally to be played back practically immediately (there are latencies in order of milliseconds). That's for the realtimeness.

The API as such is royalty free which means you can use it in a commercial project and don't have to pay anyone.

As for Pascal bindings, I believe you will have to do that yourself. But the whole initialization and operation of ASIO is <100 lines of C/C++ code (and you actually only need to control sound synthesis and maybe device selection - ony two functions that need to be exported by the wrapper) so that really should not be hard at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top