code/text formatting and cleaning up whitespace

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2023-09-24 10:47:54 +03:00
parent f35f948118
commit 00850c8001
8 changed files with 96 additions and 71 deletions

View File

@ -167,7 +167,10 @@ wat2wasm --enable-bulk-memory test_chords.wat
#### Examples
The folder `examples/code` contains usage examples for Sointu with winmm und dsound playback under Windows and asound playback under Unix. Source code is available in C and x86 assembly (win32, elf32 and elf64 versions).
The folder `examples/code` contains usage examples for Sointu with winmm
and dsound playback under Windows and asound playback under Unix. Source
code is available in C and x86 assembly (win32, elf32 and elf64
versions).
To build the examples, use `ninja examples`.

View File

@ -4,7 +4,8 @@
#include <sointu.h>
#include "test_render_samples.h"
void SU_CALLCONV su_render_song(float* buffer) {
void SU_CALLCONV su_render_song(float *buffer)
{
Synth *synth;
const unsigned char commands[] = {SU_ENVELOPE_ID, // MONO
SU_ENVELOPE_ID, // MONO

View File

@ -10,7 +10,8 @@
#define SAMPLES_PER_ROW SAMPLE_RATE * 4 * 60 / (BPM * 16)
const int su_max_samples = SAMPLES_PER_ROW * LENGTH_IN_ROWS;
int main(int argc, char* argv[]) {
int main(int argc, char *argv[])
{
Synth *synth;
float *buffer;
const unsigned char commands[] = {SU_ENVELOPE_ID, // MONO
@ -75,7 +76,8 @@ int main(int argc, char* argv[]) {
}
// Then check that each time we call render, only SAMPLES_PER_ROW
// number of samples are rendered
for (int i = 0; i < 16; i++) {
for (int i = 0; i < 16; i++)
{
// Simulate "small buffers" i.e. render a buffer with 1 sample
// check that buffer full
samples = 1;
@ -124,7 +126,8 @@ finish:
free(buffer);
return retval;
fail:
if (errcode > 0) {
if (errcode > 0)
{
if ((errcode & 0xFF00) != 0)
printf("FPU stack was not empty on exit\n");
if ((errcode & 0x04) != 0)

View File

@ -21,8 +21,8 @@ float syncBuf[SU_SYNCBUFFER_LENGTH];
float fileSyncBuf[SU_BUFFER_LENGTH];
#endif
int main(int argc, char* argv[]) {
int main(int argc, char *argv[])
{
FILE *f;
char filename[256];
int n;
@ -33,7 +33,8 @@ int main(int argc, char* argv[]) {
float max_diff;
float diff;
if (argc < 2) {
if (argc < 2)
{
fprintf(stderr, "usage: [test] path/to/expected_wave.raw");
return 1;
}
@ -64,7 +65,8 @@ int main(int argc, char* argv[]) {
f = fopen(argv[1], "rb");
if (f == NULL) {
if (f == NULL)
{
fprintf(stderr, "No expected waveform found!\n");
goto fail;
}
@ -73,12 +75,14 @@ int main(int argc, char* argv[]) {
fsize = ftell(f);
fseek(f, 0, SEEK_SET);
if (SU_BUFFER_LENGTH * sizeof(SUsample) < fsize) {
if (SU_BUFFER_LENGTH * sizeof(SUsample) < fsize)
{
fprintf(stderr, "Sointu rendered shorter wave than expected\n");
goto fail;
}
if (SU_BUFFER_LENGTH * sizeof(SUsample) > fsize) {
if (SU_BUFFER_LENGTH * sizeof(SUsample) > fsize)
{
fprintf(stderr, "Sointu rendered longer wave than expected\n");
goto fail;
}
@ -89,26 +93,31 @@ int main(int argc, char* argv[]) {
max_diff = 0.0f;
for (n = 0; n < SU_BUFFER_LENGTH; n++) {
for (n = 0; n < SU_BUFFER_LENGTH; n++)
{
diff = (float)fabs((float)(buf[n] - filebuf[n]) / SU_SAMPLE_RANGE);
if (diff > 1e-3f || isnan(diff)) {
if (diff > 1e-3f || isnan(diff))
{
fprintf(stderr, "Sointu rendered different wave than expected\n");
goto fail;
}
if (diff > max_diff) {
if (diff > max_diff)
{
max_diff = diff;
}
}
if (max_diff > 1e-6) {
if (max_diff > 1e-6)
{
fprintf(stderr, "Warning: Sointu rendered almost correct wave, but a small maximum error of %f\n", max_diff);
}
#ifdef SU_SYNC
f = fopen(argv[2], "rb");
if (f == NULL) {
if (f == NULL)
{
fprintf(stderr, "No expected sync waveform found!\n");
goto fail;
}
@ -117,12 +126,14 @@ int main(int argc, char* argv[]) {
fsize = ftell(f);
fseek(f, 0, SEEK_SET);
if (SU_SYNCBUFFER_LENGTH * sizeof(float) < fsize) {
if (SU_SYNCBUFFER_LENGTH * sizeof(float) < fsize)
{
fprintf(stderr, "Sointu rendered shorter sync wave than expected\n");
goto fail;
}
if (SU_SYNCBUFFER_LENGTH * sizeof(float) > fsize) {
if (SU_SYNCBUFFER_LENGTH * sizeof(float) > fsize)
{
fprintf(stderr, "Sointu rendered longer sync wave than expected\n");
goto fail;
}
@ -133,9 +144,11 @@ int main(int argc, char* argv[]) {
max_diff = 0.0f;
for (n = 0; n < SU_SYNCBUFFER_LENGTH; n++) {
for (n = 0; n < SU_SYNCBUFFER_LENGTH; n++)
{
diff = (float)fabs(syncBuf[n] - fileSyncBuf[n]);
if (diff > 1e-3f || isnan(diff)) {
if (diff > 1e-3f || isnan(diff))
{
fprintf(stderr, "Sointu rendered different sync wave than expected\n");
goto fail;
}
@ -144,7 +157,8 @@ int main(int argc, char* argv[]) {
return 0;
fail:
if (f != NULL) {
if (f != NULL)
{
fclose(f);
f = NULL;
}

View File

@ -1,4 +1,6 @@
//go:build ignore
// +build ignore
package main
import (

View File

@ -1,4 +1,6 @@
//go:build ignore
// +build ignore
package main
import (