diff options
author | Richard <q@1bpm.net> | 2025-03-19 02:14:06 +0000 |
---|---|---|
committer | Richard <q@1bpm.net> | 2025-03-19 02:14:06 +0000 |
commit | 8a4bb15e2c7729f70e106e220745821a467fcef4 (patch) | |
tree | 7a6639bda4f51aa80b809209115b709603b8d4fd | |
parent | 89200bf7fbccd99cad6167a15ab1da2395a250ec (diff) | |
download | libguttersynth-master.tar.gz libguttersynth-master.tar.bz2 libguttersynth-master.zip |
-rw-r--r-- | examples/example1.c | 14 | ||||
-rw-r--r-- | examples/example2.cpp | 10 | ||||
-rw-r--r-- | src/guttersynth.c | 44 |
3 files changed, 32 insertions, 36 deletions
diff --git a/examples/example1.c b/examples/example1.c index f827ca7..8a9ee5a 100644 --- a/examples/example1.c +++ b/examples/example1.c @@ -49,7 +49,7 @@ FILE* wavfile_open() header.num_channels = 1; header.sample_rate = samples_per_second; header.byte_rate = samples_per_second * (bits_per_sample / 8); - header.block_align = bits_per_sample/8; + header.block_align = bits_per_sample / 8; header.bits_per_sample = bits_per_sample; header.data_length = 0; @@ -127,12 +127,12 @@ void create() target = wavfile_open(); int seconds = 20; int total_samples = samples_per_second * seconds; - int sample = 0; - int buffer_pos = 0; - int buffer_size = 4410; - double *buffer = (double*) malloc(sizeof(double) * buffer_size); + int sample = 0; + int buffer_pos = 0; + int buffer_size = 4410; + double *buffer = (double*) malloc(sizeof(double) * buffer_size); - gutter_state *gs = gutter_init(4, 24, samples_per_second); + gutter_state *gs = gutter_init(4, 24, samples_per_second); //gutter_randomisefilters(gs); double* filterAutomation = malloc(sizeof(double) * gs->bankCount * gs->filterCount * 3 * 2); @@ -209,7 +209,7 @@ void create() free(buffer); free(filterAutomation); - gutter_cleanup(gs); + gutter_cleanup(gs); wavfile_close(); } diff --git a/examples/example2.cpp b/examples/example2.cpp index 415c1ff..13e8228 100644 --- a/examples/example2.cpp +++ b/examples/example2.cpp @@ -50,7 +50,6 @@ public: } void write(double value) { - //https://www.cplusplus.com/forum/beginner/166954/ write_word((short) (value * SHRT_MAX * 0.5), 2); } @@ -82,17 +81,14 @@ public: void run() { int total_samples = 30 * samplerate; int sample = 0; - short data; - gs->randomiseFilters(); + FLT data; gs->filtersOn(true); gs->smoothing(true); gs->distortionMethod(2); - + gs->randomiseFilters(); + for (int sample = 0; sample < total_samples; sample ++) { data = gs->process(); - if (data > 0) { - std::cout << data; - } wav->write(data); if (sample % samplerate == 0) { // randomise every second diff --git a/src/guttersynth.c b/src/guttersynth.c index 7e1607a..7e30411 100644 --- a/src/guttersynth.c +++ b/src/guttersynth.c @@ -95,7 +95,7 @@ static void gutter_distortion(gutter_state* s, FLT* audio_ptr) default: output = input; } - *audio_ptr = output; + *audio_ptr = output; } @@ -106,13 +106,13 @@ static void gutter_distortion(gutter_state* s, FLT* audio_ptr) */ void gutter_randomisefilters(gutter_state* s) { - int i, b, f; + int i, b, f; for (b = 0; b < s->bankCount; b++) { for (f = 0; f < s->filterCount; f++) { - i = b * s->bankCount + f; + i = b * s->bankCount + f; s->filterFreqs[i] = rangerandom(100, 4000); - s->gains[i] = rangerandom(0, 1); - s->Q[i] = rangerandom(20, 200); + s->gains[i] = rangerandom(0, 1); + s->Q[i] = rangerandom(20, 200); } } gutter_calccoeffs(s); @@ -140,11 +140,11 @@ int gutter_setdistortionmethod(gutter_state* s, int method) */ int gutter_setfreq(gutter_state* s, int bank, int filter, FLT value) { - if (bank >= s->bankCount || filter >= s->filterCount || bank < 0 || filter < 0) { - return -1; - } - s->filterFreqs[bank*s->bankCount+filter] = value; - return 0; + if (bank >= s->bankCount || filter >= s->filterCount || bank < 0 || filter < 0) { + return -1; + } + s->filterFreqs[bank*s->bankCount+filter] = value; + return 0; } @@ -160,10 +160,10 @@ int gutter_setfreq(gutter_state* s, int bank, int filter, FLT value) */ int gutter_setq(gutter_state* s, int bank, int filter, FLT value) { - if (bank >= s->bankCount || filter >= s->filterCount || bank < 0 || filter < 0) { - return -1; - } - s->Q[bank*s->bankCount+filter] = value; + if (bank >= s->bankCount || filter >= s->filterCount || bank < 0 || filter < 0) { + return -1; + } + s->Q[bank*s->bankCount+filter] = value; return 0; } @@ -180,10 +180,10 @@ int gutter_setq(gutter_state* s, int bank, int filter, FLT value) */ int gutter_setgain(gutter_state* s, int bank, int filter, FLT value) { - if (bank >= s->bankCount || filter >= s->filterCount || bank < 0 || filter < 0) { - return -1; - } - s->gains[bank*s->bankCount+filter] = value; + if (bank >= s->bankCount || filter >= s->filterCount || bank < 0 || filter < 0) { + return -1; + } + s->gains[bank*s->bankCount+filter] = value; return 0; } @@ -246,7 +246,7 @@ gutter_state* gutter_init_ca(int bankCount, int filterCount, int samplerate, size2d = sizeof(FLT) * bankCount * filterCount; s->gains = (FLT*) allocator(size2d); - s->Q = (FLT*) allocator(size2d); + s->Q = (FLT*) allocator(size2d); s->filterFreqs = (FLT*) allocator(size2d); s->gi.prevX1 = (FLT*) allocator(size2d); s->gi.prevX2 = (FLT*) allocator(size2d); @@ -277,8 +277,8 @@ gutter_state* gutter_init_ca(int bankCount, int filterCount, int samplerate, s->gi.prevX2[i] = 0; s->gi.prevY1[i] = 0; s->gi.prevY2[i] = 0; - s->gains[i] = 1; - s->Q[i] = 1; + s->gains[i] = 1; + s->Q[i] = 1; } } @@ -473,4 +473,4 @@ void gutter_process_samples(gutter_state* s, FLT* audioOutput, int nsamps) for (i = 0; i < nsamps; i++) { audioOutput[i] = gutter_process_input(s, 0); } -}
\ No newline at end of file +} |