Skip to content

A stand-alone C version of DrPetter's sfxr synthesizer

License

Notifications You must be signed in to change notification settings

WickedSmoke/sfx_gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sfx_gen

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.

Synthesizer Module

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(&param, SFX_SQUARE);
int sampleCount = sfx_generateWave(synth, &param);

// 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(&param, "test_sound.rfx");
if (error)
    printf("Save RFX: %s\n", error);

...

error = sfx_loadParams(&param, "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.

GUI Program

The qfxgen program...

Screenshot

Building the GUI

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

CLI Program

The sfxgen program can generate 44.1KHz Wave files from multiple .rfx files in two ways.

  1. The output filename for each Wave can be specified by using the -o option after each input file.
  2. 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

Building the CLI

To build on Unix systems:

cc main.c -Isupport -lm -o sfxgen