mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
code/text formatting and cleaning up whitespace
This commit is contained in:
parent
f35f948118
commit
00850c8001
@ -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`.
|
||||
|
||||
|
@ -4,20 +4,21 @@
|
||||
#include <sointu.h>
|
||||
#include "test_render_samples.h"
|
||||
|
||||
void SU_CALLCONV su_render_song(float* buffer) {
|
||||
Synth* synth;
|
||||
const unsigned char commands[] = { SU_ENVELOPE_ID, // MONO
|
||||
void SU_CALLCONV su_render_song(float *buffer)
|
||||
{
|
||||
Synth *synth;
|
||||
const unsigned char commands[] = {SU_ENVELOPE_ID, // MONO
|
||||
SU_ENVELOPE_ID, // MONO
|
||||
SU_OUT_ID + 1, // STEREO
|
||||
SU_ADVANCE_ID };// MONO
|
||||
const unsigned char values[] = { 64, 64, 64, 80, 128, // envelope 1
|
||||
SU_ADVANCE_ID}; // MONO
|
||||
const unsigned char values[] = {64, 64, 64, 80, 128, // envelope 1
|
||||
95, 64, 64, 80, 128, // envelope 2
|
||||
128};
|
||||
int retval;
|
||||
int samples;
|
||||
int time;
|
||||
// initialize Synth
|
||||
synth = (Synth*)malloc(sizeof(Synth));
|
||||
synth = (Synth *)malloc(sizeof(Synth));
|
||||
memset(synth, 0, sizeof(Synth));
|
||||
memcpy(synth->Commands, commands, sizeof(commands));
|
||||
memcpy(synth->Values, values, sizeof(values));
|
||||
|
@ -10,23 +10,24 @@
|
||||
#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[]) {
|
||||
Synth* synth;
|
||||
float* buffer;
|
||||
const unsigned char commands[] = { SU_ENVELOPE_ID, // MONO
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Synth *synth;
|
||||
float *buffer;
|
||||
const unsigned char commands[] = {SU_ENVELOPE_ID, // MONO
|
||||
SU_ENVELOPE_ID, // MONO
|
||||
SU_OUT_ID + 1, // STEREO
|
||||
SU_ADVANCE_ID };// MONO
|
||||
const unsigned char values[] = { 64, 64, 64, 80, 128, // envelope 1
|
||||
SU_ADVANCE_ID}; // MONO
|
||||
const unsigned char values[] = {64, 64, 64, 80, 128, // envelope 1
|
||||
95, 64, 64, 80, 128, // envelope 2
|
||||
128 };
|
||||
128};
|
||||
int errcode;
|
||||
int time;
|
||||
int samples;
|
||||
int totalrendered;
|
||||
int retval;
|
||||
// initialize Synth
|
||||
synth = (Synth*)malloc(sizeof(Synth));
|
||||
synth = (Synth *)malloc(sizeof(Synth));
|
||||
memset(synth, 0, sizeof(Synth));
|
||||
memcpy(synth->Commands, commands, sizeof(commands));
|
||||
memcpy(synth->Values, values, sizeof(values));
|
||||
@ -34,7 +35,7 @@ int main(int argc, char* argv[]) {
|
||||
synth->Polyphony = 0;
|
||||
synth->RandSeed = 1;
|
||||
// initialize Buffer
|
||||
buffer = (float*)malloc(2 * sizeof(float) * su_max_samples);
|
||||
buffer = (float *)malloc(2 * sizeof(float) * su_max_samples);
|
||||
// triger first voice
|
||||
synth->SynthWrk.Voices[0].Note = 64;
|
||||
synth->SynthWrk.Voices[0].Sustain = 1;
|
||||
@ -75,12 +76,13 @@ 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;
|
||||
time = INT32_MAX;
|
||||
errcode = su_render(synth, &buffer[totalrendered*2], &samples, &time);
|
||||
errcode = su_render(synth, &buffer[totalrendered * 2], &samples, &time);
|
||||
if (errcode != 0)
|
||||
goto fail;
|
||||
totalrendered += samples;
|
||||
@ -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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
#if defined (_WIN32)
|
||||
#if defined(_WIN32)
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#include <windows.h>
|
||||
#else
|
||||
@ -21,9 +21,9 @@ float syncBuf[SU_SYNCBUFFER_LENGTH];
|
||||
float fileSyncBuf[SU_BUFFER_LENGTH];
|
||||
#endif
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
FILE* f;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *f;
|
||||
char filename[256];
|
||||
int n;
|
||||
char test_name[] = TEST_NAME;
|
||||
@ -33,18 +33,19 @@ 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;
|
||||
}
|
||||
|
||||
#ifdef SU_LOAD_GMDLS
|
||||
#ifdef SU_LOAD_GMDLS
|
||||
su_load_gmdls();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
su_render_song(buf);
|
||||
|
||||
#if defined (_WIN32)
|
||||
#if defined(_WIN32)
|
||||
CreateDirectory(actual_output_folder, NULL);
|
||||
#else
|
||||
mkdir(actual_output_folder, 0777);
|
||||
@ -52,19 +53,20 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
snprintf(filename, sizeof filename, "%s%s%s", actual_output_folder, test_name, ".raw");
|
||||
f = fopen(filename, "wb");
|
||||
fwrite((void*)buf, sizeof(SUsample), SU_BUFFER_LENGTH, f);
|
||||
fwrite((void *)buf, sizeof(SUsample), SU_BUFFER_LENGTH, f);
|
||||
fclose(f);
|
||||
|
||||
#ifdef SU_SYNC
|
||||
#ifdef SU_SYNC
|
||||
snprintf(filename, sizeof filename, "%s%s%s", actual_output_folder, test_name, "_syncbuf.raw");
|
||||
f = fopen(filename, "wb");
|
||||
fwrite((void*)syncBuf, sizeof(float), SU_SYNCBUFFER_LENGTH, f);
|
||||
fwrite((void *)syncBuf, sizeof(float), SU_SYNCBUFFER_LENGTH, f);
|
||||
fclose(f);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
f = fopen(argv[1], "rb");
|
||||
|
||||
if (f == NULL) {
|
||||
if (f == NULL)
|
||||
{
|
||||
fprintf(stderr, "No expected waveform found!\n");
|
||||
goto fail;
|
||||
}
|
||||
@ -73,42 +75,49 @@ 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;
|
||||
}
|
||||
|
||||
fread((void*)filebuf, fsize, 1, f);
|
||||
fread((void *)filebuf, fsize, 1, f);
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
|
||||
max_diff = 0.0f;
|
||||
|
||||
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)) {
|
||||
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))
|
||||
{
|
||||
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) {
|
||||
fprintf(stderr, "Warning: Sointu rendered almost correct wave, but a small maximum error of %f\n",max_diff);
|
||||
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,25 +126,29 @@ 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;
|
||||
}
|
||||
|
||||
fread((void*)fileSyncBuf, fsize, 1, f);
|
||||
fread((void *)fileSyncBuf, fsize, 1, f);
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -1,4 +1,6 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
Loading…
Reference in New Issue
Block a user