122 lines
2.9 KiB
C
122 lines
2.9 KiB
C
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "soundconfig.h"
|
|
|
|
/*****************************
|
|
* soundconfig_load_defaults *
|
|
*****************************/
|
|
|
|
void soundconfig_load_defaults(SoundConfig *conf) {
|
|
conf->path[0] = '\0';
|
|
conf->gamma_amp = 2.2;
|
|
conf->gamma_layer = 1;
|
|
conf->tau_off = 1;
|
|
conf->tau_cut = proc_raw_tau_value(100);
|
|
conf->mix_layers = false;
|
|
for(int i = 0; i < MAX_FX; ++i) {
|
|
conf->fx_pre[i][0] = '\0';
|
|
conf->fx_post[i][0] = '\0';
|
|
conf->global_fx_pre[i][0] = '\0';
|
|
conf->global_fx_post[i][0] = '\0';
|
|
}
|
|
}
|
|
|
|
/********************
|
|
* soundconfig_copy *
|
|
********************/
|
|
|
|
void soundconfig_copy_globals(SoundConfig *to, SoundConfig *from) {
|
|
to->gamma_amp = from->gamma_amp;
|
|
to->gamma_layer = from->gamma_layer;
|
|
to->tau_off = from->tau_off;
|
|
to->tau_cut = from->tau_cut;
|
|
to->mix_layers = from->mix_layers;
|
|
for(int i = 0; i < MAX_FX; ++i) {
|
|
strncpy(to->global_fx_pre[i], from->fx_pre[i], MAX_FX_LINE);
|
|
strncpy(to->global_fx_post[i], from->fx_post[i], MAX_FX_LINE);
|
|
}
|
|
}
|
|
|
|
/**********************
|
|
* proc_fx *
|
|
**********************/
|
|
|
|
// This function parses a config file `fx` value into discrete lines that
|
|
// can be parsed later.
|
|
void soundconfig_proc_fx(SoundConfig *conf, const char *line, bool pre) {
|
|
const char *src = line;
|
|
int i_src = 0;
|
|
int i_fx = 0;
|
|
|
|
char (*fx)[MAX_FX_LINE] = pre ? conf->fx_pre : conf->fx_post;
|
|
|
|
while(1) {
|
|
// Find the next empty fx slot.
|
|
for(; i_fx < MAX_FX; ++i_fx) {
|
|
if(fx[i_fx][0] == '\0') {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Make sure we're not beyond the end.
|
|
if(i_fx == MAX_FX) {
|
|
printf("Maximum number of effects reached.\n");
|
|
exit(1);
|
|
}
|
|
|
|
// Skip spaces.
|
|
while(src[i_src] == ' ') {
|
|
i_src++;
|
|
}
|
|
|
|
// Check for end of line.
|
|
if(src[i_src] == '\0') {
|
|
return;
|
|
}
|
|
|
|
char *dest = fx[i_fx];
|
|
int i_dest = 0;
|
|
|
|
// Copy until closing paren.
|
|
while(1) {
|
|
char c = src[i_src];
|
|
i_src++;
|
|
|
|
if(c == '\0') {
|
|
printf("Failed to parse effects line: %s\n", line);
|
|
exit(1);
|
|
}
|
|
|
|
dest[i_dest] = c;
|
|
i_dest++;
|
|
|
|
if(i_dest >= MAX_FX_LINE) {
|
|
printf("FX line was too long: %s\n", line);
|
|
exit(1);
|
|
}
|
|
|
|
if(c == ')') {
|
|
dest[i_dest] = '\0';
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/**********************
|
|
* proc_raw_tau_value *
|
|
**********************/
|
|
|
|
// Convert a millisecond time-constant value into a per-sample decay.
|
|
double proc_raw_tau_value(double value)
|
|
{
|
|
if (value <= 0) {
|
|
return 1;
|
|
} else {
|
|
return exp(-1000.0 / (SAMPLE_RATE * value));
|
|
}
|
|
}
|