5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.sun.media.sound;
26
27 import java.io.IOException;
28 import java.util.Arrays;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import javax.sound.midi.VoiceStatus;
33
34 /**
35 * Software synthesizer voice class.
36 *
37 * @author Karl Helgason
38 */
39 public final class SoftVoice extends VoiceStatus {
40
41 public int exclusiveClass = 0;
42 public boolean releaseTriggered = false;
43 private int noteOn_noteNumber = 0;
44 private int noteOn_velocity = 0;
46 private int delay = 0;
47 ModelChannelMixer channelmixer = null;
48 double tunedKey = 0;
49 SoftTuning tuning = null;
50 SoftChannel stealer_channel = null;
51 ModelConnectionBlock[] stealer_extendedConnectionBlocks = null;
52 SoftPerformer stealer_performer = null;
53 ModelChannelMixer stealer_channelmixer = null;
54 int stealer_voiceID = -1;
55 int stealer_noteNumber = 0;
56 int stealer_velocity = 0;
57 boolean stealer_releaseTriggered = false;
58 int voiceID = -1;
59 boolean sustain = false;
60 boolean sostenuto = false;
61 boolean portamento = false;
62 private final SoftFilter filter_left;
63 private final SoftFilter filter_right;
64 private final SoftProcess eg = new SoftEnvelopeGenerator();
65 private final SoftProcess lfo = new SoftLowFrequencyOscillator();
66 Map<String, SoftControl> objects =
67 new HashMap<String, SoftControl>();
68 SoftSynthesizer synthesizer;
69 SoftInstrument instrument;
70 SoftPerformer performer;
71 SoftChannel softchannel = null;
72 boolean on = false;
73 private boolean audiostarted = false;
74 private boolean started = false;
75 private boolean stopping = false;
76 private float osc_attenuation = 0.0f;
77 private ModelOscillatorStream osc_stream;
78 private int osc_stream_nrofchannels;
79 private float[][] osc_buff = new float[2][];
80 private boolean osc_stream_off_transmitted = false;
81 private boolean out_mixer_end = false;
82 private float out_mixer_left = 0;
83 private float out_mixer_right = 0;
84 private float out_mixer_effect1 = 0;
85 private float out_mixer_effect2 = 0;
86 private float last_out_mixer_left = 0;
87 private float last_out_mixer_right = 0;
90 ModelConnectionBlock[] extendedConnectionBlocks = null;
91 private ModelConnectionBlock[] connections;
92 // Last value added to destination
93 private double[] connections_last = new double[50];
94 // Pointer to source value
95 private double[][][] connections_src = new double[50][3][];
96 // Key-based override (if any)
97 private int[][] connections_src_kc = new int[50][3];
98 // Pointer to destination value
99 private double[][] connections_dst = new double[50][];
100 private boolean soundoff = false;
101 private float lastMuteValue = 0;
102 private float lastSoloMuteValue = 0;
103 double[] co_noteon_keynumber = new double[1];
104 double[] co_noteon_velocity = new double[1];
105 double[] co_noteon_on = new double[1];
106 private final SoftControl co_noteon = new SoftControl() {
107 double[] keynumber = co_noteon_keynumber;
108 double[] velocity = co_noteon_velocity;
109 double[] on = co_noteon_on;
110 public double[] get(int instance, String name) {
111 if (name == null)
112 return null;
113 if (name.equals("keynumber"))
114 return keynumber;
115 if (name.equals("velocity"))
116 return velocity;
117 if (name.equals("on"))
118 return on;
119 return null;
120 }
121 };
122 private final double[] co_mixer_active = new double[1];
123 private final double[] co_mixer_gain = new double[1];
124 private final double[] co_mixer_pan = new double[1];
125 private final double[] co_mixer_balance = new double[1];
126 private final double[] co_mixer_reverb = new double[1];
127 private final double[] co_mixer_chorus = new double[1];
128 private final SoftControl co_mixer = new SoftControl() {
129 double[] active = co_mixer_active;
130 double[] gain = co_mixer_gain;
131 double[] pan = co_mixer_pan;
132 double[] balance = co_mixer_balance;
133 double[] reverb = co_mixer_reverb;
134 double[] chorus = co_mixer_chorus;
135 public double[] get(int instance, String name) {
136 if (name == null)
137 return null;
138 if (name.equals("active"))
139 return active;
140 if (name.equals("gain"))
141 return gain;
142 if (name.equals("pan"))
143 return pan;
144 if (name.equals("balance"))
145 return balance;
146 if (name.equals("reverb"))
147 return reverb;
148 if (name.equals("chorus"))
149 return chorus;
150 return null;
151 }
152 };
153 private final double[] co_osc_pitch = new double[1];
154 private final SoftControl co_osc = new SoftControl() {
155 double[] pitch = co_osc_pitch;
156 public double[] get(int instance, String name) {
157 if (name == null)
158 return null;
159 if (name.equals("pitch"))
160 return pitch;
161 return null;
162 }
163 };
164 private final double[] co_filter_freq = new double[1];
165 private final double[] co_filter_type = new double[1];
166 private final double[] co_filter_q = new double[1];
167 private final SoftControl co_filter = new SoftControl() {
168 double[] freq = co_filter_freq;
169 double[] ftype = co_filter_type;
170 double[] q = co_filter_q;
171 public double[] get(int instance, String name) {
172 if (name == null)
173 return null;
174 if (name.equals("freq"))
175 return freq;
176 if (name.equals("type"))
177 return ftype;
178 if (name.equals("q"))
179 return q;
180 return null;
181 }
182 };
183 SoftResamplerStreamer resampler;
184 private final int nrofchannels;
185
186 public SoftVoice(SoftSynthesizer synth) {
187 synthesizer = synth;
188 filter_left = new SoftFilter(synth.getFormat().getSampleRate());
189 filter_right = new SoftFilter(synth.getFormat().getSampleRate());
190 nrofchannels = synth.getFormat().getChannels();
896 out_mixer_effect2);
897 } else {
898 mixAudioStream(leftdry, eff1, deff1, last_out_mixer_effect1 * 0.5f,
899 out_mixer_effect1 * 0.5f);
900 mixAudioStream(leftdry, eff2, deff2, last_out_mixer_effect2 * 0.5f,
901 out_mixer_effect2 * 0.5f);
902 mixAudioStream(rightdry, eff1, deff1, last_out_mixer_effect1 * 0.5f,
903 out_mixer_effect1 * 0.5f);
904 mixAudioStream(rightdry, eff2, deff2, last_out_mixer_effect2 * 0.5f,
905 out_mixer_effect2 * 0.5f);
906 }
907
908 last_out_mixer_left = out_mixer_left;
909 last_out_mixer_right = out_mixer_right;
910 last_out_mixer_effect1 = out_mixer_effect1;
911 last_out_mixer_effect2 = out_mixer_effect2;
912
913 if (out_mixer_end) {
914 stopping = true;
915 }
916
917 }
918 }
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.media.sound;
27
28 import java.io.IOException;
29 import java.util.Arrays;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import javax.sound.midi.VoiceStatus;
34
35 /**
36 * Software synthesizer voice class.
37 *
38 * @author Karl Helgason
39 */
40 public final class SoftVoice extends VoiceStatus {
41
42 public int exclusiveClass = 0;
43 public boolean releaseTriggered = false;
44 private int noteOn_noteNumber = 0;
45 private int noteOn_velocity = 0;
47 private int delay = 0;
48 ModelChannelMixer channelmixer = null;
49 double tunedKey = 0;
50 SoftTuning tuning = null;
51 SoftChannel stealer_channel = null;
52 ModelConnectionBlock[] stealer_extendedConnectionBlocks = null;
53 SoftPerformer stealer_performer = null;
54 ModelChannelMixer stealer_channelmixer = null;
55 int stealer_voiceID = -1;
56 int stealer_noteNumber = 0;
57 int stealer_velocity = 0;
58 boolean stealer_releaseTriggered = false;
59 int voiceID = -1;
60 boolean sustain = false;
61 boolean sostenuto = false;
62 boolean portamento = false;
63 private final SoftFilter filter_left;
64 private final SoftFilter filter_right;
65 private final SoftProcess eg = new SoftEnvelopeGenerator();
66 private final SoftProcess lfo = new SoftLowFrequencyOscillator();
67 final Map<String, SoftControl> objects = new HashMap<>();
68 SoftSynthesizer synthesizer;
69 SoftInstrument instrument;
70 SoftPerformer performer;
71 SoftChannel softchannel = null;
72 boolean on = false;
73 private boolean audiostarted = false;
74 private boolean started = false;
75 private boolean stopping = false;
76 private float osc_attenuation = 0.0f;
77 private ModelOscillatorStream osc_stream;
78 private int osc_stream_nrofchannels;
79 private float[][] osc_buff = new float[2][];
80 private boolean osc_stream_off_transmitted = false;
81 private boolean out_mixer_end = false;
82 private float out_mixer_left = 0;
83 private float out_mixer_right = 0;
84 private float out_mixer_effect1 = 0;
85 private float out_mixer_effect2 = 0;
86 private float last_out_mixer_left = 0;
87 private float last_out_mixer_right = 0;
90 ModelConnectionBlock[] extendedConnectionBlocks = null;
91 private ModelConnectionBlock[] connections;
92 // Last value added to destination
93 private double[] connections_last = new double[50];
94 // Pointer to source value
95 private double[][][] connections_src = new double[50][3][];
96 // Key-based override (if any)
97 private int[][] connections_src_kc = new int[50][3];
98 // Pointer to destination value
99 private double[][] connections_dst = new double[50][];
100 private boolean soundoff = false;
101 private float lastMuteValue = 0;
102 private float lastSoloMuteValue = 0;
103 double[] co_noteon_keynumber = new double[1];
104 double[] co_noteon_velocity = new double[1];
105 double[] co_noteon_on = new double[1];
106 private final SoftControl co_noteon = new SoftControl() {
107 double[] keynumber = co_noteon_keynumber;
108 double[] velocity = co_noteon_velocity;
109 double[] on = co_noteon_on;
110 @Override
111 public double[] get(int instance, String name) {
112 if (name == null)
113 return null;
114 if (name.equals("keynumber"))
115 return keynumber;
116 if (name.equals("velocity"))
117 return velocity;
118 if (name.equals("on"))
119 return on;
120 return null;
121 }
122 };
123 private final double[] co_mixer_active = new double[1];
124 private final double[] co_mixer_gain = new double[1];
125 private final double[] co_mixer_pan = new double[1];
126 private final double[] co_mixer_balance = new double[1];
127 private final double[] co_mixer_reverb = new double[1];
128 private final double[] co_mixer_chorus = new double[1];
129 private final SoftControl co_mixer = new SoftControl() {
130 final double[] active = co_mixer_active;
131 final double[] gain = co_mixer_gain;
132 final double[] pan = co_mixer_pan;
133 final double[] balance = co_mixer_balance;
134 final double[] reverb = co_mixer_reverb;
135 final double[] chorus = co_mixer_chorus;
136 @Override
137 public double[] get(int instance, String name) {
138 if (name == null)
139 return null;
140 if (name.equals("active"))
141 return active;
142 if (name.equals("gain"))
143 return gain;
144 if (name.equals("pan"))
145 return pan;
146 if (name.equals("balance"))
147 return balance;
148 if (name.equals("reverb"))
149 return reverb;
150 if (name.equals("chorus"))
151 return chorus;
152 return null;
153 }
154 };
155 private final double[] co_osc_pitch = new double[1];
156 private final SoftControl co_osc = new SoftControl() {
157 final double[] pitch = co_osc_pitch;
158 @Override
159 public double[] get(int instance, String name) {
160 if (name == null)
161 return null;
162 if (name.equals("pitch"))
163 return pitch;
164 return null;
165 }
166 };
167 private final double[] co_filter_freq = new double[1];
168 private final double[] co_filter_type = new double[1];
169 private final double[] co_filter_q = new double[1];
170 private final SoftControl co_filter = new SoftControl() {
171 final double[] freq = co_filter_freq;
172 final double[] ftype = co_filter_type;
173 final double[] q = co_filter_q;
174 @Override
175 public double[] get(int instance, String name) {
176 if (name == null)
177 return null;
178 if (name.equals("freq"))
179 return freq;
180 if (name.equals("type"))
181 return ftype;
182 if (name.equals("q"))
183 return q;
184 return null;
185 }
186 };
187 SoftResamplerStreamer resampler;
188 private final int nrofchannels;
189
190 public SoftVoice(SoftSynthesizer synth) {
191 synthesizer = synth;
192 filter_left = new SoftFilter(synth.getFormat().getSampleRate());
193 filter_right = new SoftFilter(synth.getFormat().getSampleRate());
194 nrofchannels = synth.getFormat().getChannels();
900 out_mixer_effect2);
901 } else {
902 mixAudioStream(leftdry, eff1, deff1, last_out_mixer_effect1 * 0.5f,
903 out_mixer_effect1 * 0.5f);
904 mixAudioStream(leftdry, eff2, deff2, last_out_mixer_effect2 * 0.5f,
905 out_mixer_effect2 * 0.5f);
906 mixAudioStream(rightdry, eff1, deff1, last_out_mixer_effect1 * 0.5f,
907 out_mixer_effect1 * 0.5f);
908 mixAudioStream(rightdry, eff2, deff2, last_out_mixer_effect2 * 0.5f,
909 out_mixer_effect2 * 0.5f);
910 }
911
912 last_out_mixer_left = out_mixer_left;
913 last_out_mixer_right = out_mixer_right;
914 last_out_mixer_effect1 = out_mixer_effect1;
915 last_out_mixer_effect2 = out_mixer_effect2;
916
917 if (out_mixer_end) {
918 stopping = true;
919 }
920 }
921 }
|