kopia lustrzana https://github.com/jameshball/osci-render
Correctly increase volume gradually for sine effects
rodzic
5bd3c50f1b
commit
9a2d2a9495
|
@ -73,7 +73,7 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
|
|||
private double volume = 1;
|
||||
private double octaveFrequency;
|
||||
private DoubleProperty frequency;
|
||||
private double baseFrequencyVolumeScale = 0.5;
|
||||
private double baseFrequencyVolumeScale = 0.75;
|
||||
private double baseFrequency;
|
||||
private double traceMin = 0;
|
||||
private double traceMax = 1;
|
||||
|
@ -263,10 +263,16 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
|
|||
lastAttack = 0;
|
||||
}
|
||||
lastAttack++;
|
||||
|
||||
double scaledVolume = 1 - baseFrequencyVolumeScale;
|
||||
for (int channel = 0; channel < keysDown.length; channel++) {
|
||||
for (int key = 0; key < keysDown[0].length; key++) {
|
||||
if (keysDown[channel][key] != null && !keysDown[channel][key].equals(baseNote)) {
|
||||
vector = sineEffects[channel][key].apply(frame, vector);
|
||||
if (keyActualVolumes[channel][key] > 0) {
|
||||
Vector2 sine = sineEffects[channel][key].apply(frame, new Vector2());
|
||||
double volume = scaledVolume * keyActualVolumes[channel][key] / MidiNote.MAX_VELOCITY;
|
||||
vector = new Vector2(vector.x + volume * sine.x, vector.y + volume * sine.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -432,7 +438,7 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
|
|||
for (int channel = 0; channel < keyActualVolumes.length; channel++) {
|
||||
for (int key = 0; key < keyActualVolumes[channel].length; key++) {
|
||||
MidiNote note = new MidiNote(key, channel);
|
||||
sineEffects[channel][key] = new SineEffect(sampleRate, note.frequency(), (float) keyActualVolumes[channel][key] / MidiNote.MAX_VELOCITY);
|
||||
sineEffects[channel][key] = new SineEffect(sampleRate, note.frequency());
|
||||
}
|
||||
}
|
||||
for (Effect effect : effects.values()) {
|
||||
|
@ -482,23 +488,13 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
|
|||
}
|
||||
|
||||
private void updateSineEffects() {
|
||||
double totalVolume = 0;
|
||||
for (short[] volumes : keyActualVolumes) {
|
||||
for (short volume : volumes) {
|
||||
totalVolume += (float) volume / MidiNote.MAX_VELOCITY;
|
||||
}
|
||||
}
|
||||
if (totalVolume != 0) {
|
||||
double scaledVolume = (1 - baseFrequencyVolumeScale) / totalVolume;
|
||||
for (int channel = 0; channel < keyActualVolumes.length; channel++) {
|
||||
for (int key = 0; key < keyActualVolumes[channel].length; key++) {
|
||||
MidiNote note = new MidiNote(key, channel);
|
||||
if (keyActualVolumes[channel][key] > 0) {
|
||||
SineEffect effect = sineEffects[channel][key];
|
||||
if (effect != null) {
|
||||
effect.setVolume(scaledVolume * keyActualVolumes[channel][key] / MidiNote.MAX_VELOCITY);
|
||||
effect.setFrequency(note.frequency() * pitchBends[channel]);
|
||||
}
|
||||
for (int channel = 0; channel < keyActualVolumes.length; channel++) {
|
||||
for (int key = 0; key < keyActualVolumes[channel].length; key++) {
|
||||
MidiNote note = new MidiNote(key, channel);
|
||||
if (keyActualVolumes[channel][key] > 0) {
|
||||
SineEffect effect = sineEffects[channel][key];
|
||||
if (effect != null) {
|
||||
effect.setFrequency(note.frequency() * pitchBends[channel]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -511,7 +507,6 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
|
|||
MidiNote note = new MidiNote(key, mainChannel);
|
||||
frequency.set(note.frequency());
|
||||
baseNote = note;
|
||||
updateSineEffects();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Slider fx:id="visibilitySlider" blockIncrement="0.005" layoutX="106.0" layoutY="266.0" majorTickUnit="0.1" max="1.0" prefHeight="42.0" prefWidth="253.0" showTickLabels="true" showTickMarks="true" value="0.5" />
|
||||
<Slider fx:id="visibilitySlider" blockIncrement="0.005" layoutX="106.0" layoutY="266.0" majorTickUnit="0.1" max="1.0" prefHeight="42.0" prefWidth="253.0" showTickLabels="true" showTickMarks="true" value="0.75" />
|
||||
<SVGPath fx:id="visibilityMidi" content="M20.15 8.26H22V15.74H20.15M13 8.26H18.43C19 8.26 19.3 8.74 19.3 9.3V14.81C19.3 15.5 19 15.74 18.38 15.74H13V11H14.87V13.91H17.5V9.95H13M10.32 8.26H12.14V15.74H10.32M2 8.26H8.55C9.1 8.26 9.41 8.74 9.41 9.3V15.74H7.59V10.15H6.5V15.74H4.87V10.15H3.83V15.74H2Z" fill="WHITE" layoutX="361.0" layoutY="263.0" pickOnBounds="true" />
|
||||
<CheckBox fx:id="translateCheckBox" layoutX="137.0" layoutY="43.0" mnemonicParsing="false" text="Translate with Mouse (Esc to disable)" />
|
||||
<Slider fx:id="translationScaleSlider" blockIncrement="0.05" layoutX="105.0" layoutY="73.0" majorTickUnit="1.0" max="10.0" prefHeight="42.0" prefWidth="254.0" showTickLabels="true" showTickMarks="true" value="1.0" />
|
||||
|
|
Ładowanie…
Reference in New Issue