提交 7c2f1d9e 编写于 作者: K kalli

6941027: Gervill update, April 2010

Reviewed-by: amenkov
上级 557a5a33
......@@ -175,7 +175,6 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
for (int c = 0; c < targetChannels; c++) {
for (int i = 0, ix = off + c; i < len2; i++, ix += cs) {
b[ix] = conversion_buffer[i];
;
}
}
} else if (targetChannels == 1) {
......@@ -186,7 +185,6 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
for (int c = 1; c < sourceChannels; c++) {
for (int i = c, ix = off; i < len2; i += cs, ix++) {
b[ix] += conversion_buffer[i];
;
}
}
float vol = 1f / ((float) sourceChannels);
......@@ -390,6 +388,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
return -1;
if (len < 0)
return 0;
int offlen = off + len;
int remain = len / nrofchannels;
int destPos = 0;
int in_end = ibuffer_len;
......@@ -423,7 +422,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
for (int c = 0; c < nrofchannels; c++) {
int ix = 0;
float[] buff = cbuffer[c];
for (int i = c; i < b.length; i += nrofchannels) {
for (int i = c + off; i < offlen; i += nrofchannels) {
b[i] = buff[ix++];
}
}
......@@ -447,7 +446,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
}
public long skip(long len) throws IOException {
if (len > 0)
if (len < 0)
return 0;
if (skipbuffer == null)
skipbuffer = new float[1024 * targetFormat.getFrameSize()];
......
......@@ -42,11 +42,14 @@ public class AudioSynthesizerPropertyInfo {
*/
public AudioSynthesizerPropertyInfo(String name, Object value) {
this.name = name;
this.value = value;
if (value instanceof Class)
valueClass = (Class)value;
else if (value != null)
valueClass = value.getClass();
else
{
this.value = value;
if (value != null)
valueClass = value.getClass();
}
}
/**
* The name of the property.
......
......@@ -205,7 +205,8 @@ public class ModelByteBufferWavetable implements ModelWavetable {
}
if (buffer.array() == null) {
return AudioFloatInputStream.getInputStream(new AudioInputStream(
buffer.getInputStream(), format, buffer.capacity()));
buffer.getInputStream(), format,
buffer.capacity() / format.getFrameSize()));
}
if (buffer8 != null) {
if (format.getEncoding().equals(Encoding.PCM_SIGNED)
......
......@@ -56,7 +56,7 @@ public abstract class ModelInstrument extends Instrument {
public ModelDirector getDirector(ModelPerformer[] performers,
MidiChannel channel, ModelDirectedPlayer player) {
return new ModelStandardDirector(performers, player);
return new ModelStandardIndexedDirector(performers, player);
}
public ModelPerformer[] getPerformers() {
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.media.sound;
/**
* A standard indexed director who chooses performers
* by there keyfrom,keyto,velfrom,velto properties.
*
* @author Karl Helgason
*/
public class ModelStandardIndexedDirector implements ModelDirector {
ModelPerformer[] performers;
ModelDirectedPlayer player;
boolean noteOnUsed = false;
boolean noteOffUsed = false;
// Variables needed for index
byte[][] trantables;
int[] counters;
int[][] mat;
public ModelStandardIndexedDirector(ModelPerformer[] performers,
ModelDirectedPlayer player) {
this.performers = performers;
this.player = player;
for (int i = 0; i < performers.length; i++) {
ModelPerformer p = performers[i];
if (p.isReleaseTriggered()) {
noteOffUsed = true;
} else {
noteOnUsed = true;
}
}
buildindex();
}
private int[] lookupIndex(int x, int y)
{
if ((x >= 0) && (x < 128) && (y >= 0) && (y < 128)) {
int xt = trantables[0][x];
int yt = trantables[1][y];
if (xt != -1 && yt != -1) {
return mat[xt + yt * counters[0]];
}
}
return null;
}
private void buildindex() {
trantables = new byte[2][129];
counters = new int[trantables.length];
for (ModelPerformer performer : performers) {
trantables[0][performer.getKeyFrom()] = 1;
trantables[0][performer.getKeyTo() + 1] = 1;
trantables[1][performer.getVelFrom()] = 1;
trantables[1][performer.getVelTo() + 1] = 1;
}
for (int d = 0; d < trantables.length; d++) {
byte[] trantable = trantables[d];
int transize = trantable.length;
for (int i = transize - 1; i >= 0; i--) {
if (trantable[i] == 1) {
trantable[i] = -1;
break;
}
trantable[i] = -1;
}
int counter = -1;
for (int i = 0; i < transize; i++) {
if (trantable[i] != 0) {
counter++;
if (trantable[i] == -1)
break;
}
trantable[i] = (byte) counter;
}
counters[d] = counter;
}
mat = new int[counters[0] * counters[1]][];
int ix = 0;
for (ModelPerformer performer : performers) {
int x_from = trantables[0][performer.getKeyFrom()];
int x_to = trantables[0][performer.getKeyTo() + 1];
int y_from = trantables[1][performer.getVelFrom()];
int y_to = trantables[1][performer.getVelTo() + 1];
if (x_to == -1)
x_to = counters[0];
if (y_to == -1)
y_to = counters[1];
for (int y = y_from; y < y_to; y++) {
int i = x_from + y * counters[0];
for (int x = x_from; x < x_to; x++) {
int[] mprev = mat[i];
if (mprev == null) {
mat[i] = new int[] { ix };
} else {
int[] mnew = new int[mprev.length + 1];
mnew[mnew.length - 1] = ix;
for (int k = 0; k < mprev.length; k++)
mnew[k] = mprev[k];
mat[i] = mnew;
}
i++;
}
}
ix++;
}
}
public void close() {
}
public void noteOff(int noteNumber, int velocity) {
if (!noteOffUsed)
return;
int[] plist = lookupIndex(noteNumber, velocity);
if(plist == null) return;
for (int i : plist) {
ModelPerformer p = performers[i];
if (p.isReleaseTriggered()) {
player.play(i, null);
}
}
}
public void noteOn(int noteNumber, int velocity) {
if (!noteOnUsed)
return;
int[] plist = lookupIndex(noteNumber, velocity);
if(plist == null) return;
for (int i : plist) {
ModelPerformer p = performers[i];
if (!p.isReleaseTriggered()) {
player.play(i, null);
}
}
}
}
/*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -116,7 +116,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
protected int tuning_program = 0;
protected SoftInstrument current_instrument = null;
protected ModelChannelMixer current_mixer = null;
private ModelDirector current_director = null;
protected ModelDirector current_director = null;
// Controller Destination Settings
protected int cds_control_number = -1;
......@@ -1268,9 +1268,12 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
program = restrict7Bit(program);
synchronized (control_mutex) {
mainmixer.activity();
this.bank = bank;
this.program = program;
current_instrument = null;
if(this.bank != bank || this.program != program)
{
this.bank = bank;
this.program = program;
current_instrument = null;
}
}
}
......
......@@ -279,9 +279,12 @@ public class SoftVoice extends VoiceStatus {
}
protected void updateTuning(SoftTuning newtuning) {
tuning = newtuning;
tunedKey = tuning.getTuning(note) / 100.0;
if (!portamento) {
co_noteon_keynumber[0] = tunedKey * (1.0 / 128.0);
if(performer == null)
return;
int[] c = performer.midi_connections[4];
if (c == null)
return;
......@@ -433,6 +436,8 @@ public class SoftVoice extends VoiceStatus {
}
protected void setPolyPressure(int pressure) {
if(performer == null)
return;
int[] c = performer.midi_connections[2];
if (c == null)
return;
......@@ -441,6 +446,8 @@ public class SoftVoice extends VoiceStatus {
}
protected void setChannelPressure(int pressure) {
if(performer == null)
return;
int[] c = performer.midi_connections[1];
if (c == null)
return;
......@@ -449,6 +456,8 @@ public class SoftVoice extends VoiceStatus {
}
protected void controlChange(int controller, int value) {
if(performer == null)
return;
int[] c = performer.midi_ctrl_connections[controller];
if (c == null)
return;
......@@ -457,6 +466,8 @@ public class SoftVoice extends VoiceStatus {
}
protected void nrpnChange(int controller, int value) {
if(performer == null)
return;
int[] c = performer.midi_nrpn_connections.get(controller);
if (c == null)
return;
......@@ -465,6 +476,8 @@ public class SoftVoice extends VoiceStatus {
}
protected void rpnChange(int controller, int value) {
if(performer == null)
return;
int[] c = performer.midi_rpn_connections.get(controller);
if (c == null)
return;
......@@ -473,6 +486,8 @@ public class SoftVoice extends VoiceStatus {
}
protected void setPitchBend(int bend) {
if(performer == null)
return;
int[] c = performer.midi_connections[0];
if (c == null)
return;
......@@ -499,6 +514,8 @@ public class SoftVoice extends VoiceStatus {
co_noteon_on[0] = -1;
if(performer == null)
return;
int[] c = performer.midi_connections[3];
if (c == null)
return;
......@@ -527,6 +544,8 @@ public class SoftVoice extends VoiceStatus {
co_noteon_on[0] = 0;
if(performer == null)
return;
int[] c = performer.midi_connections[3];
if (c == null)
return;
......@@ -543,6 +562,8 @@ public class SoftVoice extends VoiceStatus {
sustain = true;
co_noteon_on[0] = 1;
if(performer == null)
return;
int[] c = performer.midi_connections[3];
if (c == null)
return;
......@@ -555,6 +576,11 @@ public class SoftVoice extends VoiceStatus {
active = false;
stopping = false;
audiostarted = false;
instrument = null;
performer = null;
connections = null;
extendedConnectionBlocks = null;
channelmixer = null;
if (osc_stream != null)
try {
osc_stream.close();
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@summary Test skip method returned from AudioFloatFormatConverter.getAudioInputStream */
import java.io.ByteArrayInputStream;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import com.sun.media.sound.AudioFloatFormatConverter;
public class SkipTest {
public static void main(String[] args) throws Exception {
AudioFloatFormatConverter converter = new AudioFloatFormatConverter();
byte[] data = { 10, 20, 30, 40, 30, 20, 10 };
AudioFormat format = new AudioFormat(8000, 8, 1, true, false);
AudioFormat format2 = new AudioFormat(16000, 8, 1, true, false);
AudioInputStream ais = new AudioInputStream(new ByteArrayInputStream(
data), format, data.length);
AudioInputStream ais2 = converter.getAudioInputStream(format2, ais);
byte[] data2 = new byte[30];
int ret = ais2.read(data2, 0, data2.length);
ais.reset();
AudioInputStream ais3 = converter.getAudioInputStream(format2, ais);
byte[] data3 = new byte[100];
ais3.skip(7);
int ret2 = ais3.read(data3, 7, data3.length);
if (ret2 != ret - 7)
throw new Exception("Skip doesn't work correctly (" + ret2 + " != "
+ (ret - 7) + ")");
for (int i = 7; i < ret2 + 7; i++) {
if (data3[i] != data2[i])
throw new Exception("Skip doesn't work correctly (" + data3[i]
+ " != " + data2[i] + ")");
}
}
}
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@summary Test AudioFloatInputStream.getFrameLength() returned from
ModelByteBufferWavetable openStream method */
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import javax.sound.sampled.*;
import com.sun.media.sound.*;
public class OpenStream {
static float[] testarray;
static byte[] test_byte_array;
static byte[] test_byte_array_8ext;
static AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
static AudioFormat format24 = new AudioFormat(44100, 24, 1, true, false);
static ModelByteBuffer buffer;
static ModelByteBuffer buffer_wave;
static ModelByteBuffer buffer8;
static ModelByteBuffer buffer16_8;
static ModelByteBuffer buffer24;
static File test_file;
static ModelByteBuffer buffer_wave_ondisk;
static void setUp() throws Exception {
testarray = new float[1024];
for (int i = 0; i < 1024; i++) {
double ii = i / 1024.0;
ii = ii * ii;
testarray[i] = (float) Math.sin(10 * ii * 2 * Math.PI);
testarray[i] += (float) Math.sin(1.731 + 2 * ii * 2 * Math.PI);
testarray[i] += (float) Math.sin(0.231 + 6.3 * ii * 2 * Math.PI);
testarray[i] *= 0.3;
}
test_byte_array = new byte[testarray.length * 2];
AudioFloatConverter.getConverter(format).toByteArray(testarray,
test_byte_array);
buffer = new ModelByteBuffer(test_byte_array);
byte[] test_byte_array2 = new byte[testarray.length * 3];
buffer24 = new ModelByteBuffer(test_byte_array2);
test_byte_array_8ext = new byte[testarray.length];
byte[] test_byte_array_8_16 = new byte[testarray.length * 2];
AudioFloatConverter.getConverter(format24).toByteArray(testarray,
test_byte_array2);
int ix = 0;
int x = 0;
for (int i = 0; i < test_byte_array_8ext.length; i++) {
test_byte_array_8ext[i] = test_byte_array2[ix++];
test_byte_array_8_16[x++] = test_byte_array2[ix++];
test_byte_array_8_16[x++] = test_byte_array2[ix++];
}
buffer16_8 = new ModelByteBuffer(test_byte_array_8_16);
buffer8 = new ModelByteBuffer(test_byte_array_8ext);
AudioInputStream ais = new AudioInputStream(buffer.getInputStream(),
format, testarray.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
AudioSystem.write(ais, AudioFileFormat.Type.WAVE, baos);
buffer_wave = new ModelByteBuffer(baos.toByteArray());
test_file = File.createTempFile("test", ".raw");
FileOutputStream fos = new FileOutputStream(test_file);
fos.write(baos.toByteArray());
fos.close();
buffer_wave_ondisk = new ModelByteBuffer(test_file);
}
static void tearDown() throws Exception {
if (!test_file.delete())
test_file.deleteOnExit();
}
public static void testOpenStream(ModelByteBufferWavetable wavetable)
throws Exception {
AudioFloatInputStream ais = wavetable.openStream();
long frames = wavetable.getBuffer().capacity()
/ wavetable.getFormat().getFrameSize();
long framelength = ais.getFrameLength();
ais.close();
if (frames != framelength) {
throw new Exception("Incorrect framelength returned (" + frames
+ " != " + framelength + ")");
}
}
public static void main(String[] args) throws Exception {
setUp();
try {
testOpenStream(new ModelByteBufferWavetable(buffer, format));
testOpenStream(new ModelByteBufferWavetable(buffer_wave, format));
testOpenStream(new ModelByteBufferWavetable(buffer_wave_ondisk,
format));
} finally {
tearDown();
}
}
}
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@summary Test SoftSynthesizer getAvailableInstruments method */
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
import javax.sound.sampled.*;
import javax.sound.midi.MidiDevice.Info;
import com.sun.media.sound.*;
public class GetAvailableInstruments2 {
private static void assertEquals(Object a, Object b) throws Exception {
if (!a.equals(b))
throw new RuntimeException("assertEquals fails!");
}
private static void assertTrue(boolean value) throws Exception {
if (!value)
throw new RuntimeException("assertTrue fails!");
}
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
synth.openStream(null, null);
Soundbank defsbk = synth.getDefaultSoundbank();
if (defsbk != null) {
synth.unloadAllInstruments(defsbk);
assertTrue(defsbk.getInstruments().length == synth
.getAvailableInstruments().length);
}
synth.close();
}
}
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@summary Test SoftSynthesizer getLoadedInstruments method */
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
import javax.sound.sampled.*;
import javax.sound.midi.MidiDevice.Info;
import com.sun.media.sound.*;
public class GetLoadedInstruments2 {
private static void assertEquals(Object a, Object b) throws Exception {
if (!a.equals(b))
throw new RuntimeException("assertEquals fails!");
}
private static void assertTrue(boolean value) throws Exception {
if (!value)
throw new RuntimeException("assertTrue fails!");
}
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
synth.openStream(null, null);
Soundbank defsbk = synth.getDefaultSoundbank();
if (defsbk != null) {
assertTrue(defsbk.getInstruments().length == synth
.getLoadedInstruments().length);
}
synth.close();
}
}
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@summary Test SoftSynthesizer getPropertyInfo method */
import java.util.HashMap;
import java.util.Map;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
import javax.sound.sampled.*;
import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.midi.MidiDevice.Info;
import com.sun.media.sound.*;
public class GetPropertyInfo {
private static void assertTrue(boolean value) throws Exception {
if (!value)
throw new RuntimeException("assertTrue fails!");
}
public static void main(String[] args) throws Exception {
SoftSynthesizer synth = new SoftSynthesizer();
Map<String, Object> p = new HashMap<String, Object>();
p.put("format", "8000 HZ 24 BIT MONO UNSIGNED BIG-ENDIAN");
p.put("control rate", 125);
p.put("reverb", false);
p.put("auto gain control", "false");
AudioSynthesizerPropertyInfo[] ap = synth.getPropertyInfo(p);
for (int i = 0; i < ap.length; i++) {
if (ap[i].name.equals("control rate"))
assertTrue(Math.abs((Float) ap[i].value - 125.0) < 0.001);
if (ap[i].name.equals("reverb"))
assertTrue((Boolean) ap[i].value == false);
if (ap[i].name.equals("auto gain control"))
assertTrue((Boolean) ap[i].value == false);
if (ap[i].name.equals("format")) {
AudioFormat format = (AudioFormat) ap[i].value;
assertTrue(format.getChannels() == 1);
assertTrue(format.getSampleSizeInBits() == 24);
assertTrue(format.isBigEndian());
assertTrue(Math.abs(format.getSampleRate() - 8000) < 0.001);
assertTrue(format.getEncoding() == Encoding.PCM_UNSIGNED);
}
}
p = new HashMap<String, Object>();
p.put("format", "9000 Hz, 8 bit, 4 channels");
ap = synth.getPropertyInfo(p);
for (int i = 0; i < ap.length; i++) {
if (ap[i].name.equals("format")) {
AudioFormat format = (AudioFormat) ap[i].value;
assertTrue(format.getChannels() == 4);
assertTrue(format.getSampleSizeInBits() == 8);
assertTrue(!format.isBigEndian());
assertTrue(Math.abs(format.getSampleRate() - 9000) < 0.001);
assertTrue(format.getEncoding() == Encoding.PCM_SIGNED);
}
}
p = new HashMap<String, Object>();
p.put("format", "PCM_UNSIGNED 44100.0 Hz, 16 bit, 3 channels, 6 bytes/frame, big-endian");
ap = synth.getPropertyInfo(p);
for (int i = 0; i < ap.length; i++) {
if (ap[i].name.equals("format")) {
AudioFormat format = (AudioFormat) ap[i].value;
assertTrue(format.getChannels() == 3);
assertTrue(format.getSampleSizeInBits() == 16);
assertTrue(format.isBigEndian());
assertTrue(Math.abs(format.getSampleRate() - 44100) < 0.001);
assertTrue(format.getEncoding() == Encoding.PCM_UNSIGNED);
}
}
}
}
......@@ -55,7 +55,6 @@ public class LoadAllInstruments {
Soundbank defsbk = synth.getDefaultSoundbank();
if(defsbk != null)
{
assertTrue(synth.getLoadedInstruments().length == 0);
synth.unloadAllInstruments(defsbk);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
......
......@@ -55,7 +55,6 @@ public class LoadInstrument {
Soundbank defsbk = synth.getDefaultSoundbank();
if(defsbk != null)
{
assertTrue(synth.getLoadedInstruments().length == 0);
synth.unloadAllInstruments(defsbk);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
......
......@@ -55,7 +55,6 @@ public class LoadInstruments {
Soundbank defsbk = synth.getDefaultSoundbank();
if(defsbk != null)
{
assertTrue(synth.getLoadedInstruments().length == 0);
synth.unloadAllInstruments(defsbk);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
......
......@@ -56,15 +56,15 @@ public class RemapInstrument {
Soundbank defsbk = synth.getDefaultSoundbank();
if(defsbk != null)
{
Instrument ins0 = defsbk.getInstrument(new Patch(0,0));
Instrument ins3 = defsbk.getInstrument(new Patch(0,3));
Instrument ins10 = defsbk.getInstrument(new Patch(0,10));
assertTrue(synth.remapInstrument(ins0, ins10));
assertTrue(synth.remapInstrument(ins3, ins10));
Instrument[] loaded = synth.getLoadedInstruments();
for (int i = 0; i < loaded.length; i++) {
if(loaded[i].getPatch().getBank() == 0)
if(loaded[i].getPatch().getProgram() == 10)
if(loaded[i].getPatch().getBank() == ins3.getPatch().getBank())
if(loaded[i].getPatch().getProgram() == ins3.getPatch().getProgram())
{
assertEquals(loaded[i].getName(), ins0.getName());
assertEquals(loaded[i].getName(), ins10.getName());
break;
}
}
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@summary Test Disable/enable loading default soundbank in SoftSynthesizer */
import java.util.HashMap;
import java.util.Map;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Patch;
import javax.sound.midi.Soundbank;
import javax.sound.sampled.*;
import javax.sound.midi.MidiDevice.Info;
import com.sun.media.sound.*;
public class TestDisableLoadDefaultSoundbank {
private static void assertEquals(Object a, Object b) throws Exception {
if (!a.equals(b))
throw new RuntimeException("assertEquals fails!");
}
private static void assertTrue(boolean value) throws Exception {
if (!value)
throw new RuntimeException("assertTrue fails!");
}
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
synth.openStream(null, null);
Soundbank defsbk = synth.getDefaultSoundbank();
if (defsbk != null) {
assertTrue(defsbk.getInstruments().length == synth
.getLoadedInstruments().length);
}
synth.close();
Map<String, Object> p = new HashMap<String, Object>();
p.put("load default soundbank", false);
synth.openStream(null, p);
if (defsbk != null) {
assertTrue(synth.getLoadedInstruments().length == 0);
}
synth.close();
}
}
......@@ -55,9 +55,8 @@ public class UnloadAllInstruments {
Soundbank defsbk = synth.getDefaultSoundbank();
if(defsbk != null)
{
assertTrue(synth.getLoadedInstruments().length == 0);
synth.unloadAllInstruments(defsbk);
assertTrue(synth.getAvailableInstruments().length == 0);
assertTrue(synth.getLoadedInstruments().length == 0);
synth.loadAllInstruments(defsbk);
assertTrue(synth.getLoadedInstruments().length != 0);
synth.unloadAllInstruments(defsbk);
......
......@@ -55,7 +55,6 @@ public class UnloadInstrument {
Soundbank defsbk = synth.getDefaultSoundbank();
if(defsbk != null)
{
assertTrue(synth.getLoadedInstruments().length == 0);
synth.unloadAllInstruments(defsbk);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
......
......@@ -55,7 +55,6 @@ public class UnloadInstruments {
Soundbank defsbk = synth.getDefaultSoundbank();
if(defsbk != null)
{
assertTrue(synth.getLoadedInstruments().length == 0);
synth.unloadAllInstruments(defsbk);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
@summary Test RealTime-tunings using SoftReciver.send method */
import java.io.IOException;
import javax.sound.midi.*;
import javax.sound.sampled.*;
import com.sun.media.sound.*;
public class RealTimeTuning {
private static class PitchSpy {
public float pitch = 0;
public Soundbank getSoundBank() {
ModelOscillator osc = new ModelOscillator() {
public float getAttenuation() {
return 0;
}
public int getChannels() {
return 0;
}
public ModelOscillatorStream open(float samplerate) {
return new ModelOscillatorStream() {
public void close() throws IOException {
pitch = 0;
}
public void noteOff(int velocity) {
pitch = 0;
}
public void noteOn(MidiChannel channel,
VoiceStatus voice, int noteNumber, int velocity) {
pitch = noteNumber * 100;
}
public int read(float[][] buffer, int offset, int len)
throws IOException {
return len;
}
public void setPitch(float ipitch) {
pitch = ipitch;
}
};
}
};
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleInstrument testinstrument = new SimpleInstrument();
testinstrument.setPatch(new Patch(0, 0));
testinstrument.add(performer);
SimpleSoundbank testsoundbank = new SimpleSoundbank();
testsoundbank.addInstrument(testinstrument);
return testsoundbank;
}
}
public static void sendTuningChange(Receiver recv, int channel,
int tuningpreset, int tuningbank) throws InvalidMidiDataException {
// Data Entry
ShortMessage sm1 = new ShortMessage();
sm1.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x64, 04);
ShortMessage sm2 = new ShortMessage();
sm2.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x65, 00);
// Tuning Bank
ShortMessage sm3 = new ShortMessage();
sm3.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x06, tuningbank);
// Data Increment
ShortMessage sm4 = new ShortMessage();
sm4.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x60, 0x7F);
// Data Decrement
ShortMessage sm5 = new ShortMessage();
sm5.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x61, 0x7F);
// Data Entry
ShortMessage sm6 = new ShortMessage();
sm6.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x64, 03);
ShortMessage sm7 = new ShortMessage();
sm7.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x65, 00);
// Tuning program
ShortMessage sm8 = new ShortMessage();
sm8
.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x06,
tuningpreset);
// Data Increment
ShortMessage sm9 = new ShortMessage();
sm9.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x60, 0x7F);
// Data Decrement
ShortMessage sm10 = new ShortMessage();
sm10.setMessage(ShortMessage.CONTROL_CHANGE, channel, 0x61, 0x7F);
recv.send(sm1, -1);
recv.send(sm2, -1);
recv.send(sm3, -1);
recv.send(sm4, -1);
recv.send(sm5, -1);
recv.send(sm6, -1);
recv.send(sm7, -1);
recv.send(sm8, -1);
recv.send(sm9, -1);
recv.send(sm10, -1);
}
private static void assertTrue(boolean value) throws Exception {
if (!value)
throw new RuntimeException("assertTrue fails!");
}
public static void testTunings(int[] msg, int tuningProgram,
int tuningBank, int targetNote, float targetPitch, boolean realtime)
throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
AudioInputStream stream = synth.openStream(null, null);
Receiver recv = synth.getReceiver();
MidiChannel channel = synth.getChannels()[0];
byte[] buff = new byte[2048];
// Create test instrument which we can use to monitor pitch changes
PitchSpy pitchspy = new PitchSpy();
synth.unloadAllInstruments(synth.getDefaultSoundbank());
synth.loadAllInstruments(pitchspy.getSoundBank());
SysexMessage sysex = null;
// Send tuning changes
if (msg != null) {
byte[] bmsg = new byte[msg.length];
for (int i = 0; i < bmsg.length; i++)
bmsg[i] = (byte) msg[i];
sysex = new SysexMessage();
sysex.setMessage(bmsg, bmsg.length);
if (targetPitch == 0) {
targetPitch = (float) new SoftTuning(bmsg)
.getTuning(targetNote);
// Check if targetPitch != targetNote * 100
assertTrue(Math.abs(targetPitch - targetNote * 100.0) > 0.001);
}
}
if (tuningProgram != -1)
sendTuningChange(recv, 0, tuningProgram, tuningBank);
// First test without tunings
channel.noteOn(targetNote, 64);
stream.read(buff, 0, buff.length);
assertTrue(Math.abs(pitchspy.pitch - (targetNote * 100.0)) < 0.001);
// Test if realtime/non-realtime works
if (sysex != null)
recv.send(sysex, -1);
stream.read(buff, 0, buff.length);
if (realtime)
assertTrue(Math.abs(pitchspy.pitch - targetPitch) < 0.001);
else
assertTrue(Math.abs(pitchspy.pitch - (targetNote * 100.0)) < 0.001);
// Test if tunings works
channel.noteOn(targetNote, 0);
stream.read(buff, 0, buff.length);
assertTrue(Math.abs(pitchspy.pitch - 0.0) < 0.001);
channel.noteOn(targetNote, 64);
stream.read(buff, 0, buff.length);
assertTrue(Math.abs(pitchspy.pitch - targetPitch) < 0.001);
channel.noteOn(targetNote, 0);
stream.read(buff, 0, buff.length);
assertTrue(Math.abs(pitchspy.pitch - 0.0) < 0.001);
stream.close();
}
public static void main(String[] args) throws Exception {
// Test with no-tunings
testTunings(null, -1, -1, 60, 6000, false);
int[] msg;
// 0x02 SINGLE NOTE TUNING CHANGE (REAL-TIME)
msg = new int[] { 0xf0, 0x7f, 0x7f, 0x08, 0x02, 0x10, 0x02, 36, 36, 64,
0, 60, 70, 0, 0, 0xf7 };
testTunings(msg, 0x10, 0, 60, 7000, true);
// 0x07 SINGLE NOTE TUNING CHANGE (NON REAL-TIME) (BANK)
msg = new int[] { 0xf0, 0x7e, 0x7f, 0x08, 0x07, 0x05, 0x07, 0x02, 36,
36, 64, 0, 60, 80, 0, 0, 0xf7 };
testTunings(msg, 0x07, 0x05, 60, 8000, false);
// 0x07 SINGLE NOTE TUNING CHANGE (REAL-TIME) (BANK)
msg = new int[] { 0xf0, 0x7f, 0x7f, 0x08, 0x07, 0x05, 0x07, 0x02, 36,
36, 64, 0, 60, 80, 0, 0, 0xf7 };
testTunings(msg, 0x07, 0x05, 60, 8000, true);
// 0x08 scale/octave tuning 1-byte form (Non Real-Time)
msg = new int[] { 0xf0, 0x7e, 0x7f, 0x08, 0x08, 0x03, 0x7f, 0x7f, 5,
10, 15, 20, 25, 30, 35, 40, 45, 50, 51, 52, 0xf7 };
testTunings(msg, -1, -1, 60, 0, false);
// 0x08 scale/octave tuning 1-byte form (REAL-TIME)
msg = new int[] { 0xf0, 0x7f, 0x7f, 0x08, 0x08, 0x03, 0x7f, 0x7f, 5,
10, 15, 20, 25, 30, 35, 40, 45, 50, 51, 52, 0xf7 };
testTunings(msg, -1, -1, 60, 0, true);
// 0x09 scale/octave tuning 2-byte form (Non Real-Time)
msg = new int[] { 0xf0, 0x7e, 0x7f, 0x08, 0x09, 0x03, 0x7f, 0x7f, 5,
10, 15, 20, 25, 30, 35, 40, 45, 50, 51, 52, 5, 10, 15, 20, 25,
30, 35, 40, 45, 50, 51, 52, 0xf7 };
testTunings(msg, -1, -1, 60, 0, false);
// 0x09 scale/octave tuning 2-byte form (REAL-TIME)
msg = new int[] { 0xf0, 0x7f, 0x7f, 0x08, 0x09, 0x03, 0x7f, 0x7f, 5,
10, 15, 20, 25, 30, 35, 40, 45, 50, 51, 52, 5, 10, 15, 20, 25,
30, 35, 40, 45, 50, 51, 52, 0xf7 };
testTunings(msg, -1, -1, 60, 0, true);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册