From 7738bb46d4a5ee0fede6ab112e55b4d5f04d5b59 Mon Sep 17 00:00:00 2001 From: rsp4jack Date: Sat, 19 Oct 2024 12:34:08 +0800 Subject: [PATCH 1/8] Add chorus, reverb dry and master gain for sonivoxrender --- example/sonivoxrender.c | 88 +++++++++++++++++++++++++++++++++++------ 1 file changed, 75 insertions(+), 13 deletions(-) diff --git a/example/sonivoxrender.c b/example/sonivoxrender.c index a4ee425f..6cbb092b 100644 --- a/example/sonivoxrender.c +++ b/example/sonivoxrender.c @@ -24,10 +24,14 @@ #include #include +#include const char *dls_path = NULL; -EAS_I32 reverb_type = -1; -EAS_I32 reverb_wet = 0; +EAS_I32 playback_gain = 90; +EAS_I32 reverb_type = 0; +EAS_I32 reverb_wet = 32767; +EAS_I32 reverb_dry = 0; +EAS_I32 chorus_type = 0; EAS_DATA_HANDLE mEASDataHandle = NULL; int Read(void *handle, void *buf, int offset, int size) { @@ -101,11 +105,18 @@ int initializeLibrary(void) } } - EAS_BOOL sw = EAS_TRUE; - EAS_I32 preset = reverb_type - 1; - if ( preset >= EAS_PARAM_REVERB_LARGE_HALL && preset <= EAS_PARAM_REVERB_ROOM ) { - sw = EAS_FALSE; - result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_REVERB, EAS_PARAM_REVERB_PRESET, preset); + result = EAS_SetVolume(mEASDataHandle, NULL, playback_gain); + if (result != EAS_SUCCESS) { + fprintf(stderr, "Failed to set volume\n"); + ok = EXIT_FAILURE; + goto cleanup; + } + + EAS_BOOL reverb_bypass = EAS_TRUE; + EAS_I32 reverb_preset = reverb_type - 1; + if ( reverb_preset >= EAS_PARAM_REVERB_LARGE_HALL && reverb_preset <= EAS_PARAM_REVERB_ROOM ) { + reverb_bypass = EAS_FALSE; + result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_REVERB, EAS_PARAM_REVERB_PRESET, reverb_preset); if (result != EAS_SUCCESS) { fprintf(stderr, "Failed to set reverb preset"); ok = EXIT_FAILURE; @@ -120,14 +131,40 @@ int initializeLibrary(void) ok = EXIT_FAILURE; goto cleanup; } + + result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_REVERB, EAS_PARAM_REVERB_DRY, reverb_dry); + if (result != EAS_SUCCESS) { + fprintf(stderr, "Failed to set reverb dry amount"); + ok = EXIT_FAILURE; + goto cleanup; + } } - result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_REVERB, EAS_PARAM_REVERB_BYPASS, sw); + result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_REVERB, EAS_PARAM_REVERB_BYPASS, reverb_bypass); if (result != EAS_SUCCESS) { fprintf(stderr, "Failed to set reverb bypass"); ok = EXIT_FAILURE; goto cleanup; } + EAS_BOOL chorus_bypass = EAS_TRUE; + EAS_I32 chorus_preset = chorus_type - 1; + if ( chorus_preset >= EAS_PARAM_CHORUS_PRESET1 && chorus_preset <= EAS_PARAM_CHORUS_PRESET4 ) { + chorus_bypass = EAS_FALSE; + result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_CHORUS, EAS_PARAM_CHORUS_PRESET, chorus_preset); + if (result != EAS_SUCCESS) { + fprintf(stderr, "Failed to set chorus preset"); + ok = EXIT_FAILURE; + goto cleanup; + } + } + + result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_CHORUS, EAS_PARAM_CHORUS_BYPASS, chorus_bypass); + if (result != EAS_SUCCESS) { + fprintf(stderr, "Failed to set chorus bypass"); + ok = EXIT_FAILURE; + goto cleanup; + } + return ok; cleanup: @@ -259,17 +296,21 @@ int main (int argc, char **argv) opterr = 0; - while ((c = getopt (argc, argv, "hd:r:w:")) != -1) { + while ((c = getopt (argc, argv, "hd:r:w:n:c:v:")) != -1) { switch (c) { case 'h': - fprintf (stderr, "Usage: %s [-h] [-d file.dls] [-r 0..4] [-w 0..32765] file.mid ...\n"\ + fprintf (stderr, "Usage: %s [-h] [-d file.dls] [-r 0..4] [-w 0..32767] [-n 0..32767] [-c 0..4] [-v 0..100] file.mid ...\n"\ "Render standard MIDI files into raw PCM audio.\n"\ "Options:\n"\ "\t-h\t\tthis help message.\n"\ "\t-d file.dls\tDLS soundfont.\n"\ "\t-r n\t\treverb preset: 0=no, 1=large hall, 2=hall, 3=chamber, 4=room.\n"\ - "\t-w n\t\treverb wet: 0..32765.\n", argv[0]); + "\t-w n\t\treverb wet: 0..32767.\n" + "\t-n n\t\treverb dry: 0..32767.\n" + "\t-c n\t\tchorus preset: 0=no, 1..4=presents.\n" + "\t-v n\t\tmaster volume: 0..100.\n" + , argv[0]); return EXIT_FAILURE; case 'd': dls_path = optarg; @@ -283,8 +324,29 @@ int main (int argc, char **argv) break; case 'w': reverb_wet = atoi(optarg); - if (reverb_wet < 0 || reverb_wet > 32765) { - fprintf (stderr, "invalid reverb amount: %ld\n", reverb_wet); + if (reverb_wet < 0 || reverb_wet > 32767) { + fprintf (stderr, "invalid reverb wet: %ld\n", reverb_wet); + return EXIT_FAILURE; + } + break; + case 'n': + reverb_dry = atoi(optarg); + if (reverb_dry < 0 || reverb_dry > 32767) { + fprintf (stderr, "invalid reverb dry: %ld\n", reverb_dry); + return EXIT_FAILURE; + } + break; + case 'c': + chorus_type = atoi(optarg); + if (chorus_type < 0 || chorus_type > 4) { + fprintf (stderr, "invalid chorus preset: %ld\n", chorus_type); + return EXIT_FAILURE; + } + break; + case 'v': + playback_gain = atoi(optarg); + if (playback_gain < 0 || playback_gain > 100) { + fprintf (stderr, "invalid playback gain: %ld\n", playback_gain); return EXIT_FAILURE; } break; From 06d53c45a46c5ac3dae5fef7d35e0e7ec9c4ee26 Mon Sep 17 00:00:00 2001 From: rsp4jack Date: Sat, 19 Oct 2024 15:11:04 +0800 Subject: [PATCH 2/8] Update sonivoxrender.1.md for 027255b --- example/sonivoxrender.1.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/example/sonivoxrender.1.md b/example/sonivoxrender.1.md index c0c380bb..0658f2a6 100644 --- a/example/sonivoxrender.1.md +++ b/example/sonivoxrender.1.md @@ -7,7 +7,7 @@ # SYNOPSIS -| **sonivoxrender** [**-h**] [**-d** _file.dls_] [**-r** _0..4_] [**-w** _0..32765_] _midi_file_ +| **sonivoxrender** [**-h**] [**-d** _file.dls_] [**-r** _0..4_] [**-w** _0..32767_] [**-n** _0..32767_] [**-c** _0..4_] [**-v** _0..100_] _midi_file_ # DESCRIPTION @@ -30,7 +30,19 @@ It reads .MID (Standard MIDI Files) file format, and writes an audio stream to t -w _reverb_wet_ -: Reverb wet level between 0 and 32765. +: Reverb wet level between 0 and 32767. + +-n _reverb_dry_ + +: Reverb dry level between 0 and 32767. + +-c _chorus_preset_ + +: Chorus preset between 0 and 4: 0=no, 1..4=presents. + +-v _master_volume_ + +: Master volume between 0 and 100, default to 90. ## Arguments From b4683db192b520db55f86b3131eae824b82fb1ef Mon Sep 17 00:00:00 2001 From: rsp4jack Date: Sat, 19 Oct 2024 16:29:40 +0800 Subject: [PATCH 3/8] Delete example/sonivoxrender.1 --- example/sonivoxrender.1 | 105 ---------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 example/sonivoxrender.1 diff --git a/example/sonivoxrender.1 b/example/sonivoxrender.1 deleted file mode 100644 index 4d8e7e0b..00000000 --- a/example/sonivoxrender.1 +++ /dev/null @@ -1,105 +0,0 @@ -.\" Automatically generated by Pandoc 2.14.0.3 -.\" -.TH "SONIVOXRENDER" "1" "October 6, 2024" "sonivox 3.6.14.0" "Sonivox MIDI File Renderer" -.hy -.SH NAME -.PP -\f[B]sonivoxrender\f[R] \[em] Render standard MIDI files into raw PCM -audio -.SH SYNOPSIS -.PP -\f[B]sonivoxrender\f[R] [\f[B]-h\f[R]] [\f[B]-d\f[R] \f[I]file.dls\f[R]] -[\f[B]-r\f[R] \f[I]0..4\f[R]] [\f[B]-w\f[R] \f[I]0..32765\f[R]] -\f[I]midi_file\f[R] -.SH DESCRIPTION -.PP -This program is a MIDI file renderer based on the sonivox synthesizer -library. -It reads .MID (Standard MIDI Files) file format, and writes an audio -stream to the standard output as raw 16 bit stereo PCM samples. -.SS Options -.TP --h -Prints brief usage information. -.TP --d \f[I]file.dls\f[R] -Optional DLS soundfont file name. -If not provided, it uses an internal embedded soundfont. -.TP --r \f[I]reverb_preset\f[R] -Reverb preset between 0 and 4: 0=no, 1=large hall, 2=hall, 3=chamber, -4=room. -.TP --w \f[I]reverb_wet\f[R] -Reverb wet level between 0 and 32765. -.SS Arguments -.TP -\f[I]midi_file\f[R] -Input MID file name. -.SH EXAMPLES -.PP -The following examples assume the default option USE_44KHZ=ON, which -means an output sample rate = 44100 Hz. -.PP -Example 1: Render a MIDI file and save the rendered audio as a raw audio -file: -.IP -.nf -\f[C] -$ sonivoxrender ants.mid > ants.pcm -\f[R] -.fi -.PP -Example 2: pipe the rendered audio thru the Linux ALSA \f[B]aplay\f[R] -utility: -.IP -.nf -\f[C] -$ sonivoxrender ants.mid | aplay -c 2 -f S16_LE -r 44100 -\f[R] -.fi -.PP -is equivalent to: -.IP -.nf -\f[C] -$ sonivoxrender ants.mid | aplay -f cd -\f[R] -.fi -.PP -Example 3: pipe the rendered audio thru the \f[B]lame\f[R] utility -creating a MP3 file: -.IP -.nf -\f[C] -$ sonivoxrender ants.mid | lame -r -s 44100 - ants.mp3 -\f[R] -.fi -.PP -Example 4: pipe the rendered audio thru the \f[B]sox\f[R] utility -creating a WAV file: -.IP -.nf -\f[C] -$ sonivoxrender ants.mid | sox -t s16 -c 2 -r 44100 - ants.wav -\f[R] -.fi -.PP -Example 5: pipe the rendered audio thru the PulseAudio\[cq]s -\f[B]pacat\f[R] utility: -.IP -.nf -\f[C] -$ sonivoxrender ants.mid | pacat -\f[R] -.fi -.SH BUGS -.PP -See Tickets at GitHub -.SH LICENSE AND COPYRIGHT -.PP -Licensed under the Apache License, Version 2.0 -.PP -Copyright (c) 2022-2024 Pedro L\['o]pez-Cabanillas and contributors -.SH AUTHORS -Pedro L\['o]pez-Cabanillas . From e495333f604c0a09fe25a510823fb3020d0996a0 Mon Sep 17 00:00:00 2001 From: rsp4jack Date: Sat, 19 Oct 2024 17:14:27 +0800 Subject: [PATCH 4/8] Revert "Delete example/sonivoxrender.1" This reverts commit ea38ba3a245923162a615fe5a4cadf7208be6f52. --- example/sonivoxrender.1 | 105 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 example/sonivoxrender.1 diff --git a/example/sonivoxrender.1 b/example/sonivoxrender.1 new file mode 100644 index 00000000..4d8e7e0b --- /dev/null +++ b/example/sonivoxrender.1 @@ -0,0 +1,105 @@ +.\" Automatically generated by Pandoc 2.14.0.3 +.\" +.TH "SONIVOXRENDER" "1" "October 6, 2024" "sonivox 3.6.14.0" "Sonivox MIDI File Renderer" +.hy +.SH NAME +.PP +\f[B]sonivoxrender\f[R] \[em] Render standard MIDI files into raw PCM +audio +.SH SYNOPSIS +.PP +\f[B]sonivoxrender\f[R] [\f[B]-h\f[R]] [\f[B]-d\f[R] \f[I]file.dls\f[R]] +[\f[B]-r\f[R] \f[I]0..4\f[R]] [\f[B]-w\f[R] \f[I]0..32765\f[R]] +\f[I]midi_file\f[R] +.SH DESCRIPTION +.PP +This program is a MIDI file renderer based on the sonivox synthesizer +library. +It reads .MID (Standard MIDI Files) file format, and writes an audio +stream to the standard output as raw 16 bit stereo PCM samples. +.SS Options +.TP +-h +Prints brief usage information. +.TP +-d \f[I]file.dls\f[R] +Optional DLS soundfont file name. +If not provided, it uses an internal embedded soundfont. +.TP +-r \f[I]reverb_preset\f[R] +Reverb preset between 0 and 4: 0=no, 1=large hall, 2=hall, 3=chamber, +4=room. +.TP +-w \f[I]reverb_wet\f[R] +Reverb wet level between 0 and 32765. +.SS Arguments +.TP +\f[I]midi_file\f[R] +Input MID file name. +.SH EXAMPLES +.PP +The following examples assume the default option USE_44KHZ=ON, which +means an output sample rate = 44100 Hz. +.PP +Example 1: Render a MIDI file and save the rendered audio as a raw audio +file: +.IP +.nf +\f[C] +$ sonivoxrender ants.mid > ants.pcm +\f[R] +.fi +.PP +Example 2: pipe the rendered audio thru the Linux ALSA \f[B]aplay\f[R] +utility: +.IP +.nf +\f[C] +$ sonivoxrender ants.mid | aplay -c 2 -f S16_LE -r 44100 +\f[R] +.fi +.PP +is equivalent to: +.IP +.nf +\f[C] +$ sonivoxrender ants.mid | aplay -f cd +\f[R] +.fi +.PP +Example 3: pipe the rendered audio thru the \f[B]lame\f[R] utility +creating a MP3 file: +.IP +.nf +\f[C] +$ sonivoxrender ants.mid | lame -r -s 44100 - ants.mp3 +\f[R] +.fi +.PP +Example 4: pipe the rendered audio thru the \f[B]sox\f[R] utility +creating a WAV file: +.IP +.nf +\f[C] +$ sonivoxrender ants.mid | sox -t s16 -c 2 -r 44100 - ants.wav +\f[R] +.fi +.PP +Example 5: pipe the rendered audio thru the PulseAudio\[cq]s +\f[B]pacat\f[R] utility: +.IP +.nf +\f[C] +$ sonivoxrender ants.mid | pacat +\f[R] +.fi +.SH BUGS +.PP +See Tickets at GitHub +.SH LICENSE AND COPYRIGHT +.PP +Licensed under the Apache License, Version 2.0 +.PP +Copyright (c) 2022-2024 Pedro L\['o]pez-Cabanillas and contributors +.SH AUTHORS +Pedro L\['o]pez-Cabanillas . From 33d8286a4c52a29c0a79394a00093899546b4313 Mon Sep 17 00:00:00 2001 From: rsp4jack Date: Sat, 19 Oct 2024 17:16:43 +0800 Subject: [PATCH 5/8] Update sonivoxrender.1 --- example/sonivoxrender.1 | 88 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/example/sonivoxrender.1 b/example/sonivoxrender.1 index 4d8e7e0b..84d8b494 100644 --- a/example/sonivoxrender.1 +++ b/example/sonivoxrender.1 @@ -1,105 +1,101 @@ -.\" Automatically generated by Pandoc 2.14.0.3 +.\" Automatically generated by Pandoc 3.1.11 .\" .TH "SONIVOXRENDER" "1" "October 6, 2024" "sonivox 3.6.14.0" "Sonivox MIDI File Renderer" -.hy .SH NAME -.PP \f[B]sonivoxrender\f[R] \[em] Render standard MIDI files into raw PCM audio .SH SYNOPSIS .PP -\f[B]sonivoxrender\f[R] [\f[B]-h\f[R]] [\f[B]-d\f[R] \f[I]file.dls\f[R]] -[\f[B]-r\f[R] \f[I]0..4\f[R]] [\f[B]-w\f[R] \f[I]0..32765\f[R]] -\f[I]midi_file\f[R] +\f[B]sonivoxrender\f[R] [\f[B]\-h\f[R]] [\f[B]\-d\f[R] +\f[I]file.dls\f[R]] [\f[B]\-r\f[R] \f[I]0..4\f[R]] [\f[B]\-w\f[R] +\f[I]0..32767\f[R]] [\f[B]\-n\f[R] \f[I]0..32767\f[R]] [\f[B]\-c\f[R] +\f[I]0..4\f[R]] [\f[B]\-v\f[R] \f[I]0..100\f[R]] \f[I]midi_file\f[R] .SH DESCRIPTION -.PP This program is a MIDI file renderer based on the sonivox synthesizer library. It reads .MID (Standard MIDI Files) file format, and writes an audio stream to the standard output as raw 16 bit stereo PCM samples. .SS Options .TP --h +\-h Prints brief usage information. .TP --d \f[I]file.dls\f[R] +\-d \f[I]file.dls\f[R] Optional DLS soundfont file name. If not provided, it uses an internal embedded soundfont. .TP --r \f[I]reverb_preset\f[R] +\-r \f[I]reverb_preset\f[R] Reverb preset between 0 and 4: 0=no, 1=large hall, 2=hall, 3=chamber, 4=room. .TP --w \f[I]reverb_wet\f[R] -Reverb wet level between 0 and 32765. +\-w \f[I]reverb_wet\f[R] +Reverb wet level between 0 and 32767. +.TP +\-n \f[I]reverb_dry\f[R] +Reverb dry level between 0 and 32767. +.TP +\-c \f[I]chorus_preset\f[R] +Chorus preset between 0 and 4: 0=no, 1..4=presents. +.TP +\-v \f[I]master_volume\f[R] +Master volume between 0 and 100, default to 90. .SS Arguments .TP \f[I]midi_file\f[R] Input MID file name. .SH EXAMPLES -.PP The following examples assume the default option USE_44KHZ=ON, which means an output sample rate = 44100 Hz. .PP Example 1: Render a MIDI file and save the rendered audio as a raw audio file: .IP -.nf -\f[C] +.EX $ sonivoxrender ants.mid > ants.pcm -\f[R] -.fi +.EE .PP Example 2: pipe the rendered audio thru the Linux ALSA \f[B]aplay\f[R] utility: .IP -.nf -\f[C] -$ sonivoxrender ants.mid | aplay -c 2 -f S16_LE -r 44100 -\f[R] -.fi +.EX +$ sonivoxrender ants.mid | aplay \-c 2 \-f S16_LE \-r 44100 +.EE .PP is equivalent to: .IP -.nf -\f[C] -$ sonivoxrender ants.mid | aplay -f cd -\f[R] -.fi +.EX +$ sonivoxrender ants.mid | aplay \-f cd +.EE .PP Example 3: pipe the rendered audio thru the \f[B]lame\f[R] utility creating a MP3 file: .IP -.nf -\f[C] -$ sonivoxrender ants.mid | lame -r -s 44100 - ants.mp3 -\f[R] -.fi +.EX +$ sonivoxrender ants.mid | lame \-r \-s 44100 \- ants.mp3 +.EE .PP Example 4: pipe the rendered audio thru the \f[B]sox\f[R] utility creating a WAV file: .IP -.nf -\f[C] -$ sonivoxrender ants.mid | sox -t s16 -c 2 -r 44100 - ants.wav -\f[R] -.fi +.EX +$ sonivoxrender ants.mid | sox \-t s16 \-c 2 \-r 44100 \- ants.wav +.EE .PP Example 5: pipe the rendered audio thru the PulseAudio\[cq]s \f[B]pacat\f[R] utility: .IP -.nf -\f[C] +.EX $ sonivoxrender ants.mid | pacat -\f[R] -.fi +.EE .SH BUGS -.PP -See Tickets at GitHub +See Tickets at GitHub \c +.UR https://github.com/pedrolcl/sonivox/issues/ +.UE \c .SH LICENSE AND COPYRIGHT -.PP Licensed under the Apache License, Version 2.0 .PP -Copyright (c) 2022-2024 Pedro L\['o]pez-Cabanillas and contributors +Copyright (c) 2022\-2024 Pedro López\-Cabanillas and contributors .SH AUTHORS -Pedro L\['o]pez-Cabanillas . +Pedro López\-Cabanillas \c +.MT plcl@users.sf.net +.ME \c. From 85f9dbf7d517047240697340d92f14afede2112e Mon Sep 17 00:00:00 2001 From: rsp4jack Date: Sat, 19 Oct 2024 17:34:43 +0800 Subject: [PATCH 6/8] Fix typo in sonivoxrender --- example/sonivoxrender.1 | 2 +- example/sonivoxrender.1.md | 2 +- example/sonivoxrender.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/sonivoxrender.1 b/example/sonivoxrender.1 index 84d8b494..a5d4ad87 100644 --- a/example/sonivoxrender.1 +++ b/example/sonivoxrender.1 @@ -35,7 +35,7 @@ Reverb wet level between 0 and 32767. Reverb dry level between 0 and 32767. .TP \-c \f[I]chorus_preset\f[R] -Chorus preset between 0 and 4: 0=no, 1..4=presents. +Chorus preset between 0 and 4: 0=no, 1..4=presets. .TP \-v \f[I]master_volume\f[R] Master volume between 0 and 100, default to 90. diff --git a/example/sonivoxrender.1.md b/example/sonivoxrender.1.md index 0658f2a6..9c0459b0 100644 --- a/example/sonivoxrender.1.md +++ b/example/sonivoxrender.1.md @@ -38,7 +38,7 @@ It reads .MID (Standard MIDI Files) file format, and writes an audio stream to t -c _chorus_preset_ -: Chorus preset between 0 and 4: 0=no, 1..4=presents. +: Chorus preset between 0 and 4: 0=no, 1..4=presets. -v _master_volume_ diff --git a/example/sonivoxrender.c b/example/sonivoxrender.c index 6cbb092b..692df48a 100644 --- a/example/sonivoxrender.c +++ b/example/sonivoxrender.c @@ -308,7 +308,7 @@ int main (int argc, char **argv) "\t-r n\t\treverb preset: 0=no, 1=large hall, 2=hall, 3=chamber, 4=room.\n"\ "\t-w n\t\treverb wet: 0..32767.\n" "\t-n n\t\treverb dry: 0..32767.\n" - "\t-c n\t\tchorus preset: 0=no, 1..4=presents.\n" + "\t-c n\t\tchorus preset: 0=no, 1..4=presets.\n" "\t-v n\t\tmaster volume: 0..100.\n" , argv[0]); return EXIT_FAILURE; From cbe3d46ab67e0f89cfa08ae05baeb8fa0fa4252c Mon Sep 17 00:00:00 2001 From: rsp4jack Date: Fri, 25 Oct 2024 11:34:20 +0800 Subject: [PATCH 7/8] Refactor reverb and chorus to make preset apply immediately --- arm-wt-22k/lib_src/eas_chorus.c | 49 ++++++++--------------------- arm-wt-22k/lib_src/eas_chorusdata.h | 4 --- arm-wt-22k/lib_src/eas_reverb.c | 47 ++------------------------- arm-wt-22k/lib_src/eas_reverbdata.h | 3 -- 4 files changed, 16 insertions(+), 87 deletions(-) diff --git a/arm-wt-22k/lib_src/eas_chorus.c b/arm-wt-22k/lib_src/eas_chorus.c index 4a2c8d03..e60730f1 100644 --- a/arm-wt-22k/lib_src/eas_chorus.c +++ b/arm-wt-22k/lib_src/eas_chorus.c @@ -85,7 +85,6 @@ static const EAS_I16 EAS_chorusShape[CHORUS_SHAPE_SIZE] = { static EAS_RESULT ChorusInit (EAS_DATA_HANDLE pEASData, EAS_VOID_PTR *pInstData) { S_CHORUS_OBJECT *pChorusData; - S_CHORUS_PRESET *pPreset; EAS_I32 index; /* check Configuration Module for data allocation */ @@ -109,29 +108,7 @@ static EAS_RESULT ChorusInit (EAS_DATA_HANDLE pEASData, EAS_VOID_PTR *pInstData) /* set some default values */ pChorusData->bypass = EAS_CHORUS_BYPASS_DEFAULT; - pChorusData->preset = EAS_CHORUS_PRESET_DEFAULT; - pChorusData->m_nLevel = EAS_CHORUS_LEVEL_DEFAULT; - pChorusData->m_nRate = EAS_CHORUS_RATE_DEFAULT; - pChorusData->m_nDepth = EAS_CHORUS_DEPTH_DEFAULT; - - //chorus rate and depth need some massaging from preset value (which is sample rate independent) - - //convert rate from steps of .05 Hz to value which can be used as phase increment, - //with current CHORUS_SHAPE_SIZE and rate limits, this fits into 16 bits - //want to compute ((shapeSize * 65536) * (storedRate/20))/sampleRate; - //computing it as below allows rate steps to be evenly spaced - //uses 32 bit divide, but only once when new value is selected - pChorusData->m_nRate = (EAS_I16) - ((((EAS_I32)CHORUS_SHAPE_SIZE<<16)/(20*(EAS_I32)_OUTPUT_SAMPLE_RATE)) * pChorusData->m_nRate); - - //convert depth from steps of .05 ms, to samples, with 16 bit whole part, discard fraction - //want to compute ((depth * sampleRate)/20000) - //use the following approximation since 105/32 is roughly 65536/20000 - /*lint -e{704} use shift for performance */ - pChorusData->m_nDepth = (EAS_I16) - (((((EAS_I32)pChorusData->m_nDepth * _OUTPUT_SAMPLE_RATE)>>5) * 105) >> 16); - - pChorusData->m_nLevel = pChorusData->m_nLevel; + pChorusData->m_nNextChorus = EAS_CHORUS_PRESET_DEFAULT; //zero delay memory for chorus for (index = CHORUS_L_SIZE - 1; index >= 0; index--) @@ -157,18 +134,7 @@ static EAS_RESULT ChorusInit (EAS_DATA_HANDLE pEASData, EAS_VOID_PTR *pInstData) pChorusData->chorusTapPosition = (EAS_I16)((CHORUS_DELAY_MS * _OUTPUT_SAMPLE_RATE)/1000); //now copy from the new preset into Chorus - pPreset = &pChorusData->m_sPreset.m_sPreset[pChorusData->m_nNextChorus]; - - pChorusData->m_nLevel = pPreset->m_nLevel; - pChorusData->m_nRate = pPreset->m_nRate; - pChorusData->m_nDepth = pPreset->m_nDepth; - - pChorusData->m_nRate = (EAS_I16) - ((((EAS_I32)CHORUS_SHAPE_SIZE<<16)/(20*(EAS_I32)_OUTPUT_SAMPLE_RATE)) * pChorusData->m_nRate); - - /*lint -e{704} use shift for performance */ - pChorusData->m_nDepth = (EAS_I16) - (((((EAS_I32)pChorusData->m_nDepth * _OUTPUT_SAMPLE_RATE)>>5) * 105) >> 16); + ChorusUpdate(pChorusData); *pInstData = pChorusData; @@ -491,6 +457,7 @@ static EAS_RESULT ChorusSetParam (EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 value!=EAS_PARAM_CHORUS_PRESET3 && value!=EAS_PARAM_CHORUS_PRESET4) return EAS_ERROR_INVALID_PARAMETER; p->m_nNextChorus = (EAS_I8)value; + ChorusUpdate(p); // update parameters immediately break; case EAS_PARAM_CHORUS_RATE: if(valueEAS_CHORUS_RATE_MAX) @@ -590,9 +557,19 @@ static EAS_RESULT ChorusUpdate(S_CHORUS_OBJECT *pChorusData) pChorusData->m_nRate = pPreset->m_nRate; pChorusData->m_nDepth = pPreset->m_nDepth; + //chorus rate and depth need some massaging from preset value (which is sample rate independent) + + //convert rate from steps of .05 Hz to value which can be used as phase increment, + //with current CHORUS_SHAPE_SIZE and rate limits, this fits into 16 bits + //want to compute ((shapeSize * 65536) * (storedRate/20))/sampleRate; + //computing it as below allows rate steps to be evenly spaced + //uses 32 bit divide, but only once when new value is selected pChorusData->m_nRate = (EAS_I16) ((((EAS_I32)CHORUS_SHAPE_SIZE<<16)/(20*(EAS_I32)_OUTPUT_SAMPLE_RATE)) * pChorusData->m_nRate); + //convert depth from steps of .05 ms, to samples, with 16 bit whole part, discard fraction + //want to compute ((depth * sampleRate)/20000) + //use the following approximation since 105/32 is roughly 65536/20000 /*lint -e{704} use shift for performance */ pChorusData->m_nDepth = (EAS_I16) (((((EAS_I32)pChorusData->m_nDepth * _OUTPUT_SAMPLE_RATE)>>5) * 105) >> 16); diff --git a/arm-wt-22k/lib_src/eas_chorusdata.h b/arm-wt-22k/lib_src/eas_chorusdata.h index ec8daa45..292ceb59 100644 --- a/arm-wt-22k/lib_src/eas_chorusdata.h +++ b/arm-wt-22k/lib_src/eas_chorusdata.h @@ -38,9 +38,6 @@ #define EAS_CHORUS_BYPASS_DEFAULT 1 #define EAS_CHORUS_PRESET_DEFAULT 0 -#define EAS_CHORUS_RATE_DEFAULT 30 -#define EAS_CHORUS_DEPTH_DEFAULT 39 -#define EAS_CHORUS_LEVEL_DEFAULT 32767 #define EAS_CHORUS_LEVEL_MIN 0 #define EAS_CHORUS_LEVEL_MAX 32767 @@ -91,7 +88,6 @@ typedef struct EAS_PCM chorusDelayR[CHORUS_R_SIZE]; EAS_BOOL bypass; - EAS_I8 preset; EAS_I16 m_nCurrentChorus; // preset number for current Chorus EAS_I16 m_nNextChorus; // preset number for next Chorus diff --git a/arm-wt-22k/lib_src/eas_reverb.c b/arm-wt-22k/lib_src/eas_reverb.c index cd5befe3..0aabb7ad 100644 --- a/arm-wt-22k/lib_src/eas_reverb.c +++ b/arm-wt-22k/lib_src/eas_reverb.c @@ -168,13 +168,7 @@ static EAS_RESULT ReverbInit(EAS_DATA_HANDLE pEASData, EAS_VOID_PTR *pInstData) // for debugging purposes, allow bypass pReverbData->m_bBypass = EAS_TRUE; //EAS_FALSE; - pReverbData->m_nNextRoom = 1; - - pReverbData->m_nCurrentRoom = pReverbData->m_nNextRoom + 1; // force update on first iteration - - pReverbData->m_nWet = REVERB_DEFAULT_WET; - - pReverbData->m_nDry = REVERB_DEFAULT_DRY; + pReverbData->m_nNextRoom = REVERB_DEFAULT_ROOM_NUMBER; // set base index into circular buffer pReverbData->m_nBaseIndex = 0; @@ -207,43 +201,7 @@ static EAS_RESULT ReverbInit(EAS_DATA_HANDLE pEASData, EAS_VOID_PTR *pInstData) pReverbData->m_nDelayLine[i] = 0; } - //////////////////////////////// - ///code from the EAS DEMO Reverb - //now copy from the new preset into the reverb - pPreset = &pReverbData->m_sPreset.m_sPreset[pReverbData->m_nNextRoom]; - - pReverbData->m_nLpfFbk = pPreset->m_nLpfFbk; - pReverbData->m_nLpfFwd = pPreset->m_nLpfFwd; - - pReverbData->m_nEarly = pPreset->m_nEarly; - pReverbData->m_nWet = pPreset->m_nWet; - pReverbData->m_nDry = pPreset->m_nDry; - - pReverbData->m_nMaxExcursion = pPreset->m_nMaxExcursion; - //stored as time based, convert to sample based - temp = pPreset->m_nXfadeInterval; - /*lint -e{702} shift for performance */ - temp = (temp * _OUTPUT_SAMPLE_RATE) >> 16; - pReverbData->m_nXfadeInterval = (EAS_U16) temp; - //gsReverbObject.m_nXfadeInterval = pPreset->m_nXfadeInterval; - - pReverbData->m_sAp0.m_nApGain = pPreset->m_nAp0_ApGain; - //stored as time based, convert to absolute sample value - temp = pPreset->m_nAp0_ApOut; - /*lint -e{702} shift for performance */ - temp = (temp * _OUTPUT_SAMPLE_RATE) >> 16; - pReverbData->m_sAp0.m_zApOut = (EAS_U16) (pReverbData->m_sAp0.m_zApIn + temp); - //gsReverbObject.m_sAp0.m_zApOut = pPreset->m_nAp0_ApOut; - - pReverbData->m_sAp1.m_nApGain = pPreset->m_nAp1_ApGain; - //stored as time based, convert to absolute sample value - temp = pPreset->m_nAp1_ApOut; - /*lint -e{702} shift for performance */ - temp = (temp * _OUTPUT_SAMPLE_RATE) >> 16; - pReverbData->m_sAp1.m_zApOut = (EAS_U16) (pReverbData->m_sAp1.m_zApIn + temp); - //gsReverbObject.m_sAp1.m_zApOut = pPreset->m_nAp1_ApOut; - ///code from the EAS DEMO Reverb - //////////////////////////////// + ReverbUpdateRoom(pReverbData); *pInstData = pReverbData; @@ -877,6 +835,7 @@ static EAS_RESULT ReverbSetParam (EAS_VOID_PTR pInstData, EAS_I32 param, EAS_I32 value!=EAS_PARAM_REVERB_CHAMBER && value!=EAS_PARAM_REVERB_ROOM) return EAS_ERROR_INVALID_PARAMETER; p->m_nNextRoom = (EAS_I16)value; + ReverbUpdateRoom(p); // change parameters immediately break; case EAS_PARAM_REVERB_WET: if(value>EAS_REVERB_WET_MAX || value Date: Fri, 25 Oct 2024 21:37:45 +0800 Subject: [PATCH 8/8] Add chorus level for sonivoxrender --- example/sonivoxrender.1 | 10 +++++++--- example/sonivoxrender.1.md | 6 +++++- example/sonivoxrender.c | 20 ++++++++++++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/example/sonivoxrender.1 b/example/sonivoxrender.1 index a5d4ad87..484e5ebf 100644 --- a/example/sonivoxrender.1 +++ b/example/sonivoxrender.1 @@ -1,6 +1,6 @@ -.\" Automatically generated by Pandoc 3.1.11 +.\" Automatically generated by Pandoc 3.1.11.1 .\" -.TH "SONIVOXRENDER" "1" "October 6, 2024" "sonivox 3.6.14.0" "Sonivox MIDI File Renderer" +.TH "SONIVOXRENDER" "1" "October 25, 2024" "sonivox 3.6.15.0" "Sonivox MIDI File Renderer" .SH NAME \f[B]sonivoxrender\f[R] \[em] Render standard MIDI files into raw PCM audio @@ -9,7 +9,8 @@ audio \f[B]sonivoxrender\f[R] [\f[B]\-h\f[R]] [\f[B]\-d\f[R] \f[I]file.dls\f[R]] [\f[B]\-r\f[R] \f[I]0..4\f[R]] [\f[B]\-w\f[R] \f[I]0..32767\f[R]] [\f[B]\-n\f[R] \f[I]0..32767\f[R]] [\f[B]\-c\f[R] -\f[I]0..4\f[R]] [\f[B]\-v\f[R] \f[I]0..100\f[R]] \f[I]midi_file\f[R] +\f[I]0..4\f[R]] [\f[B]\-l\f[R] \f[I]0..32767\f[R]] [\f[B]\-v\f[R] +\f[I]0..100\f[R]] \f[I]midi_file\f[R] .SH DESCRIPTION This program is a MIDI file renderer based on the sonivox synthesizer library. @@ -37,6 +38,9 @@ Reverb dry level between 0 and 32767. \-c \f[I]chorus_preset\f[R] Chorus preset between 0 and 4: 0=no, 1..4=presets. .TP +\-l \f[I]chorus_level\f[R] +Chorus level between 0 and 32767. +.TP \-v \f[I]master_volume\f[R] Master volume between 0 and 100, default to 90. .SS Arguments diff --git a/example/sonivoxrender.1.md b/example/sonivoxrender.1.md index 9c0459b0..4a41fe9b 100644 --- a/example/sonivoxrender.1.md +++ b/example/sonivoxrender.1.md @@ -7,7 +7,7 @@ # SYNOPSIS -| **sonivoxrender** [**-h**] [**-d** _file.dls_] [**-r** _0..4_] [**-w** _0..32767_] [**-n** _0..32767_] [**-c** _0..4_] [**-v** _0..100_] _midi_file_ +| **sonivoxrender** [**-h**] [**-d** _file.dls_] [**-r** _0..4_] [**-w** _0..32767_] [**-n** _0..32767_] [**-c** _0..4_] [**-l** _0..32767_] [**-v** _0..100_] _midi_file_ # DESCRIPTION @@ -40,6 +40,10 @@ It reads .MID (Standard MIDI Files) file format, and writes an audio stream to t : Chorus preset between 0 and 4: 0=no, 1..4=presets. +-l _chorus_level_ + +: Chorus level between 0 and 32767. + -v _master_volume_ : Master volume between 0 and 100, default to 90. diff --git a/example/sonivoxrender.c b/example/sonivoxrender.c index 692df48a..4c29a6c8 100644 --- a/example/sonivoxrender.c +++ b/example/sonivoxrender.c @@ -32,6 +32,7 @@ EAS_I32 reverb_type = 0; EAS_I32 reverb_wet = 32767; EAS_I32 reverb_dry = 0; EAS_I32 chorus_type = 0; +EAS_I32 chorus_level = 32767; EAS_DATA_HANDLE mEASDataHandle = NULL; int Read(void *handle, void *buf, int offset, int size) { @@ -156,6 +157,13 @@ int initializeLibrary(void) ok = EXIT_FAILURE; goto cleanup; } + + result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_CHORUS, EAS_PARAM_CHORUS_LEVEL, chorus_level); + if (result != EAS_SUCCESS) { + fprintf(stderr, "Failed to set chorus level"); + ok = EXIT_FAILURE; + goto cleanup; + } } result = EAS_SetParameter(mEASDataHandle, EAS_MODULE_CHORUS, EAS_PARAM_CHORUS_BYPASS, chorus_bypass); @@ -296,11 +304,11 @@ int main (int argc, char **argv) opterr = 0; - while ((c = getopt (argc, argv, "hd:r:w:n:c:v:")) != -1) { + while ((c = getopt (argc, argv, "hd:r:w:n:c:l:v:")) != -1) { switch (c) { case 'h': - fprintf (stderr, "Usage: %s [-h] [-d file.dls] [-r 0..4] [-w 0..32767] [-n 0..32767] [-c 0..4] [-v 0..100] file.mid ...\n"\ + fprintf (stderr, "Usage: %s [-h] [-d file.dls] [-r 0..4] [-w 0..32767] [-n 0..32767] [-c 0..4] [-l 0..32767] [-v 0..100] file.mid ...\n"\ "Render standard MIDI files into raw PCM audio.\n"\ "Options:\n"\ "\t-h\t\tthis help message.\n"\ @@ -309,6 +317,7 @@ int main (int argc, char **argv) "\t-w n\t\treverb wet: 0..32767.\n" "\t-n n\t\treverb dry: 0..32767.\n" "\t-c n\t\tchorus preset: 0=no, 1..4=presets.\n" + "\t-l n\t\tchorus level: 0..32767.\n" "\t-v n\t\tmaster volume: 0..100.\n" , argv[0]); return EXIT_FAILURE; @@ -343,6 +352,13 @@ int main (int argc, char **argv) return EXIT_FAILURE; } break; + case 'l': + chorus_level = atoi(optarg); + if (chorus_level < 0 || chorus_level > 32767) { + fprintf (stderr, "invalid chorus level: %ld\n", chorus_level); + return EXIT_FAILURE; + } + break; case 'v': playback_gain = atoi(optarg); if (playback_gain < 0 || playback_gain > 100) {