mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
Change the C-API to roughly match the new Go-API.
The parameter order is now so that all the in/out int parameters are in the end of the signature.
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
#define SAMPLES_PER_ROW SAMPLE_RATE * 4 * 60 / (BPM * 16)
|
||||
const int su_max_samples = SAMPLES_PER_ROW * TOTAL_ROWS;
|
||||
|
||||
void CALLCONV su_render(float* buffer) {
|
||||
void CALLCONV su_render_song(float* buffer) {
|
||||
SynthState* synthState;
|
||||
const unsigned char commands[] = { su_envelope_id, // MONO
|
||||
su_envelope_id, // MONO
|
||||
@ -33,14 +33,13 @@ void CALLCONV su_render(float* buffer) {
|
||||
memset(synthState, 0, sizeof(SynthState));
|
||||
memcpy(synthState->Commands, commands, sizeof(commands));
|
||||
memcpy(synthState->Values, values, sizeof(values));
|
||||
synthState->RandSeed = 1;
|
||||
synthState->SamplesPerRow = INT32_MAX;
|
||||
synthState->RandSeed = 1;
|
||||
synthState->NumVoices = 1;
|
||||
synthState->Synth.Voices[0].Note = 64;
|
||||
retval = su_render_samples(synthState, su_max_samples / 2, buffer);
|
||||
retval = su_render(synthState, buffer, su_max_samples / 2);
|
||||
synthState->Synth.Voices[0].Release++;
|
||||
buffer = buffer + su_max_samples;
|
||||
retval = su_render_samples(synthState, su_max_samples / 2, buffer);
|
||||
retval = su_render(synthState, buffer, su_max_samples / 2);
|
||||
free(synthState);
|
||||
return;
|
||||
}
|
||||
|
@ -19,8 +19,11 @@ int main(int argc, char* argv[]) {
|
||||
su_advance_id };// MONO
|
||||
const unsigned char values[] = { 64, 64, 64, 80, 128, // envelope 1
|
||||
95, 64, 64, 80, 128, // envelope 2
|
||||
128 };
|
||||
int remaining, remainingOut;
|
||||
128 };
|
||||
int errcode;
|
||||
int time;
|
||||
int samples;
|
||||
int totalrendered;
|
||||
int retval;
|
||||
synthState = (SynthState*)malloc(sizeof(SynthState));
|
||||
buffer = (float*)malloc(2 * sizeof(float) * su_max_samples);
|
||||
@ -29,58 +32,89 @@ int main(int argc, char* argv[]) {
|
||||
memcpy(synthState->Values, values, sizeof(values));
|
||||
synthState->RandSeed = 1;
|
||||
synthState->NumVoices = 1;
|
||||
synthState->Synth.Voices[0].Note = 64;
|
||||
remaining = su_max_samples;
|
||||
// First check that when RowLen = 0, we render nothing and remaining does not change
|
||||
synthState->SamplesPerRow = 0;
|
||||
if (su_render_samples(synthState, remaining, buffer) != remaining)
|
||||
synthState->Synth.Voices[0].Note = 64;
|
||||
totalrendered = 0;
|
||||
// First check that when we render using su_render_time with 0 time
|
||||
// we get nothing done
|
||||
samples = su_max_samples;
|
||||
time = 0;
|
||||
errcode = su_render_time(synthState, buffer, &samples, &time);
|
||||
if (errcode != 0)
|
||||
{
|
||||
printf("su_render_samples rendered samples despite number of samples per row being 0");
|
||||
printf("su_render_time returned error");
|
||||
goto fail;
|
||||
}
|
||||
if (samples > 0)
|
||||
{
|
||||
printf("su_render_time rendered samples, despite it should not");
|
||||
goto fail;
|
||||
}
|
||||
if (time > 0)
|
||||
{
|
||||
printf("su_render_time advanced time, despite it should not");
|
||||
goto fail;
|
||||
}
|
||||
// Then check that when we render using su_render_time with 0 samples,
|
||||
// we get nothing done
|
||||
samples = 0;
|
||||
time = INT32_MAX;
|
||||
errcode = su_render_time(synthState, buffer, &samples, &time);
|
||||
if (errcode != 0)
|
||||
{
|
||||
printf("su_render_time returned error");
|
||||
goto fail;
|
||||
}
|
||||
if (samples > 0)
|
||||
{
|
||||
printf("su_render_time rendered samples, despite it should not");
|
||||
goto fail;
|
||||
}
|
||||
if (time > 0)
|
||||
{
|
||||
printf("su_render_time 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
|
||||
synthState->SamplesPerRow = SAMPLES_PER_ROW;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
// Simulate "small buffers" i.e. render a buffer with 1 sample
|
||||
// check that buffer full
|
||||
remainingOut = su_render_samples(synthState, 1, &buffer[2 * (su_max_samples - remaining)]);
|
||||
if (remainingOut != -1)
|
||||
samples = 1;
|
||||
time = INT32_MAX;
|
||||
su_render_time(synthState, &buffer[totalrendered*2], &samples, &time);
|
||||
totalrendered += samples;
|
||||
if (samples != 1)
|
||||
{
|
||||
printf("su_render_samples should have return -1, as it should have believed buffer is full");
|
||||
printf("su_render should have return 1, as it should have believed buffer is full");
|
||||
goto fail;
|
||||
}
|
||||
if (synthState->RowTick != 1)
|
||||
if (time != 1)
|
||||
{
|
||||
printf("su_render_samples RowTick should be at 1 after rendering 1 tick of a row");
|
||||
printf("su_render should have advanced the time also by one");
|
||||
goto fail;
|
||||
}
|
||||
samples = SAMPLES_PER_ROW - 1;
|
||||
time = INT32_MAX;
|
||||
su_render_time(synthState, &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;
|
||||
}
|
||||
remaining--; // we rendered just one sample
|
||||
remainingOut = su_render_samples(synthState, remaining, &buffer[2 * (su_max_samples - remaining)]);
|
||||
if (remainingOut != remaining - SAMPLES_PER_ROW + 1)
|
||||
if (time != SAMPLES_PER_ROW - 1)
|
||||
{
|
||||
printf("su_render_samples did not render SAMPLES_PER_ROW, despite rowLen being SAMPLES_PER_ROW");
|
||||
printf("su_render should have advanced the time also by SAMPLES_PER_ROW - 1");
|
||||
goto fail;
|
||||
}
|
||||
if (synthState->RowTick != 0)
|
||||
{
|
||||
printf("The row should be have been reseted");
|
||||
goto fail;
|
||||
}
|
||||
remaining = remainingOut;
|
||||
if (i == 8)
|
||||
synthState->Synth.Voices[0].Release++;
|
||||
synthState->Synth.Voices[0].Release++;
|
||||
}
|
||||
if (remaining != 0) {
|
||||
printf("The buffer should be full and row finished");
|
||||
goto fail;
|
||||
}
|
||||
// Finally, now that there is no more buffer remaining, should return -1
|
||||
if (su_render_samples(synthState, remaining, &buffer[2 * (su_max_samples - remaining)]) != -1)
|
||||
if (totalrendered != su_max_samples)
|
||||
{
|
||||
printf("su_render_samples should have ran out of buffer and thus return -1");
|
||||
printf("su_render should have rendered a total of su_max_samples");
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
finish:
|
||||
free(synthState);
|
||||
|
@ -24,7 +24,7 @@
|
||||
#else // 64-bit
|
||||
#define CALLCONV // the asm will use honor honor correct x64 ABI on all 64-bit platforms
|
||||
#endif
|
||||
extern void CALLCONV su_render(void *);
|
||||
extern void CALLCONV su_render_song(void *);
|
||||
|
||||
#ifdef INCLUDE_GMDLS
|
||||
extern void CALLCONV su_load_gmdls(void);
|
||||
@ -67,7 +67,7 @@ int main(int argc, char* argv[]) {
|
||||
su_load_gmdls();
|
||||
#endif
|
||||
|
||||
su_render(buf);
|
||||
su_render_song(buf);
|
||||
|
||||
snprintf(filename, sizeof filename, "%s%s%s", expected_output_folder, test_name, ".raw");
|
||||
|
||||
@ -117,7 +117,10 @@ int main(int argc, char* argv[]) {
|
||||
printf("4klang rendered different wave than expected\n");
|
||||
goto fail;
|
||||
}
|
||||
max_diff = fmax(diff, max_diff);
|
||||
|
||||
if (diff > max_diff) {
|
||||
max_diff = diff;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_diff > 1e-6) {
|
||||
|
Reference in New Issue
Block a user