Rename decay to release

pull/137/head
James Ball 2022-11-05 21:18:29 +00:00 zatwierdzone przez James H Ball
rodzic 9070262769
commit c536b9d59c
4 zmienionych plików z 27 dodań i 30 usunięć

Wyświetl plik

@ -20,7 +20,7 @@ public interface AudioPlayer<S> extends Runnable, MidiListener {
void setBackingMidiVolume(double scale); void setBackingMidiVolume(double scale);
void setDecay(double decaySeconds); void setRelease(double decaySeconds);
void setAttack(double attackSeconds); void setAttack(double attackSeconds);

Wyświetl plik

@ -5,7 +5,6 @@ import sh.ball.audio.effect.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level; import java.util.logging.Level;
import sh.ball.audio.engine.AudioDevice; import sh.ball.audio.engine.AudioDevice;
@ -45,13 +44,12 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
private int mainChannel = 0; private int mainChannel = 0;
private MidiNote baseNote = new MidiNote(60, mainChannel); private MidiNote baseNote = new MidiNote(60, mainChannel);
private final double[] pitchBends = new double[MidiNote.NUM_CHANNELS]; private final double[] pitchBends = new double[MidiNote.NUM_CHANNELS];
private int lastDecay = 0; private int lastRelease = 0;
private double decaySeconds = 0.2; private double releaseSeconds = 0.2;
private int decayFrames; private int releaseFrames;
private int lastAttack = 0; private int lastAttack = 0;
private double attackSeconds = 0.1; private double attackSeconds = 0.1;
private int attackFrames; private int attackFrames;
private int totalVolume = MidiNote.MAX_VELOCITY;
private final Callable<AudioEngine> audioEngineBuilder; private final Callable<AudioEngine> audioEngineBuilder;
private final BlockingQueue<List<Shape>> frameQueue = new ArrayBlockingQueue<>(BUFFER_SIZE); private final BlockingQueue<List<Shape>> frameQueue = new ArrayBlockingQueue<>(BUFFER_SIZE);
@ -269,16 +267,16 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
try { try {
keyOnLock.acquire(); keyOnLock.acquire();
totalVolume = MidiNote.MAX_VELOCITY; int totalVolume = MidiNote.MAX_VELOCITY;
boolean resetDecay = false; boolean resetRelease = false;
boolean resetAttack = false; boolean resetAttack = false;
for (int i = keyOn.nextSetBit(0); i >= 0; i = keyOn.nextSetBit(i + 1)) { for (int i = keyOn.nextSetBit(0); i >= 0; i = keyOn.nextSetBit(i + 1)) {
int noteVolume = keyActualVolumes[i]; int noteVolume = keyActualVolumes[i];
if (lastDecay > decayFrames) { if (lastRelease > releaseFrames) {
resetDecay = true; resetRelease = true;
if (noteVolume > keyTargetVolumes[i]) { if (noteVolume > keyTargetVolumes[i]) {
int newVolume = --keyActualVolumes[i]; int newVolume = --keyActualVolumes[i];
if (newVolume <= 0) { if (newVolume <= 0) {
@ -316,8 +314,8 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
} }
} }
if (resetDecay) { if (resetRelease) {
lastDecay = 0; lastRelease = 0;
} }
if (resetAttack) { if (resetAttack) {
@ -330,7 +328,7 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
keyOnLock.release(); keyOnLock.release();
} }
lastDecay++; lastRelease++;
lastAttack++; lastAttack++;
vector = new Vector2( vector = new Vector2(
@ -359,9 +357,9 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
} }
@Override @Override
public void setDecay(double decaySeconds) { public void setRelease(double releaseSeconds) {
this.decaySeconds = decaySeconds; this.releaseSeconds = releaseSeconds;
updateDecay(); updateRelease();
} }
@Override @Override
@ -528,12 +526,12 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
phase.setSampleRate(sampleRate); phase.setSampleRate(sampleRate);
} }
} }
updateDecay(); updateRelease();
updateAttack(); updateAttack();
} }
private void updateDecay() { private void updateRelease() {
this.decayFrames = (int) (decaySeconds * sampleRate / MidiNote.MAX_VELOCITY); this.releaseFrames = (int) (releaseSeconds * sampleRate / MidiNote.MAX_VELOCITY);
} }
private void updateAttack() { private void updateAttack() {

Wyświetl plik

@ -30,7 +30,6 @@ import java.util.concurrent.*;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -179,7 +178,7 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
@FXML @FXML
private Spinner<Double> attackSpinner; private Spinner<Double> attackSpinner;
@FXML @FXML
private Spinner<Double> decaySpinner; private Spinner<Double> releaseSpinner;
@FXML @FXML
private ComboBox<PrintableSlider> sliderComboBox; private ComboBox<PrintableSlider> sliderComboBox;
@FXML @FXML
@ -491,8 +490,8 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
attackSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, 10, 0.2, 0.01)); attackSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, 10, 0.2, 0.01));
attackSpinner.valueProperty().addListener((o, oldValue, newValue) -> audioPlayer.setAttack(newValue)); attackSpinner.valueProperty().addListener((o, oldValue, newValue) -> audioPlayer.setAttack(newValue));
decaySpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, 10, 0.1, 0.01)); releaseSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, 10, 0.1, 0.01));
decaySpinner.valueProperty().addListener((o, oldValue, newValue) -> audioPlayer.setDecay(newValue)); releaseSpinner.valueProperty().addListener((o, oldValue, newValue) -> audioPlayer.setRelease(newValue));
recordLengthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.1, 100000000, 2.0, 0.1)); recordLengthSpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.1, 100000000, 2.0, 0.1));
@ -1185,7 +1184,7 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
root.appendChild(midiAttack); root.appendChild(midiAttack);
Element midiDecay = document.createElement("midiDecay"); Element midiDecay = document.createElement("midiDecay");
midiDecay.appendChild(document.createTextNode(decaySpinner.getValue().toString())); midiDecay.appendChild(document.createTextNode(releaseSpinner.getValue().toString()));
root.appendChild(midiDecay); root.appendChild(midiDecay);
Element audioSample = document.createElement("audioSample"); Element audioSample = document.createElement("audioSample");
@ -1370,9 +1369,9 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
attackSpinner.getValueFactory().setValue(Double.parseDouble(midiAttack.getTextContent())); attackSpinner.getValueFactory().setValue(Double.parseDouble(midiAttack.getTextContent()));
} }
Element midiDecay = (Element) root.getElementsByTagName("midiDecay").item(0); Element midiRelease = (Element) root.getElementsByTagName("midiDecay").item(0);
if (midiDecay != null) { if (midiRelease != null) {
decaySpinner.getValueFactory().setValue(Double.parseDouble(midiDecay.getTextContent())); releaseSpinner.getValueFactory().setValue(Double.parseDouble(midiRelease.getTextContent()));
} }
Element audioSample = (Element) root.getElementsByTagName("audioSample").item(0); Element audioSample = (Element) root.getElementsByTagName("audioSample").item(0);

Wyświetl plik

@ -139,12 +139,12 @@
</AnchorPane> </AnchorPane>
</content> </content>
</CustomMenuItem> </CustomMenuItem>
<CustomMenuItem hideOnClick="false" mnemonicParsing="false" text="Note Decay (sec)"> <CustomMenuItem hideOnClick="false" mnemonicParsing="false" text="Note Release (sec)">
<content> <content>
<AnchorPane> <AnchorPane>
<children> <children>
<Label prefHeight="25.0" text="Note Decay (sec)" textFill="WHITE" /> <Label prefHeight="25.0" text="Note Release (sec)" textFill="WHITE" />
<Spinner fx:id="decaySpinner" editable="true" layoutY="25.0" /> <Spinner fx:id="releaseSpinner" editable="true" layoutY="25.0" />
</children> </children>
</AnchorPane> </AnchorPane>
</content> </content>