Browse Source

Changed name. Got code working.

master
dirkson 7 months ago
parent
commit
7d566ed576
7 changed files with 99 additions and 26 deletions
  1. 5
    0
      .gitignore
  2. 20
    0
      .lvimrc
  3. 2
    2
      README.md
  4. 9
    9
      include/csfxr.h
  5. 12
    5
      meson.build
  6. 10
    10
      src/csfxr.c
  7. 41
    0
      src/examples/basic.c

+ 5
- 0
.gitignore View File

@@ -71,3 +71,8 @@ tags
# Persistent undo
[._]*.un~

meson-log.txt
meson/*
bin/*
lib/*


+ 20
- 0
.lvimrc View File

@@ -0,0 +1,20 @@
"Stuff you're more likely to edit goes near the top

let s:projstd = '-std=gnu89 -Wall'
let s:projinc = '-Iinclude -Isrc -Imeson/debug -Isrc/example'
let s:projopt = ''

let g:ale_linters = {'c': ['clang', 'clangcheck']}
"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck']}
"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck','cquery', 'flawfinder', 'gcc']}

let s:projstrn = s:projstd.' '.s:projopt.' '.s:projinc
let g:ale_c_clang_options = s:projstrn
let g:ale_c_clangd_options = s:projstrn
let g:ale_c_clangformat_options = s:projstrn
let g:ale_c_clangcheck_options = s:projstrn
let g:ale_c_cppcheck_options = s:projstrn
let g:ale_c_gcc_options = s:projstrn
"Use build_dir instead
"let g:ale_c_clangtidy_options = projstrn
let g:ale_c_build_dir = 'meson/debug'

+ 2
- 2
README.md View File

@@ -1,3 +1,3 @@
# bepx
# csfxr

bepx is a c89 library to procedurally generate simple synth noises. It is based on DrPetter's sfxr and Bjorn Ritzl's Blip.
Csfxr is a C wrapper around DrPetter's sfxr to generate randomized game sounds. The sfxr code is based on the rework done by Bjorn Ritzl's for Blip.

include/sfxr.h → include/csfxr.h View File

@@ -10,10 +10,10 @@ extern "C"{

#define PI 3.14159265f

struct SfxrSound {
typedef struct SfxrSound {
unsigned char* data;
int length;
};
} SfxrSound;

typedef struct Sfxr {
int wave_type;
@@ -104,13 +104,13 @@ typedef struct Sfxr {
float filesample;
} Sfxr;

struct SfxrSound SfxrBlip(int seed);
struct SfxrSound SfxrJump(int seed);
struct SfxrSound SfxrHurt(int seed);
struct SfxrSound SfxrPowerup(int seed);
struct SfxrSound SfxrExplosion(int seed);
struct SfxrSound SfxrLaser(int seed);
struct SfxrSound SfxrPickup(int seed);
SfxrSound SfxrBlip(int seed);
SfxrSound SfxrJump(int seed);
SfxrSound SfxrHurt(int seed);
SfxrSound SfxrPowerup(int seed);
SfxrSound SfxrExplosion(int seed);
SfxrSound SfxrLaser(int seed);
SfxrSound SfxrPickup(int seed);

#ifdef __cplusplus
}

+ 12
- 5
meson.build View File

@@ -1,16 +1,23 @@
project('bepx', 'c', default_options : ['default_library=static', 'c_std=gnu89'])
project('csfxr', 'c', default_options : ['default_library=static', 'c_std=gnu89'])
incdir = include_directories('include')

libbepx = library('bepx', 'src/sfxr.c', 'src/bepx.c', include_directories : incdir)
bepx_dep = declare_dependency(link_with : libbepx, include_directories : incdir)

cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : true)
#m_dep = dependency('m')
libcsfxr = library('csfxr', 'src/csfxr.c', include_directories : incdir, dependencies:m_dep)
csfxr_dep = declare_dependency(link_with : libcsfxr, include_directories : incdir)


if not meson.is_subproject()

#Basic test binary
executable('bepxbasic', 'src/examples/basic.c', include_directories : incdir, dependencies: bepx_dep)
depao = dependency('ao')

executable('basic', 'src/examples/basic.c', include_directories : incdir, dependencies: [csfxr_dep, depao])

#Complex test binary
executable('bepxtest', 'src/examples/test.c', include_directories : incdir, dependencies: [bepx_dep])
#executable('test', 'src/examples/test.c', include_directories : incdir, dependencies: csfxr_dep)

endif


src/sfxr.c → src/csfxr.c View File

@@ -20,7 +20,7 @@
THE SOFTWARE.
*/

#include "sfxr.h"
#include "csfxr.h"

static Sfxr sfxr;

@@ -342,8 +342,8 @@ int SfxrCalculateLength() {
}


struct SfxrSound SfxrToBuffer() {
struct SfxrSound sound;
SfxrSound SfxrToBuffer() {
SfxrSound sound;
sound.length = SfxrCalculateLength();
sound.data = (unsigned char*) malloc(sound.length);

@@ -413,7 +413,7 @@ int SfxrToWAV(const char* filename)
}


struct SfxrSound SfxrPickup(int seed) {
SfxrSound SfxrPickup(int seed) {
srand(seed);
SfxrResetParams();

@@ -430,7 +430,7 @@ struct SfxrSound SfxrPickup(int seed) {
return SfxrToBuffer();
}

struct SfxrSound SfxrLaser(int seed) {
SfxrSound SfxrLaser(int seed) {
srand(seed);
SfxrResetParams();

@@ -477,7 +477,7 @@ struct SfxrSound SfxrLaser(int seed) {



struct SfxrSound SfxrExplosion(int seed) {
SfxrSound SfxrExplosion(int seed) {
srand(seed);
SfxrResetParams();

@@ -522,7 +522,7 @@ struct SfxrSound SfxrExplosion(int seed) {
}


struct SfxrSound SfxrPowerup(int seed) {
SfxrSound SfxrPowerup(int seed) {
srand(seed);
SfxrResetParams();

@@ -555,7 +555,7 @@ struct SfxrSound SfxrPowerup(int seed) {
}


struct SfxrSound SfxrHurt(int seed) {
SfxrSound SfxrHurt(int seed) {
srand(seed);
SfxrResetParams();

@@ -578,7 +578,7 @@ struct SfxrSound SfxrHurt(int seed) {
}


struct SfxrSound SfxrJump(int seed) {
SfxrSound SfxrJump(int seed) {
srand(seed);
SfxrResetParams();

@@ -599,7 +599,7 @@ struct SfxrSound SfxrJump(int seed) {
}


struct SfxrSound SfxrBlip(int seed) {
SfxrSound SfxrBlip(int seed) {
srand(seed);
SfxrResetParams();


+ 41
- 0
src/examples/basic.c View File

@@ -0,0 +1,41 @@
#include <csfxr.h>
#include <ao/ao.h>
#include <time.h>

int main()
{
//init
ao_initialize();
int driver = ao_default_driver_id();
ao_sample_format format = {0};
format.bits = 16;
format.channels = 2;
format.rate = 44100;
format.byte_format = AO_FMT_LITTLE;
ao_device *device = ao_open_live(driver, &format, NULL /* no options */);
srand(time(NULL));

struct timespec delay;
delay.tv_sec = 0;


//play sound
int i;
for (i=0; i < 100; i++)
{
SfxrSound sound = SfxrBlip(rand());
ao_play(device, (char *)sound.data, sound.length);
free(sound.data);
delay.tv_nsec = (rand() % (300000001 - 20000000)) + 20000000;
nanosleep(&delay, NULL);
}


//cleanup
ao_close(device);
ao_shutdown();
return 0;
}




Loading…
Cancel
Save