From 7e64165b922135b914a20d1faf3f5fbf9cefd6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20L=C3=B3pez-Cabanillas?= Date: Sun, 27 Oct 2024 13:01:41 +0100 Subject: [PATCH] several cleanups and example updates --- arm-wt-22k/lib_src/eas_reverb.c | 2 - arm-wt-22k/lib_src/eas_reverbdata.h | 2 - example/sonivoxrender.1 | 93 +++++++++++++++++------------ example/sonivoxrender.1.md | 10 +++- example/sonivoxrender.c | 73 +++++++++++++++------- 5 files changed, 112 insertions(+), 68 deletions(-) diff --git a/arm-wt-22k/lib_src/eas_reverb.c b/arm-wt-22k/lib_src/eas_reverb.c index 0aabb7ad..9509ed0a 100644 --- a/arm-wt-22k/lib_src/eas_reverb.c +++ b/arm-wt-22k/lib_src/eas_reverb.c @@ -76,10 +76,8 @@ static EAS_RESULT ReverbInit(EAS_DATA_HANDLE pEASData, EAS_VOID_PTR *pInstData) { EAS_I32 i; EAS_U16 nOffset; - EAS_INT temp; S_REVERB_OBJECT *pReverbData; - S_REVERB_PRESET *pPreset; /* check Configuration Module for data allocation */ if (pEASData->staticMemoryModel) diff --git a/arm-wt-22k/lib_src/eas_reverbdata.h b/arm-wt-22k/lib_src/eas_reverbdata.h index f500fe19..1280778c 100644 --- a/arm-wt-22k/lib_src/eas_reverbdata.h +++ b/arm-wt-22k/lib_src/eas_reverbdata.h @@ -357,8 +357,6 @@ typedef struct S_REVERB_PRESET_BANK m_sPreset; - //EAS_I8 preset; - } S_REVERB_OBJECT; diff --git a/example/sonivoxrender.1 b/example/sonivoxrender.1 index 484e5ebf..c10fd38c 100644 --- a/example/sonivoxrender.1 +++ b/example/sonivoxrender.1 @@ -1,105 +1,122 @@ -.\" Automatically generated by Pandoc 3.1.11.1 +.\" Automatically generated by Pandoc 2.14.0.3 .\" -.TH "SONIVOXRENDER" "1" "October 25, 2024" "sonivox 3.6.15.0" "Sonivox MIDI File Renderer" +.TH "SONIVOXRENDER" "1" "October 27, 2024" "sonivox 3.6.15.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..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]\-l\f[R] \f[I]0..32767\f[R]] [\f[B]\-v\f[R] +\f[B]sonivoxrender\f[R] [\f[B]-h\f[R]] [\f[B]-v\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]-l\f[R] \f[I]0..32767\f[R]] [\f[B]-g\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] +-v +Prints the version numbers. +.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] +-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] +-w \f[I]reverb_wet\f[R] Reverb wet level between 0 and 32767. .TP -\-n \f[I]reverb_dry\f[R] +-n \f[I]reverb_dry\f[R] Reverb dry level between 0 and 32767. .TP -\-c \f[I]chorus_preset\f[R] +-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] +-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. +-g \f[I]master_gain\f[R] +Master gain between 0 and 100, default is 90 (10 dB below maximum). .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 -.EX +.nf +\f[C] $ sonivoxrender ants.mid > ants.pcm -.EE +\f[R] +.fi .PP Example 2: pipe the rendered audio thru the Linux ALSA \f[B]aplay\f[R] utility: .IP -.EX -$ sonivoxrender ants.mid | aplay \-c 2 \-f S16_LE \-r 44100 -.EE +.nf +\f[C] +$ sonivoxrender ants.mid | aplay -c 2 -f S16_LE -r 44100 +\f[R] +.fi .PP is equivalent to: .IP -.EX -$ sonivoxrender ants.mid | aplay \-f cd -.EE +.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 -.EX -$ sonivoxrender ants.mid | lame \-r \-s 44100 \- ants.mp3 -.EE +.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 -.EX -$ sonivoxrender ants.mid | sox \-t s16 \-c 2 \-r 44100 \- ants.wav -.EE +.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 -.EX +.nf +\f[C] $ sonivoxrender ants.mid | pacat -.EE +\f[R] +.fi .SH BUGS -See Tickets at GitHub \c -.UR https://github.com/pedrolcl/sonivox/issues/ -.UE \c +.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ópez\-Cabanillas and contributors +Copyright (c) 2022-2024 Pedro L\['o]pez-Cabanillas and contributors .SH AUTHORS -Pedro López\-Cabanillas \c -.MT plcl@users.sf.net -.ME \c. +Pedro L\['o]pez-Cabanillas . diff --git a/example/sonivoxrender.1.md b/example/sonivoxrender.1.md index 4a41fe9b..86df0cc4 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_] [**-l** _0..32767_] [**-v** _0..100_] _midi_file_ +| **sonivoxrender** [**-h**] [**-v**] [**-d** _file.dls_] [**-r** _0..4_] [**-w** _0..32767_] [**-n** _0..32767_] [**-c** _0..4_] [**-l** _0..32767_] [**-g** _0..100_] _midi_file_ # DESCRIPTION @@ -20,6 +20,10 @@ It reads .MID (Standard MIDI Files) file format, and writes an audio stream to t : Prints brief usage information. +-v + +: Prints the version numbers. + -d _file.dls_ : Optional DLS soundfont file name. If not provided, it uses an internal embedded soundfont. @@ -44,9 +48,9 @@ It reads .MID (Standard MIDI Files) file format, and writes an audio stream to t : Chorus level between 0 and 32767. --v _master_volume_ +-g _master_gain_ -: Master volume between 0 and 100, default to 90. +: Master gain between 0 and 100, default is 90 (10 dB below maximum). ## Arguments diff --git a/example/sonivoxrender.c b/example/sonivoxrender.c index 4c29a6c8..eb113675 100644 --- a/example/sonivoxrender.c +++ b/example/sonivoxrender.c @@ -34,8 +34,11 @@ EAS_I32 reverb_dry = 0; EAS_I32 chorus_type = 0; EAS_I32 chorus_level = 32767; EAS_DATA_HANDLE mEASDataHandle = NULL; +const S_EAS_LIB_CONFIG *mEASConfig = NULL; +char sLibrary_version[16]; -int Read(void *handle, void *buf, int offset, int size) { +int Read(void *handle, void *buf, int offset, int size) +{ int ret; ret = fseek((FILE *) handle, offset, SEEK_SET); @@ -53,6 +56,22 @@ int Size(void *handle) { return ftell((FILE *) handle); } +void initLibraryVersion() +{ + memset(sLibrary_version, 0, sizeof(sLibrary_version)); + mEASConfig = EAS_Config(); + if (mEASConfig == NULL) { + fprintf(stderr, "Failed to get the library configuration\n"); + } else { + u_int8_t v1, v2, v3, v4; + v1 = (mEASConfig->libVersion >> 24) & 0xff; + v2 = (mEASConfig->libVersion >> 16) & 0xff; + v3 = (mEASConfig->libVersion >> 8) & 0xff; + v4 = mEASConfig->libVersion & 0xff; + snprintf(sLibrary_version, sizeof(sLibrary_version), "%d.%d.%d.%d", v1, v2, v3, v4); + } +} + void shutdownLibrary(void) { if (mEASDataHandle) { @@ -108,7 +127,7 @@ int initializeLibrary(void) result = EAS_SetVolume(mEASDataHandle, NULL, playback_gain); if (result != EAS_SUCCESS) { - fprintf(stderr, "Failed to set volume\n"); + fprintf(stderr, "Failed to set master gain\n"); ok = EXIT_FAILURE; goto cleanup; } @@ -187,7 +206,6 @@ int renderFile(const char *fileName) EAS_FILE mEasFile; EAS_PCM *mAudioBuffer = NULL; EAS_I32 mPCMBufferSize = 0; - const S_EAS_LIB_CONFIG *mEASConfig; int ok = EXIT_SUCCESS; @@ -302,66 +320,75 @@ int main (int argc, char **argv) int ok = EXIT_SUCCESS; int index, c; + initLibraryVersion(); + opterr = 0; - while ((c = getopt (argc, argv, "hd:r:w:n:c:l:v:")) != -1) { + while ((c = getopt(argc, argv, "hvd:r:w:n:c:l:g:")) != -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] [-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"\ - "\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..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]); + fprintf( + stderr, + "Usage: %s [-h] [-v] [-d file.dls] [-r 0..4] [-w 0..32767] [-n 0..32767] [-c 0..4] " + "[-l 0..32767] [-g 0..100] file.mid ...\n" + "Render standard MIDI files into raw PCM audio.\n" + "Options:\n" + "\t-h\t\tthis help message.\n" + "\t-v\t\tsonivox version.\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..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-g n\t\tmaster gain: 0..100.\n", + argv[0]); + return EXIT_FAILURE; + case 'v': + fprintf(stderr, "version: %s\n", sLibrary_version); return EXIT_FAILURE; case 'd': dls_path = optarg; break; case 'r': reverb_type = atoi(optarg); - if (reverb_type < 0 || reverb_type > 4) { + if ((reverb_type < 0) || (reverb_type > 4)) { fprintf (stderr, "invalid reverb preset: %ld\n", reverb_type); return EXIT_FAILURE; } break; case 'w': reverb_wet = atoi(optarg); - if (reverb_wet < 0 || reverb_wet > 32767) { + 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) { + 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) { + if ((chorus_type < 0) || (chorus_type > 4)) { fprintf (stderr, "invalid chorus preset: %ld\n", chorus_type); return EXIT_FAILURE; } break; case 'l': chorus_level = atoi(optarg); - if (chorus_level < 0 || chorus_level > 32767) { + if ((chorus_level < 0) || (chorus_level > 32767)) { fprintf (stderr, "invalid chorus level: %ld\n", chorus_level); return EXIT_FAILURE; } break; - case 'v': + case 'g': playback_gain = atoi(optarg); - if (playback_gain < 0 || playback_gain > 100) { + if ((playback_gain < 0) || (playback_gain > 100)) { fprintf (stderr, "invalid playback gain: %ld\n", playback_gain); return EXIT_FAILURE; }