Browse Source

Changed name. Got code working.

dirkson 2 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
71 71
 # Persistent undo
72 72
 [._]*.un~
73 73
 
74
+meson-log.txt
75
+meson/*
76
+bin/*
77
+lib/*
78
+

+ 20
- 0
.lvimrc View File

@@ -0,0 +1,20 @@
1
+"Stuff you're more likely to edit goes near the top
2
+
3
+let s:projstd = '-std=gnu89 -Wall'
4
+let s:projinc = '-Iinclude -Isrc -Imeson/debug -Isrc/example'
5
+let s:projopt = ''
6
+
7
+let g:ale_linters = {'c': ['clang', 'clangcheck']}
8
+"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck']}
9
+"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck','cquery', 'flawfinder', 'gcc']}
10
+
11
+let s:projstrn = s:projstd.' '.s:projopt.' '.s:projinc
12
+let g:ale_c_clang_options       = s:projstrn
13
+let g:ale_c_clangd_options      = s:projstrn
14
+let g:ale_c_clangformat_options = s:projstrn
15
+let g:ale_c_clangcheck_options  = s:projstrn
16
+let g:ale_c_cppcheck_options    = s:projstrn
17
+let g:ale_c_gcc_options         = s:projstrn
18
+"Use build_dir instead
19
+"let g:ale_c_clangtidy_options  = projstrn
20
+let g:ale_c_build_dir = 'meson/debug'

+ 2
- 2
README.md View File

@@ -1,3 +1,3 @@
1
-# bepx
1
+# csfxr
2 2
 
3
-bepx is a c89 library to procedurally generate simple synth noises. It is based on DrPetter's sfxr and Bjorn Ritzl's Blip.
3
+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"{
10 10
 
11 11
 #define PI 3.14159265f
12 12
 
13
-struct SfxrSound {
13
+typedef struct SfxrSound {
14 14
 	unsigned char* data;
15 15
 	int length;
16
-};
16
+} SfxrSound;
17 17
 
18 18
 typedef struct Sfxr {
19 19
 	int wave_type;
@@ -104,13 +104,13 @@ typedef struct Sfxr {
104 104
 	float filesample;
105 105
 } Sfxr;
106 106
 
107
-struct SfxrSound SfxrBlip(int seed);
108
-struct SfxrSound SfxrJump(int seed);
109
-struct SfxrSound SfxrHurt(int seed);
110
-struct SfxrSound SfxrPowerup(int seed);
111
-struct SfxrSound SfxrExplosion(int seed);
112
-struct SfxrSound SfxrLaser(int seed);
113
-struct SfxrSound SfxrPickup(int seed);
107
+SfxrSound SfxrBlip(int seed);
108
+SfxrSound SfxrJump(int seed);
109
+SfxrSound SfxrHurt(int seed);
110
+SfxrSound SfxrPowerup(int seed);
111
+SfxrSound SfxrExplosion(int seed);
112
+SfxrSound SfxrLaser(int seed);
113
+SfxrSound SfxrPickup(int seed);
114 114
 
115 115
 #ifdef __cplusplus
116 116
 }

+ 12
- 5
meson.build View File

@@ -1,16 +1,23 @@
1
-project('bepx', 'c', default_options : ['default_library=static', 'c_std=gnu89'])
1
+project('csfxr', 'c', default_options : ['default_library=static', 'c_std=gnu89'])
2 2
 incdir = include_directories('include')
3 3
 
4
-libbepx = library('bepx', 'src/sfxr.c', 'src/bepx.c', include_directories : incdir)
5
-bepx_dep = declare_dependency(link_with : libbepx, include_directories : incdir)
4
+
5
+cc = meson.get_compiler('c')
6
+m_dep = cc.find_library('m', required : true)
7
+#m_dep = dependency('m')
8
+libcsfxr = library('csfxr', 'src/csfxr.c', include_directories : incdir, dependencies:m_dep)
9
+csfxr_dep = declare_dependency(link_with : libcsfxr, include_directories : incdir)
10
+
6 11
 
7 12
 if not meson.is_subproject()
8 13
 
9 14
 #Basic test binary
10
-executable('bepxbasic', 'src/examples/basic.c', include_directories : incdir, dependencies: bepx_dep)
15
+depao = dependency('ao')
16
+
17
+executable('basic', 'src/examples/basic.c', include_directories : incdir, dependencies: [csfxr_dep, depao])
11 18
 
12 19
 #Complex test binary
13
-executable('bepxtest', 'src/examples/test.c', include_directories : incdir, dependencies: [bepx_dep])
20
+#executable('test', 'src/examples/test.c', include_directories : incdir, dependencies: csfxr_dep)
14 21
 
15 22
 endif
16 23
 

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

@@ -20,7 +20,7 @@
20 20
 	THE SOFTWARE.
21 21
 */
22 22
 
23
-#include "sfxr.h"
23
+#include "csfxr.h"
24 24
 
25 25
 static Sfxr sfxr;
26 26
 
@@ -342,8 +342,8 @@ int SfxrCalculateLength() {
342 342
 }
343 343
 
344 344
 
345
-struct SfxrSound SfxrToBuffer() {
346
-	struct SfxrSound sound;
345
+SfxrSound SfxrToBuffer() {
346
+	SfxrSound sound;
347 347
 	sound.length = SfxrCalculateLength();
348 348
 	sound.data = (unsigned char*) malloc(sound.length);
349 349
 
@@ -413,7 +413,7 @@ int SfxrToWAV(const char* filename)
413 413
 }
414 414
 
415 415
 
416
-struct SfxrSound SfxrPickup(int seed) {
416
+SfxrSound SfxrPickup(int seed) {
417 417
 	srand(seed);
418 418
 	SfxrResetParams();
419 419
 
@@ -430,7 +430,7 @@ struct SfxrSound SfxrPickup(int seed) {
430 430
 	return SfxrToBuffer();
431 431
 }
432 432
 
433
-struct SfxrSound SfxrLaser(int seed) {
433
+SfxrSound SfxrLaser(int seed) {
434 434
 	srand(seed);
435 435
 	SfxrResetParams();
436 436
 
@@ -477,7 +477,7 @@ struct SfxrSound SfxrLaser(int seed) {
477 477
 
478 478
 
479 479
 
480
-struct SfxrSound SfxrExplosion(int seed) {
480
+SfxrSound SfxrExplosion(int seed) {
481 481
 	srand(seed);
482 482
 	SfxrResetParams();
483 483
 
@@ -522,7 +522,7 @@ struct SfxrSound SfxrExplosion(int seed) {
522 522
 }
523 523
 
524 524
 
525
-struct SfxrSound SfxrPowerup(int seed) {
525
+SfxrSound SfxrPowerup(int seed) {
526 526
 	srand(seed);
527 527
 	SfxrResetParams();
528 528
 
@@ -555,7 +555,7 @@ struct SfxrSound SfxrPowerup(int seed) {
555 555
 }
556 556
 
557 557
 
558
-struct SfxrSound SfxrHurt(int seed) {
558
+SfxrSound SfxrHurt(int seed) {
559 559
 	srand(seed);
560 560
 	SfxrResetParams();
561 561
 
@@ -578,7 +578,7 @@ struct SfxrSound SfxrHurt(int seed) {
578 578
 }
579 579
 
580 580
 
581
-struct SfxrSound SfxrJump(int seed) {
581
+SfxrSound SfxrJump(int seed) {
582 582
 	srand(seed);
583 583
 	SfxrResetParams();
584 584
 
@@ -599,7 +599,7 @@ struct SfxrSound SfxrJump(int seed) {
599 599
 }
600 600
 
601 601
 
602
-struct SfxrSound SfxrBlip(int seed) {
602
+SfxrSound SfxrBlip(int seed) {
603 603
 	srand(seed);
604 604
 	SfxrResetParams();
605 605
 

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

@@ -0,0 +1,41 @@
1
+#include <csfxr.h>
2
+#include <ao/ao.h>
3
+#include <time.h>
4
+
5
+int main()
6
+{
7
+	//init
8
+	ao_initialize();
9
+	int driver = ao_default_driver_id();
10
+	ao_sample_format format = {0};
11
+		format.bits = 16;
12
+		format.channels = 2;
13
+		format.rate = 44100;
14
+		format.byte_format = AO_FMT_LITTLE;
15
+		ao_device *device = ao_open_live(driver, &format, NULL /* no options */);
16
+	srand(time(NULL));
17
+
18
+	struct timespec delay;
19
+	delay.tv_sec = 0;
20
+
21
+
22
+	//play sound
23
+	int i;
24
+	for (i=0; i < 100; i++)
25
+	{
26
+		SfxrSound sound = SfxrBlip(rand());
27
+		ao_play(device, (char *)sound.data, sound.length);
28
+		free(sound.data);
29
+		delay.tv_nsec = (rand() % (300000001 - 20000000)) + 20000000;
30
+		nanosleep(&delay, NULL);
31
+	}
32
+
33
+
34
+	//cleanup
35
+	ao_close(device);
36
+	ao_shutdown();
37
+	return 0;
38
+}
39
+
40
+
41
+

Loading…
Cancel
Save