This is a single-header adaptation of the library version of cRSID for embedding in game engines or other applications. Changes have been made for easier compilation in C/C++ environments and with varying compilers (tested with MSVC, GCC, and Clang across different operating systems). SDL and filesystem references have been removed; the library is intended to receive an in-memory SID track and produce samples on demand.
Define CRSID_IMPLEMENTATION before including libcRSID.h in one source file within your project. It can then be included anywhere else that it needs to be referenced.
To compile a test program, please use the CMakeLists file in the example directory. It will build a small program that displays a window and replays an embedded SID file, or if passed a filepath as the first parameter will attempt to play it.
- The test program uses the Sokol libraries which are zlib-licensed and is based on the mod player example from sokol-samples, which is MIT licensed. Neither of these licenses affect libcRSID when compiled on its own.
- Initialize a
cRSID_C64instancepointer with thecRSID_initfunction, passing the desired frequency/sampling rate as a parameter and a boolean to enable/disable the higher-quality wave generators (at the expense of increased overhead). - Initialize a
cRSID_SIDheaderpointer with thecRSID_processSIDbufferfunction, passing the previously createdcRSID_C64instanceas well as a pointer to a memory buffer containing the SID track and its length as parameters.- NOTE: The
cRSID_SIDheaderwill use the same pointer as the memory buffer you passed to it here. It is NOT safe to free this buffer until you are completely done with the track!
- NOTE: The
- Alternatively, initialize a
cRSID_SIDheaderpointer with thecRSID_processSIDfilefunction, passing the previously createdcRSID_C64instanceas well as a file path to a valid SID file.- If a track is loaded with this method, it will create an internal buffer that, unlike with
cRSID_processSIDbuffer, will be freed whencRSID_resetis called.
- If a track is loaded with this method, it will create an internal buffer that, unlike with
- Prepare the SID track for playback with the
cRSID_initSIDtunefunction, passing thecRSID_C64instance,cRSID_SIDheader, and the number of the subtune to play (or 0 if not applicable). This will not generate any audio yet. - In an appropriate place in your program, call the
cRSID_generateSoundfunction, passing thecRSID_C64instance, a pointer to an initialized buffer to store the generated samples and its length as parameters. Generated samples will be in the form of pairs of signed 16-bit integers.- Alternatively,
cRSID_generateFloatcan be used to produce floating point output.
- Alternatively,
- When finished, hard-reset the SID with the
cRSID_resetfunction, passing thecRSID_C64instanceas a parameter. Do NOT try to free the memory represented by thecRSID_C64instancepointer after this; rather set it to NULL as with the way cRSID works under the hood this will remove a globalcRSID_C64instancethat the library relies on. Next, set thecRSID_SIDheaderpointer to NULL and then free the memory represented by the original pointer used to instantiate it (if not planning to reuse it).