Skip to content

Commit

Permalink
* Kontakt 1-4, MPC Keygroups, Soundfont 2, TAL Sampler, TX16Wx
Browse files Browse the repository at this point in the history
  * New: Added support for amplitude and filter velocity modulation.
  • Loading branch information
git-moss committed Jul 1, 2024
1 parent 2485e87 commit 846c8d7
Show file tree
Hide file tree
Showing 50 changed files with 836 additions and 491 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changes

## 10.5.0 (unreleased)
## 10.2.0

* Added support for Waldorf Quantum MkI/MkII, Iridium, Iridium Core sample format.
* Kontakt 1-4, MPC Keygroups, Soundfont 2, TAL Sampler, TX16Wx
* New: Added support for amplitude and filter velocity modulation.
* Kontakt - Writing
* New: Improved pitch envelope.
* Kontakt 4.2-7 - Reading
Expand Down
Binary file modified documentation/SupportedFeaturesSampleFormats.ods
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.mossgrabers</groupId>
<artifactId>convertwithmoss</artifactId>
<version>10.5.0</version>
<version>10.2.0</version>
<packaging>jar</packaging>
<name>ConvertWithMoss</name>
<organization>
Expand Down
40 changes: 6 additions & 34 deletions src/main/java/de/mossgrabers/convertwithmoss/core/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,6 @@ private MathUtils ()
}


/**
* Limit the given value to the minimum/maximum range including minimum/maximum values.
*
* @param value The value to clamp
* @param minimum The minimum value
* @param maximum The maximum value
* @return The value clamped to the minimum/maximum range
*/
public static double clamp (final double value, final double minimum, final double maximum)
{
return Math.max (minimum, Math.min (value, maximum));
}


/**
* Limit the given value to the minimum/maximum range including minimum/maximum values.
*
* @param value The value to clamp
* @param minimum The minimum value
* @param maximum The maximum value
* @return The value clamped to the minimum/maximum range
*/
public static int clamp (final int value, final int minimum, final int maximum)
{
return Math.max (minimum, Math.min (value, maximum));
}


/**
* Converts a signed integer into a two complement short value.
*
Expand Down Expand Up @@ -122,7 +94,7 @@ public static double dBToDouble (final double dBValue)
*/
public static double normalizeFrequency (final double frequency, final double maxFrequency)
{
return clamp (log2 (frequency) / log2 (maxFrequency), 0, 1);
return Math.clamp (log2 (frequency) / log2 (maxFrequency), 0, 1);
}


Expand All @@ -147,7 +119,7 @@ public static double denormalizeFrequency (final double normalizedFrequency, fin
*/
public static double normalizeCutoff (final double cutoffInHertz)
{
return MathUtils.clamp ((log2 (cutoffInHertz / (2 * 440.0)) * 12.0 + 57) / 140.0, 0, 1);
return Math.clamp ((log2 (cutoffInHertz / (2 * 440.0)) * 12.0 + 57) / 140.0, 0, 1);
}


Expand All @@ -159,7 +131,7 @@ public static double normalizeCutoff (final double cutoffInHertz)
*/
public static double denormalizeCutoff (final double normalizedValue)
{
return MathUtils.clamp (2.0 * 440.0 * Math.pow (2, (normalizedValue * 140.0 - 57.0) / 12.0), 32.7, 106300);
return Math.clamp (2.0 * 440.0 * Math.pow (2, (normalizedValue * 140.0 - 57.0) / 12.0), 32.7, 106300);
}


Expand All @@ -186,7 +158,7 @@ public static double normalize (final double value, final double maximum)
*/
public static double normalize (final double value, final double minimum, final double maximum)
{
return clamp (value, minimum, maximum) / maximum;
return Math.clamp (value, minimum, maximum) / maximum;
}


Expand All @@ -200,7 +172,7 @@ public static double normalize (final double value, final double minimum, final
*/
public static double denormalize (final double value, final double minimum, final double maximum)
{
return clamp (value * maximum, minimum, maximum);
return Math.clamp (value * maximum, minimum, maximum);
}


Expand Down Expand Up @@ -267,7 +239,7 @@ public static int normalizeTimeAsInt (final double value, final double maxValue)
public static double normalizeTime (final double value, final double maxValue)
{
// value is negative if not set but 0 is fine then!
final double clamped = MathUtils.clamp (value, 0, maxValue);
final double clamped = Math.clamp (value, 0, maxValue);
return Math.log (clamped + 1) / Math.log (maxValue + 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import de.mossgrabers.convertwithmoss.core.AbstractCoreTask;
import de.mossgrabers.convertwithmoss.core.IMultisampleSource;
import de.mossgrabers.convertwithmoss.core.INotifier;
import de.mossgrabers.convertwithmoss.core.MathUtils;
import de.mossgrabers.convertwithmoss.core.model.IGroup;
import de.mossgrabers.convertwithmoss.core.model.IMetadata;
import de.mossgrabers.convertwithmoss.core.model.ISampleData;
Expand Down Expand Up @@ -650,7 +649,7 @@ private void rewriteFile (final IMetadata metadata, final ISampleZone zone, fina
// Update information chunks
if (this.isUpdateBroadcastAudioChunk ())
updateBroadcastAudioChunk (metadata, wavFile);
final int unityNote = MathUtils.clamp (zone.getKeyRoot (), 0, 127);
final int unityNote = Math.clamp (zone.getKeyRoot (), 0, 127);
if (this.isUpdateInstrumentChunk ())
updateInstrumentChunk (zone, wavFile, unityNote);
if (this.isUpdateSampleChunk ())
Expand All @@ -665,7 +664,7 @@ private void rewriteFile (final IMetadata metadata, final ISampleZone zone, fina
/**
* Trims the data of the wave file to the part from the zone start and zone end. The zone is
* updated accordingly.
*
*
* @param wavFile The WAV file to trim
* @param zone The zone
*/
Expand Down Expand Up @@ -746,12 +745,12 @@ private static void updateInstrumentChunk (final ISampleZone zone, final WaveFil
}

instrumentChunk.setUnshiftedNote (unityNote);
instrumentChunk.setFineTune (MathUtils.clamp ((int) (zone.getTune () * 100), -50, 50));
instrumentChunk.setGain (MathUtils.clamp ((int) zone.getGain (), -127, 127));
instrumentChunk.setLowNote (MathUtils.clamp (zone.getKeyLow (), 0, 127));
instrumentChunk.setHighNote (MathUtils.clamp (limitToDefault (zone.getKeyHigh (), 127), 0, 127));
instrumentChunk.setLowVelocity (MathUtils.clamp (zone.getVelocityLow (), 0, 127));
instrumentChunk.setHighVelocity (MathUtils.clamp (limitToDefault (zone.getVelocityHigh (), 127), 0, 127));
instrumentChunk.setFineTune (Math.clamp ((int) (zone.getTune () * 100), -50, 50));
instrumentChunk.setGain (Math.clamp ((int) zone.getGain (), -127, 127));
instrumentChunk.setLowNote (Math.clamp (zone.getKeyLow (), 0, 127));
instrumentChunk.setHighNote (Math.clamp (limitToDefault (zone.getKeyHigh (), 127), 0, 127));
instrumentChunk.setLowVelocity (Math.clamp (zone.getVelocityLow (), 0, 127));
instrumentChunk.setHighVelocity (Math.clamp (limitToDefault (zone.getVelocityHigh (), 127), 0, 127));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import de.mossgrabers.convertwithmoss.core.IMultisampleSource;
import de.mossgrabers.convertwithmoss.core.INotifier;
import de.mossgrabers.convertwithmoss.core.MathUtils;
import de.mossgrabers.convertwithmoss.core.model.IFileBasedSampleData;
import de.mossgrabers.convertwithmoss.core.model.IGroup;
import de.mossgrabers.convertwithmoss.core.model.IMetadata;
Expand Down Expand Up @@ -348,7 +347,7 @@ protected String loadTextFile (final File file) throws IOException
*/
protected static double denormalizeValue (final double value, final double minimum, final double maximum)
{
return minimum + MathUtils.clamp (value, 0, 1) * (maximum - minimum);
return minimum + Math.clamp (value, 0, 1) * (maximum - minimum);
}


Expand Down Expand Up @@ -558,7 +557,7 @@ protected File findSampleFile (final File folder, final File previousFolder, fin
}

// ... and search recursively...
final File found = findSampleFileRecursively (startDirectory, sampleFile.getName ());
final File found = this.findSampleFileRecursively (startDirectory, sampleFile.getName ());
// Returning the original file triggers the expected error...
if (found == null)
return sampleFile;
Expand Down Expand Up @@ -600,7 +599,7 @@ private File findSampleFileRecursively (final File folder, final String fileName
if (children != null)
for (final File subFolder: children)
{
sampleFile = findSampleFileRecursively (subFolder, fileName);
sampleFile = this.findSampleFileRecursively (subFolder, fileName);
if (sampleFile != null)
return sampleFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class DefaultFilter implements IFilter
protected double cutoff;
protected double resonance;
protected int envelopeDepth;
protected IEnvelopeModulator cutoffEnvelopeModulator = new DefaultEnvelopeModulator (1);
protected IModulator cutoffVelocityModulator = new DefaultModulator (1);
protected IEnvelopeModulator cutoffEnvelopeModulator = new DefaultEnvelopeModulator (0);
protected IModulator cutoffVelocityModulator = new DefaultModulator (0);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package de.mossgrabers.convertwithmoss.core.model.implementation;

import de.mossgrabers.convertwithmoss.core.MathUtils;
import de.mossgrabers.convertwithmoss.core.model.IModulator;


Expand All @@ -25,7 +24,7 @@ public class DefaultModulator implements IModulator
*/
public DefaultModulator (final double depth)
{
this.depth = MathUtils.clamp (depth, -1, 1);
this.depth = Math.clamp (depth, -1, 1);
}


Expand All @@ -41,7 +40,7 @@ public double getDepth ()
@Override
public void setDepth (final double depth)
{
this.depth = MathUtils.clamp (depth, -1.0, 1.0);
this.depth = Math.clamp (depth, -1.0, 1.0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package de.mossgrabers.convertwithmoss.core.model.implementation;

import de.mossgrabers.convertwithmoss.core.MathUtils;
import de.mossgrabers.convertwithmoss.core.model.ISampleLoop;
import de.mossgrabers.convertwithmoss.core.model.enumeration.LoopType;

Expand Down Expand Up @@ -101,7 +100,7 @@ public int getCrossfadeInSamples ()
@Override
public void setCrossfade (final double crossfade)
{
this.crossfade = MathUtils.clamp (crossfade, 0.0, 1.0);
this.crossfade = Math.clamp (crossfade, 0.0, 1.0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.List;
import java.util.Optional;

import de.mossgrabers.convertwithmoss.core.MathUtils;
import de.mossgrabers.convertwithmoss.core.model.IEnvelopeModulator;
import de.mossgrabers.convertwithmoss.core.model.IFilter;
import de.mossgrabers.convertwithmoss.core.model.IModulator;
Expand Down Expand Up @@ -340,7 +339,7 @@ public void setVelocityCrossfadeHigh (final int crossfadeHigh)
@Override
public void setGain (final double gain)
{
this.gain = MathUtils.clamp (gain, -12.0, 12.0);
this.gain = Math.clamp (gain, -12.0, 12.0);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,10 @@ public static WaveFile convertToWav (final ISampleData sampleData, final Destina

// AudioSystem handles 32bit float values incorrect. We need our own implementation.
if (is32BitFloat)
{
try (AudioInputStream convertedAudioInputStream = convertAudioStreamFrom32BitFloatTo16BitPCM (audioInputStream, audioFormat, newAudioFormat))
{
return doConvertToWav (convertedAudioInputStream, newAudioFormat);
}
}

return doConvertToWav (audioInputStream, newAudioFormat);
}
Expand All @@ -303,7 +301,7 @@ private static AudioInputStream convertAudioStreamFrom32BitFloatTo16BitPCM (fina

for (int i = 0; i < sourceData.length; i += 4)
{
float floatValue = inputBuffer.getFloat (i);
final float floatValue = inputBuffer.getFloat (i);

// Convert float to 16-bit PCM
outputBuffer.putShort ((short) (floatValue * Short.MAX_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
public class Sf2Modulator
{
/** The ID for a Velocity modulator. */
public static final Integer MODULATOR_VELOCITY = Integer.valueOf (2);
/** The ID for a Pitch Bend modulator. */
public static final Integer MODULATOR_PITCH_BEND = Integer.valueOf (14);

Expand All @@ -30,7 +32,7 @@ public class Sf2Modulator
* The controller source to be used is the velocity value which is sent from the MIDI
* note-on command which generated the given sound.
*/
MODULATOR_NAMES.put (Integer.valueOf (2), "Note-On Velocity");
MODULATOR_NAMES.put (MODULATOR_VELOCITY, "Note-On Velocity");
/**
* The controller source to be used is the key number value which was sent from the MIDI
* note-on command which generated the given sound.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void setSignificantBitsPerSample (final int bitsPerSample)
*/
public int calculateLength (final byte [] data)
{
return data.length / calculateBytesPerSample ();
return data.length / this.calculateBytesPerSample ();
}


Expand All @@ -314,14 +314,14 @@ public int calculateLength (final byte [] data)
*/
public int calculateDataSize (final int lengthInSamples)
{
return lengthInSamples * calculateBytesPerSample ();
return lengthInSamples * this.calculateBytesPerSample ();
}


/**
* Calculate the number of bytes which are used for one sample depending on the significant bite
* per sample and the number of channels.
*
*
* @return The number of bytes
*/
public int calculateBytesPerSample ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public int getMIDIUnityNoteRaw ()
public int getMIDIUnityNote ()
{
final int unityNote = this.getFourBytesAsInt (0x0C);
return getMIDIPitchFractionAsCents () < 0 ? unityNote + 1 : unityNote;
return this.getMIDIPitchFractionAsCents () < 0 ? unityNote + 1 : unityNote;
}


Expand Down Expand Up @@ -192,7 +192,7 @@ public long getMIDIPitchFraction ()
*/
public int getMIDIPitchFractionAsCents ()
{
long midiPitchFraction = this.getMIDIPitchFraction ();
final long midiPitchFraction = this.getMIDIPitchFraction ();
final int value = (int) Math.round (midiPitchFraction * 50.0 / 0x80000000L);
return value > 50 ? value - 100 : value;
}
Expand All @@ -201,7 +201,7 @@ public int getMIDIPitchFractionAsCents ()
/**
* Sets the unity note and the pitch fraction. If the cents are negative the unity note and
* fraction are adapted accordingly.
*
*
* @param unityNote The unity note to set
* @param cent The pitch adjustment in cents
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void setBroadcastAudioExtensionChunk (final BroadcastAudioExtensionChunk
{
this.broadcastAudioExtensionChunk = broadcastAudioExtensionChunk;
this.chunkStack.clear ();
fillChunkStack ();
this.fillChunkStack ();
}


Expand All @@ -156,7 +156,7 @@ public void setInstrumentChunk (final InstrumentChunk instrumentChunk)
{
this.instrumentChunk = instrumentChunk;
this.chunkStack.clear ();
fillChunkStack ();
this.fillChunkStack ();
}


Expand All @@ -180,7 +180,7 @@ public void setSampleChunk (final SampleChunk sampleChunk)
{
this.sampleChunk = sampleChunk;
this.chunkStack.clear ();
fillChunkStack ();
this.fillChunkStack ();
}


Expand All @@ -204,7 +204,7 @@ public void setDataChunk (final DataChunk dataChunk)
{
this.dataChunk = dataChunk;
this.chunkStack.clear ();
fillChunkStack ();
this.fillChunkStack ();
}


Expand Down
Loading

0 comments on commit 846c8d7

Please sign in to comment.