Skip to content

Commit

Permalink
several cleanups and example updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolcl committed Oct 27, 2024
1 parent 765e624 commit 7e64165
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 68 deletions.
2 changes: 0 additions & 2 deletions arm-wt-22k/lib_src/eas_reverb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions arm-wt-22k/lib_src/eas_reverbdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,6 @@ typedef struct

S_REVERB_PRESET_BANK m_sPreset;

//EAS_I8 preset;

} S_REVERB_OBJECT;


Expand Down
93 changes: 55 additions & 38 deletions example/sonivoxrender.1
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/pedrolcl/sonivox/issues/>
.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 <plcl@users.sf.net>.
10 changes: 7 additions & 3 deletions example/sonivoxrender.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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

Expand Down
73 changes: 50 additions & 23 deletions example/sonivoxrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7e64165

Please sign in to comment.