diff --git a/instrument-core/src/main/java/jomu/instrument/audio/TarsosAudioSynthesizer.java b/instrument-core/src/main/java/jomu/instrument/audio/TarsosAudioSynthesizer.java index 829f1910..ca492530 100644 --- a/instrument-core/src/main/java/jomu/instrument/audio/TarsosAudioSynthesizer.java +++ b/instrument-core/src/main/java/jomu/instrument/audio/TarsosAudioSynthesizer.java @@ -396,14 +396,17 @@ public void run() { } gain = amplitude; // if (noteStatusElement.state != OFF) { - double newGain = lastAmps[toneMapElement.getIndex()] - + (gain - lastAmps[toneMapElement.getIndex()]) / 2.0; - if (newGain < 0) { - newGain = 0; - } - totalGain += newGain; - lastAmps[toneMapElement.getIndex()] = newGain; - audioStream.getSineGenerators()[toneMapElement.getIndex()].setGain(newGain); + // double newGain = lastAmps[toneMapElement.getIndex()] + // + (gain - lastAmps[toneMapElement.getIndex()]) / 2.0; + // if (newGain < 0) { + // newGain = 0; + // } + // totalGain += newGain; + // lastAmps[toneMapElement.getIndex()] = newGain; + // audioStream.getSineGenerators()[toneMapElement.getIndex()].setGain(newGain); + totalGain += gain; + lastAmps[toneMapElement.getIndex()] = gain; + audioStream.getSineGenerators()[toneMapElement.getIndex()].setGain(gain); // } else { // audioStream.getSineGenerators()[toneMapElement.getIndex()].setGain(0.0); // lastAmps[toneMapElement.getIndex()] = 0F; @@ -413,7 +416,7 @@ public void run() { // if (totalGain > 1.0) { for (ToneMapElement toneMapElement : ttfElements) { double gain = audioStream.getSineGenerators()[toneMapElement.getIndex()].getGain(); - if (gain > 0.01) { + if (gain > 0.1) { audioStream.getSineGenerators()[toneMapElement.getIndex()].setGain(gain / totalGain); // GAIN } else { audioStream.getSineGenerators()[toneMapElement.getIndex()].setGain(0.0); // GAIN diff --git a/instrument-core/src/main/java/jomu/instrument/audio/features/ResynthSource.java b/instrument-core/src/main/java/jomu/instrument/audio/features/ResynthSource.java index 57274500..9e9dbe72 100644 --- a/instrument-core/src/main/java/jomu/instrument/audio/features/ResynthSource.java +++ b/instrument-core/src/main/java/jomu/instrument/audio/features/ResynthSource.java @@ -65,8 +65,8 @@ public ResynthSource(AudioDispatcher dispatcher) { .getParameterManager(); this.windowSize = parameterManager.getIntParameter(InstrumentParameterNames.PERCEPTION_HEARING_DEFAULT_WINDOW); envelopeFollower = new EnvelopeFollower(samplerate, 0.005, 0.01); - this.followEnvelope = true; - this.usePureSine = true; + this.followEnvelope = false; + this.usePureSine = false; previousFrequencies = new double[5]; previousFrequencyIndex = 0; } @@ -113,7 +113,6 @@ public float getSampleRate() { } void initialise() { - LOG.severe(">>!!RS init: " + this.windowSize); PitchEstimationAlgorithm algo = PitchEstimationAlgorithm.FFT_YIN; binStartingPointsInCents = new float[windowSize]; @@ -140,7 +139,6 @@ public boolean process(AudioEvent audioEvent) { .clone(); ResynthInfo ri = new ResynthInfo(audioFloatBuffer, envelopeAudioBuffer); putFeature(audioEvent.getTimeStamp(), ri); - LOG.severe(">>!!RS process"); return true; } @@ -156,7 +154,6 @@ public void processingFinished() { @Override public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) { double frequency = pitchDetectionResult.getPitch(); - LOG.severe(">>!!RS handlePitch: " + audioEvent.getTimeStamp()); if (frequency == -1) { frequency = prevFrequency; } else { @@ -177,29 +174,26 @@ public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent au } final double twoPiF = 2 * Math.PI * frequency; - envelopeAudioBuffer = audioEvent.getFloatBuffer() - .clone(); // !!TODO CLONED - float[] envelope = null; - LOG.severe(">>!!RS handlePitch ENVELOP: " + audioEvent.getTimeStamp()); + float[] audioBuffer = audioEvent.getFloatBuffer(); + envelopeAudioBuffer = audioBuffer.clone(); if (followEnvelope) { - envelope = envelopeAudioBuffer.clone(); - envelopeFollower.calculateEnvelope(envelope); + envelopeFollower.calculateEnvelope(envelopeAudioBuffer); } - for (int sample = 0; sample < envelopeAudioBuffer.length; sample++) { + for (int sample = 0; sample < audioBuffer.length; sample++) { double time = sample / samplerate; double wave = Math.sin(twoPiF * time + phase); if (!usePureSine) { wave += 0.05 * Math.sin(twoPiF * 4 * time + phaseFirst); wave += 0.01 * Math.sin(twoPiF * 8 * time + phaseSecond); } - envelopeAudioBuffer[sample] = (float) wave; + audioBuffer[sample] = (float) wave; if (followEnvelope) { - envelopeAudioBuffer[sample] = envelopeAudioBuffer[sample] * envelope[sample]; + audioBuffer[sample] = audioBuffer[sample] * envelopeAudioBuffer[sample]; } } - double timefactor = twoPiF * envelopeAudioBuffer.length / samplerate; + double timefactor = twoPiF * audioBuffer.length / samplerate; phase = timefactor + phase; if (!usePureSine) { phaseFirst = 4 * timefactor + phaseFirst;