Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
Clang-formatted code. Fixed CRLF bug. Fixed print_debug* bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
harieamjari committed May 26, 2021
1 parent 2b26356 commit 5c61dd8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion dats/dats.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int process_args(const int argc, char *const *argv) {
global_errors++;
break;
default:
fp = fopen(argv[i], "r");
fp = fopen(argv[i], "rb");
if (fp == NULL) {
perror(argv[i]);
return 1;
Expand Down
33 changes: 21 additions & 12 deletions dats/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,20 @@ void print_debugging_info(const token_t tok, dats_t *d) {
ERROR("\n");
}
char buff[1000] = {0};
if (d->scan_line[strlen(d->scan_line)-1] != '\n'){
if (d->scan_line[strlen(d->scan_line) - 1] != '\n') {
int ls = strlen(d->scan_line);
d->scan_line[ls] = '\n';
d->scan_line[ls+1] = 0;
d->scan_line[ls + 1] = 0;
}
if (d->scan_line[strlen(d->scan_line)-2] != '\r'){
if (d->scan_line[strlen(d->scan_line) - 2] == '\r') {
int ls = strlen(d->scan_line);
memcpy(d->scan_line+(ls-2), d->scan_line+(ls-1), 2);
memcpy(d->scan_line + (ls - 2), d->scan_line + (ls - 1), 2);
}

int length = sprintf(buff, " %d | %s", line_token_found, d->scan_line);
ERROR("%s", buff);
ERROR("%*s\n", column_token_found + (length - (int)strlen(d->scan_line)),
ERROR("%*s\n", column_token_found +
(length - (int)strlen(d->scan_line)),
"^");
}
/*---------.
Expand All @@ -198,8 +199,14 @@ token_t read_next_tok_cur_dats_t(dats_t *const d) {
d->line++;
seek++;
d->column = 0;
if (fgets(d->scan_line, 500, d->fp) != NULL)
void *p = fgets(d->scan_line, 500, d->fp);
if (p != NULL)
fseek(d->fp, -(long)(strlen(d->scan_line)), SEEK_CUR);
else {
d->scan_line[0] = ' ';
d->scan_line[1] = 0;
}

goto w;
}
line_token_found = d->line;
Expand Down Expand Up @@ -264,8 +271,8 @@ token_t read_next_tok_cur_dats_t(dats_t *const d) {
} else if (c == '\n') {
d->line++;
d->column = 0;
if (fgets(d->scan_line, 500, d->fp) != NULL)
fseek(d->fp, -(long)(strlen(d->scan_line)), SEEK_CUR);
if (fgets(d->scan_line, 500, d->fp) != NULL)
fseek(d->fp, -(long)(strlen(d->scan_line)), SEEK_CUR);
seek++;
}
break;
Expand Down Expand Up @@ -294,7 +301,7 @@ token_t read_next_tok_cur_dats_t(dats_t *const d) {
c = '/';
}
switch (c) {
// clang-format off
// clang-format off
/* *INDENT-OFF* */
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
Expand Down Expand Up @@ -428,7 +435,7 @@ token_t read_next_tok_cur_dats_t(dats_t *const d) {
return TOK_IDENTIFIER;
}
}
// clang-format off
// clang-format off
/* *INDENT-OFF* */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
Expand Down Expand Up @@ -674,7 +681,9 @@ void print_all_symrec_t_cur_dats_t(const dats_t *const t) {
token_t_to_str(TOK_STAFF));
break;
case TOK_PCM16:
printf(" %-20s %-20s\n", p->value.staff.identifier == NULL? "(null)": p->value.staff.identifier,
printf(" %-20s %-20s\n",
p->value.staff.identifier == NULL ? "(null)"
: p->value.staff.identifier,
token_t_to_str(TOK_PCM16));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion dats/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ EXTERN const char *token_t_to_str(const token_t t);
EXTERN symrec_t *getsym(const dats_t *const t, char const *const id);
EXTERN token_t read_next_tok_cur_dats_t(dats_t *const t);
EXTERN void print_all_symrec_t_cur_dats_t(const dats_t *const t);
EXTERN void print_debugging_info(const token_t tok, dats_t * d);
EXTERN void print_debugging_info(const token_t tok, dats_t *d);

EXTERN int line_token_found;
EXTERN int column_token_found;
Expand Down
2 changes: 1 addition & 1 deletion libsynth/s_kpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static pcm16_t *synth(const symrec_t *restrict staff) {
: (i > nn->duration - (uint32_t)nn->release
? (-(double)i + (double)(nn->duration)) / nn->release
: 1.0));
//pcm[total + i] += wavetable[cur];
// pcm[total + i] += wavetable[cur];
prev = wavetable[cur];
cur++;
cur %= (int)(44100.0 / nn->frequency);
Expand Down
48 changes: 26 additions & 22 deletions libsynth/s_sin.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,41 @@ static void free_string_options(void) {
}
}

static double linear_attack(double x, double n){
return x / n;
}
static double linear_attack(double x, double n) { return x / n; }

static double linear_release(double x, double n){
return x / n;
}
static double linear_release(double x, double n) { return x / n; }

static double exponential_attack(double x, double n){
return pow(M_E, x-n);
}
static double exponential_release(double x, double n){
return pow(M_E, (-x-n)+1.0);
static double exponential_attack(double x, double n) { return pow(M_E, x - n); }
static double exponential_release(double x, double n) {
return pow(M_E, (-x - n) + 1.0);
}
static pcm16_t *synth(const symrec_t *staff) {

double (*attack_ret)(double, double) = NULL;
double (*release_ret)(double, double) = NULL;

switch (options[2].value.intv){
case 0: attack_ret = linear_attack; break;
case 1: attack_ret = exponential_attack; break;
default: fprintf(stderr, "unknown attack type: %d\n", options[2].value.intv);
return NULL;
switch (options[2].value.intv) {
case 0:
attack_ret = linear_attack;
break;
case 1:
attack_ret = exponential_attack;
break;
default:
fprintf(stderr, "unknown attack type: %d\n", options[2].value.intv);
return NULL;
}

switch (options[5].value.intv){
case 0: release_ret = linear_release; break;
case 1: release_ret = exponential_release; break;
default: fprintf(stderr, "unknown attack type: %d\n", options[5].value.intv);
return NULL;
switch (options[5].value.intv) {
case 0:
release_ret = linear_release;
break;
case 1:
release_ret = exponential_release;
break;
default:
fprintf(stderr, "unknown attack type: %d\n", options[5].value.intv);
return NULL;
}
int16_t *pcm = calloc(sizeof(int16_t), (size_t)staff->value.staff.numsamples);
pcm16_t *pcm_ctx = malloc(sizeof(pcm16_t));
Expand All @@ -93,7 +97,7 @@ static pcm16_t *synth(const symrec_t *staff) {
(i < (uint32_t)nn->attack
? attack_ret((double)i, nn->attack)
: (i > nn->duration - (uint32_t)nn->release
? release_ret(-(double)i+nn->duration, nn->release)
? release_ret(-(double)i + nn->duration, nn->release)
: 1.0));
}
}
Expand Down

0 comments on commit 5c61dd8

Please sign in to comment.