mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-17 20:44:29 -04:00
go4k
include
scripts
tests
expected_output
CMakeLists.txt
test_add.asm
test_add_stereo.asm
test_addp.asm
test_addp_stereo.asm
test_aux.asm
test_aux_stereo.asm
test_chords.asm
test_clip.asm
test_clip_stereo.asm
test_compressor.asm
test_compressor_stereo.asm
test_crush.asm
test_crush_stereo.asm
test_delay.asm
test_delay_dampmod.asm
test_delay_drymod.asm
test_delay_feedbackmod.asm
test_delay_flanger.asm
test_delay_notetracking.asm
test_delay_pregainmod.asm
test_delay_reverb.asm
test_delay_stereo.asm
test_distort.asm
test_distort_mod.asm
test_distort_stereo.asm
test_envelope.asm
test_envelope_mod.asm
test_envelope_stereo.asm
test_filter_band.asm
test_filter_freqmod.asm
test_filter_high.asm
test_filter_low.asm
test_filter_peak.asm
test_filter_resmod.asm
test_filter_stereo.asm
test_gain.asm
test_gain_stereo.asm
test_hold.asm
test_hold_mod.asm
test_hold_stereo.asm
test_in.asm
test_in_stereo.asm
test_invgain.asm
test_invgain_stereo.asm
test_loadnote.asm
test_loadnote_stereo.asm
test_loadval.asm
test_loadval_stereo.asm
test_mul.asm
test_mul_stereo.asm
test_mulp.asm
test_mulp_stereo.asm
test_multiple_instruments.asm
test_noise.asm
test_noise_stereo.asm
test_oscillat_colormod.asm
test_oscillat_detunemod.asm
test_oscillat_gainmod.asm
test_oscillat_gate.asm
test_oscillat_lfo.asm
test_oscillat_phasemod.asm
test_oscillat_pulse.asm
test_oscillat_sample.asm
test_oscillat_sample_stereo.asm
test_oscillat_shapemod.asm
test_oscillat_sine.asm
test_oscillat_stereo.asm
test_oscillat_transposemod.asm
test_oscillat_trisaw.asm
test_oscillat_unison.asm
test_oscillat_unison_stereo.asm
test_outaux.asm
test_outaux_stereo.asm
test_panning.asm
test_panning_stereo.asm
test_polyphony.asm
test_pop.asm
test_pop_stereo.asm
test_push.asm
test_push_stereo.asm
test_receive.asm
test_receive_stereo.asm
test_render_samples.c
test_render_samples_api.c
test_renderer.c
test_send.asm
test_send_global.asm
test_send_stereo.asm
test_speed.asm
test_xch.asm
test_xch_stereo.asm
.gitignore
CHANGELOG.md
CMakeLists.txt
CMakeSettings.json
LICENSE
README.md
go.mod
render.asm
130 lines
3.9 KiB
C
130 lines
3.9 KiB
C
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <sointu/sointu.h>
|
|
|
|
#define BPM 100
|
|
#define SAMPLE_RATE 44100
|
|
#define TOTAL_ROWS 16
|
|
#define SAMPLES_PER_ROW SAMPLE_RATE * 4 * 60 / (BPM * 16)
|
|
const int su_max_samples = SAMPLES_PER_ROW * TOTAL_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 errcode;
|
|
int time;
|
|
int samples;
|
|
int totalrendered;
|
|
int retval;
|
|
// initialize Synth
|
|
synth = (Synth*)malloc(sizeof(Synth));
|
|
memcpy(synth->Commands, commands, sizeof(commands));
|
|
memcpy(synth->Values, values, sizeof(values));
|
|
synth->NumVoices = 1;
|
|
synth->Polyphony = 0;
|
|
synth->RandSeed = 1;
|
|
// initialize Buffer
|
|
buffer = (float*)malloc(2 * sizeof(float) * su_max_samples);
|
|
// triger first voice
|
|
synth->SynthWrk.Voices[0].Note = 64;
|
|
totalrendered = 0;
|
|
// First check that when we render using su_render with 0 time
|
|
// we get nothing done
|
|
samples = su_max_samples;
|
|
time = 0;
|
|
errcode = su_render(synth, buffer, &samples, &time);
|
|
if (errcode != 0)
|
|
{
|
|
printf("su_render returned error");
|
|
goto fail;
|
|
}
|
|
if (samples > 0)
|
|
{
|
|
printf("su_render rendered samples, despite it should not");
|
|
goto fail;
|
|
}
|
|
if (time > 0)
|
|
{
|
|
printf("su_render advanced time, despite it should not");
|
|
goto fail;
|
|
}
|
|
// Then check that when we render using su_render with 0 samples,
|
|
// we get nothing done
|
|
samples = 0;
|
|
time = INT32_MAX;
|
|
errcode = su_render(synth, buffer, &samples, &time);
|
|
if (errcode != 0)
|
|
{
|
|
printf("su_render returned error");
|
|
goto fail;
|
|
}
|
|
if (samples > 0)
|
|
{
|
|
printf("su_render rendered samples, despite it should not");
|
|
goto fail;
|
|
}
|
|
if (time > 0)
|
|
{
|
|
printf("su_render advanced time, despite it should not");
|
|
goto fail;
|
|
}
|
|
// Then check that each time we call render, only SAMPLES_PER_ROW
|
|
// number of samples are rendered
|
|
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;
|
|
su_render(synth, &buffer[totalrendered*2], &samples, &time);
|
|
totalrendered += samples;
|
|
if (samples != 1)
|
|
{
|
|
printf("su_render should have return 1, as it should have believed buffer is full");
|
|
goto fail;
|
|
}
|
|
if (time != 1)
|
|
{
|
|
printf("su_render should have advanced the time also by one");
|
|
goto fail;
|
|
}
|
|
samples = SAMPLES_PER_ROW - 1;
|
|
time = INT32_MAX;
|
|
su_render(synth, &buffer[totalrendered * 2], &samples, &time);
|
|
totalrendered += samples;
|
|
if (samples != SAMPLES_PER_ROW - 1)
|
|
{
|
|
printf("su_render should have return SAMPLES_PER_ROW - 1, as it should have believed buffer is full");
|
|
goto fail;
|
|
}
|
|
if (time != SAMPLES_PER_ROW - 1)
|
|
{
|
|
printf("su_render should have advanced the time also by SAMPLES_PER_ROW - 1");
|
|
goto fail;
|
|
}
|
|
if (i == 8)
|
|
synth->SynthWrk.Voices[0].Release++;
|
|
}
|
|
if (totalrendered != su_max_samples)
|
|
{
|
|
printf("su_render should have rendered a total of su_max_samples");
|
|
goto fail;
|
|
}
|
|
retval = 0;
|
|
finish:
|
|
free(synth);
|
|
free(buffer);
|
|
return retval;
|
|
fail:
|
|
retval = 1;
|
|
goto finish;
|
|
}
|