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

@ -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
SU_ENVELOPE_ID, // MONO
SU_OUT_ID + 1, // STEREO
SU_ADVANCE_ID };// MONO
const unsigned char values[] = { 64, 64, 64, 80, 128, // envelope 1
95, 64, 64, 80, 128, // envelope 2
128 };
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
95, 64, 64, 80, 128, // envelope 2
128};
int errcode;
int time;
int samples;
int totalrendered;
int retval;
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,13 +35,13 @@ int main(int argc, char* argv[]) {
synth->Polyphony = 0;
synth->RandSeed = 1;
// initialize Buffer
buffer = (float*)malloc(2 * sizeof(float) * su_max_samples);
// triger first voice
buffer = (float *)malloc(2 * sizeof(float) * su_max_samples);
// triger first voice
synth->SynthWrk.Voices[0].Note = 64;
synth->SynthWrk.Voices[0].Sustain = 1;
totalrendered = 0;
// First check that when we render using su_render with 0 time
// we get nothing done
// we get nothing done
samples = su_max_samples;
time = 0;
errcode = su_render(synth, buffer, &samples, &time);
@ -50,18 +51,18 @@ int main(int argc, char* argv[]) {
{
printf("su_render rendered samples, despite it should not\n");
goto fail;
}
}
if (time > 0)
{
printf("su_render advanced time, despite it should not\n");
goto fail;
}
// Then check that when we render using su_render with 0 samples,
// we get nothing done
// we get nothing done
samples = 0;
time = INT32_MAX;
errcode = su_render(synth, buffer, &samples, &time);
if (errcode != 0)
if (errcode != 0)
goto fail;
if (samples > 0)
{
@ -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;
@ -93,7 +95,7 @@ int main(int argc, char* argv[]) {
{
printf("su_render should have advanced the time also by one");
goto fail;
}
}
samples = SAMPLES_PER_ROW - 1;
time = INT32_MAX;
errcode = su_render(synth, &buffer[totalrendered * 2], &samples, &time);
@ -117,14 +119,15 @@ int main(int argc, char* argv[]) {
{
printf("su_render should have rendered a total of su_max_samples");
goto fail;
}
}
retval = 0;
finish:
free(synth);
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)