Sfx_gen is a stand-alone C version of DrPetter's sfxr sound effect generator. The project includes the following:
- The synthesizer C module (sfx_gen.c/.h).
- A Qt based GUI program for creating sound parameters & Wave files.
- A CLI program to create Wave files from parameters.
Sfx_gen extends the original sfxr code by adding two new wave types: Triangle & Pink Noise.
To use the C library in your program include the sfx_gen.* files in
your project and implement the sfx_random()
function somewhere in your code.
Here is a minimal example:
#include <stdlib.h>
#include "sfx_gen.h"
int sfx_random(int range) {
return rand() % range;
}
...
SfxParams param;
SfxSynth* synth = sfx_allocSynth(SFX_I16, 44100, 10);
srand(999);
sfx_genRandomize(¶m, SFX_SQUARE);
int sampleCount = sfx_generateWave(synth, ¶m);
// Use the generated samples as desired, e.g.
alBufferData(bufId, AL_FORMAT_MONO16, synth->samples.i16,
sampleCount * sizeof(int16_t), synth->sampleRate);
free(synth);
Sound parameters can be saved as rFX files (compatible with rFXGen v2.5) and reloaded later:
const char* error = sfx_saveRfx(¶m, "test_sound.rfx");
if (error)
printf("Save RFX: %s\n", error);
...
error = sfx_loadParams(¶m, "test_sound.rfx", NULL);
The compiled code can be modified by defining the following macros:
Macro Name | Effect |
---|---|
CONFIG_SFX_NO_FILEIO | Exclude file load/save functions. |
CONFIG_SFX_NO_GENERATORS | Exclude parameter generator functions. |
SINGLE_FORMAT=[1,3] | Hardcode sfx_generateWave output sample format. |
The qfxgen
program...
Qt 5 and OpenAL are required. Project files are provided for QMake & Copr.
To build with QMake:
qmake-qt5; make
To build both qfxgen & sfxgen with copr:
copr
The sfxgen
program can generate 44.1KHz Wave files from multiple .rfx
files in two ways.
- The output filename for each Wave can be specified by using the
-o
option after each input file. - If
-o
does not follow the input filename then that path with the extension replaced with.wav
is used as the output filename.
To generate Wave files for an entire directory shell wildcards can be used:
sfxgen my_sounds/*.rfx
To build on Unix systems:
cc main.c -Isupport -lm -o sfxgen