Skip to content

Commit

Permalink
Merge pull request #26 from rsp4jack/patch1
Browse files Browse the repository at this point in the history
Add chorus, reverb dry and master gain for sonivoxrender
  • Loading branch information
pedrolcl authored Oct 27, 2024
2 parents 1040b71 + 1472c2b commit 765e624
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 149 deletions.
49 changes: 13 additions & 36 deletions arm-wt-22k/lib_src/eas_chorus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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--)
Expand All @@ -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;

Expand Down Expand Up @@ -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(value<EAS_CHORUS_RATE_MIN || value>EAS_CHORUS_RATE_MAX)
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions arm-wt-22k/lib_src/eas_chorusdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
47 changes: 3 additions & 44 deletions arm-wt-22k/lib_src/eas_reverb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<EAS_REVERB_WET_MIN)
Expand Down
3 changes: 0 additions & 3 deletions arm-wt-22k/lib_src/eas_reverbdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ EAS_I32 nPanG1 = -1.0 for cos
#define DEFAULT_AP1_LENGTH (int)(((double) (16.5/1000.0)) * ((double) _OUTPUT_SAMPLE_RATE))
#define DEFAULT_AP1_GAIN -19400

#define REVERB_DEFAULT_WET 32767
#define REVERB_DEFAULT_DRY 0

#define EAS_REVERB_WET_MAX 32767
#define EAS_REVERB_WET_MIN 0
#define EAS_REVERB_DRY_MAX 32767
Expand Down
94 changes: 47 additions & 47 deletions example/sonivoxrender.1
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
.\" Automatically generated by Pandoc 2.14.0.3
.\" Automatically generated by Pandoc 3.1.11.1
.\"
.TH "SONIVOXRENDER" "1" "October 6, 2024" "sonivox 3.6.14.0" "Sonivox MIDI File Renderer"
.hy
.TH "SONIVOXRENDER" "1" "October 25, 2024" "sonivox 3.6.15.0" "Sonivox MIDI File Renderer"
.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]\-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
.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=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
.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 <https://github.com/pedrolcl/sonivox/issues/>
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 <plcl@users.sf.net>.
Pedro López\-Cabanillas \c
.MT plcl@users.sf.net
.ME \c.
20 changes: 18 additions & 2 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..32765_] _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

Expand All @@ -30,7 +30,23 @@ 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=presets.

-l _chorus_level_

: Chorus level between 0 and 32767.

-v _master_volume_

: Master volume between 0 and 100, default to 90.

## Arguments

Expand Down
Loading

0 comments on commit 765e624

Please sign in to comment.