提交 6fe7d095 编写于 作者: A amenkov

6702956: OpenJDK: replace encumbered code (software synthesizer)

6717691: Update Gervill with post 1.0 fixes
6740210: Update Gervill with more post 1.0 fixes
6748247: Further update Gervill with still more post 1.0 fixes
6748251: Apply IcedTea midi sound patch
6758986: Gervill: Turn SoftJitterCorrector, SoftAudioPusher threads into a daemon threads
Reviewed-by: ohair, darcy
上级 69faf834
......@@ -911,14 +911,6 @@ initial-image-jdk:: initial-image-jdk-setup \
fi; \
done
ifeq ($(PLATFORM), windows)
@#
@# Audio soundbank - Bug# 4236400
@# Windows only: adding audio files to JDK's jre/lib directory.
@#
($(CD) $(LIBDIR) && $(TAR) cf - \
`$(FIND) audio -depth -print`) | \
($(CD) $(JDK_IMAGE_DIR)/jre/lib && $(TAR) xf -)
@#
@#
@# lib/
@#
......
......@@ -29,9 +29,7 @@
# Names of native shared libraries
PLUG_JSOUND_LIBRARY=$(LIB_PREFIX)jsoundhs.$(LIBRARY_SUFFIX)
PLUG_LIBRARY_NAMES = \
$(PLUG_JSOUND_LIBRARY)
PLUG_LIBRARY_NAMES=
# Sub-directory where native shared libraries are located (e.g. jre/bin or...)
......@@ -74,62 +72,10 @@ com/sun/jmx/snmp/daemon/SnmpSocket.class \
com/sun/jmx/snmp/daemon/SnmpTimerServer.class \
com/sun/jmx/snmp/daemon/WaitQ.class
PLUG_SOUND_CLASS_NAMES = \
com/sun/media/sound/AbstractPlayer.class \
com/sun/media/sound/CircularBuffer.class \
com/sun/media/sound/HeadspaceInstrument.class \
com/sun/media/sound/HeadspaceMixer\$$1.class \
com/sun/media/sound/HeadspaceMixer\$$MidiLine.class \
com/sun/media/sound/HeadspaceMixer\$$MidiLineInfo.class \
com/sun/media/sound/HeadspaceMixer\$$MixerInfo.class \
com/sun/media/sound/HeadspaceMixer\$$MixerReverbControl\$$MixerReverbType.class \
com/sun/media/sound/HeadspaceMixer\$$MixerReverbControl.class \
com/sun/media/sound/HeadspaceMixer.class \
com/sun/media/sound/HeadspaceMixerProvider.class \
com/sun/media/sound/HeadspaceSample.class \
com/sun/media/sound/HeadspaceSoundbank.class \
com/sun/media/sound/HsbParser.class \
com/sun/media/sound/MixerClip\$$1.class \
com/sun/media/sound/MixerClip\$$MixerClipApplyReverbControl.class \
com/sun/media/sound/MixerClip\$$MixerClipGainControl.class \
com/sun/media/sound/MixerClip\$$MixerClipMuteControl.class \
com/sun/media/sound/MixerClip\$$MixerClipPanControl.class \
com/sun/media/sound/MixerClip\$$MixerClipSampleRateControl.class \
com/sun/media/sound/MixerClip.class \
com/sun/media/sound/MixerMidiChannel.class \
com/sun/media/sound/MixerSequencer\$$1.class \
com/sun/media/sound/MixerSequencer\$$ControllerVectorElement.class \
com/sun/media/sound/MixerSequencer\$$MixerSequencerInfo.class \
com/sun/media/sound/MixerSequencer\$$RecordingTrack.class \
com/sun/media/sound/MixerSequencer.class \
com/sun/media/sound/MixerSequencerProvider.class \
com/sun/media/sound/MixerSourceLine\$$1.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineApplyReverbControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineGainControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineMuteControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLinePanControl.class \
com/sun/media/sound/MixerSourceLine\$$MixerSourceLineSampleRateControl.class \
com/sun/media/sound/MixerSourceLine.class \
com/sun/media/sound/MixerSynth\$$1.class \
com/sun/media/sound/MixerSynth\$$MixerSynthInfo.class \
com/sun/media/sound/MixerSynth\$$SynthReceiver.class \
com/sun/media/sound/MixerSynth.class \
com/sun/media/sound/MixerSynthProvider.class \
com/sun/media/sound/MixerThread.class \
com/sun/media/sound/RmfFileReader.class \
com/sun/media/sound/SimpleInputDevice\$$1.class \
com/sun/media/sound/SimpleInputDevice\$$InputDeviceDataLine.class \
com/sun/media/sound/SimpleInputDevice\$$InputDevicePort.class \
com/sun/media/sound/SimpleInputDevice\$$InputDevicePortInfo.class \
com/sun/media/sound/SimpleInputDevice.class \
com/sun/media/sound/SimpleInputDeviceProvider\$$1.class \
com/sun/media/sound/SimpleInputDeviceProvider\$$InputDeviceInfo.class \
com/sun/media/sound/SimpleInputDeviceProvider.class
# Class list temp files (used by both import and export of plugs)
PLUG_TEMPDIR=$(ABS_TEMPDIR)/plugs
PLUG_CLASS_AREAS = jmf sound
PLUG_CLASS_AREAS = jmf
PLUG_CLISTS = $(PLUG_CLASS_AREAS:%=$(PLUG_TEMPDIR)/%.clist)
# Create jargs file command
......@@ -147,18 +93,11 @@ $(PLUG_TEMPDIR)/jmf.clist:
@for i in $(PLUG_JMF_CLASS_NAMES) ; do \
$(ECHO) "$$i" >> $@; \
done
$(PLUG_TEMPDIR)/sound.clist:
@$(prep-target)
@for i in $(PLUG_SOUND_CLASS_NAMES) ; do \
$(ECHO) "$$i" >> $@ ; \
done
$(PLUG_TEMPDIR)/all.clist: $(PLUG_CLISTS)
@$(prep-target)
$(CAT) $(PLUG_CLISTS) > $@
$(PLUG_TEMPDIR)/jmf.jargs: $(PLUG_TEMPDIR)/jmf.clist
$(plug-create-jargs)
$(PLUG_TEMPDIR)/sound.jargs: $(PLUG_TEMPDIR)/sound.clist
$(plug-create-jargs)
$(PLUG_TEMPDIR)/all.jargs: $(PLUG_TEMPDIR)/all.clist
$(plug-create-jargs)
......@@ -193,25 +132,11 @@ endef # import-binary-plug-classes
import-binary-plug-jmf-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/jmf.clist
$(call import-binary-plug-classes,$(PLUG_TEMPDIR)/jmf.clist)
import-binary-plug-sound-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/sound.clist
$(call import-binary-plug-classes,$(PLUG_TEMPDIR)/sound.clist)
# Import all classes from the jar file
import-binary-plug-jar: \
import-binary-plug-jmf-classes \
import-binary-plug-sound-classes
# Import native libraries
$(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY): \
$(PLUG_IMPORT_DIR)/$(PLUG_LOCATION_SUBDIR)/$(PLUG_JSOUND_LIBRARY)
$(import-binary-plug-file)
# Rules only used by lower level makefiles
import-binary-plug-jsound-library: \
$(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY)
import-binary-plug-jmf-classes
# Binary plug start/complete messages
......@@ -241,9 +166,7 @@ import-binary-plugs: \
import-binary-plugs-libs \
import-binary-plugs \
import-binary-plug-jar \
import-binary-plug-jmf-classes \
import-binary-plug-sound-classes \
import-binary-plug-jsound-library
import-binary-plug-jmf-classes
else # !OPENJDK
......@@ -280,12 +203,6 @@ $(PLUG_EXPORT_JARFILE): $(PLUG_TEMPDIR)/all.clist $(PLUG_TEMPDIR)/all.jargs
@$(java-vm-cleanup)
export-binary-plugs-jar: $(PLUG_EXPORT_JARFILE)
# Export native libraries
$(PLUG_EXPORT_DIR)/$(PLUG_LOCATION_SUBDIR)/$(PLUG_JSOUND_LIBRARY): \
$(LIB_LOCATION)/$(PLUG_JSOUND_LIBRARY)
$(export-binary-plug-file)
# Export binary plug start/complete messages
export-binary-plugs-started:
......
......@@ -53,18 +53,6 @@ include FILES_c.gmk
# add java files
AUTO_FILES_JAVA_DIRS = javax/sound com/sun/media/sound
#
# Specific to OpenJDK building
#
ifdef OPENJDK
# copy closed .class files
build: import-binary-plug-sound-classes
include $(BUILDDIR)/common/internal/BinaryPlugs.gmk
endif # OPENJDK
#
# Files that just need cp.
#
......@@ -79,13 +67,11 @@ FILES_copy = \
$(SERVICEDIR)/javax.sound.sampled.spi.AudioFileReader \
$(SERVICEDIR)/javax.sound.sampled.spi.FormatConversionProvider \
$(SERVICEDIR)/javax.sound.sampled.spi.MixerProvider \
$(LIBDIR)/audio/soundbank.gm \
$(LIBDIR)/sound.properties
FILES_mkdirs = \
$(CLASSBINDIR)/META-INF \
$(CLASSBINDIR)/META-INF/services \
$(LIBDIR)/audio
$(CLASSBINDIR)/META-INF/services
FILES_copydirs = \
$(CLASSBINDIR) \
......@@ -95,11 +81,6 @@ FILES_copydirs = \
FILES_c += $(FILES_$(PLATFORM))
#
# add "closed" library
#
SUBDIRS += jsoundhs
#
# system dependent flags
#
......
#
# Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
FILES_c = \
Utilities.c \
MixerThread.c \
HeadspaceMixer.c \
MixerClip.c \
MixerSourceLine.c \
SimpleInputDevice.c \
SimpleInputDeviceProvider.c \
HeadspaceSoundbank.c \
MixerMidiChannel.c \
AbstractPlayer.c \
MixerSequencer.c \
MixerSynth.c
FILES_engine = \
DriverTools.c \
GenAudioCaptureStreams.c \
GenAudioStreams.c \
GenOutput.c \
GenPatch.c \
GenReverb.c \
GenSample.c \
GenSeq.c \
GenSetup.c \
GenSong.c \
GenSynth.c \
GenSynthFilters.c \
GenSynthInterp2.c \
GenSynthResample.c \
NewNewLZSS.c \
SampleTools.c \
SMOD_Volume_Scaler.c \
X_API.c \
X_Decompress.c \
X_IMA.c \
GenFiltersReverb.c \
GenInterp2Reverb.c \
GenSoundFiles.c \
SincResample.c
FILES_solaris = \
HAE_API_SolarisOS.c \
HAE_API_SolarisOS_Capture.c
FILES_linux = \
HAE_API_LinuxOS.c \
HAE_API_LinuxOS_Capture.c
FILES_windows = \
HAE_API_WinOS.c \
HAE_API_WinOS_Capture.c \
HAE_API_WinOS_Synth.c
FILES_export = \
com/sun/media/sound/AbstractPlayer.java \
com/sun/media/sound/HeadspaceMixer.java \
com/sun/media/sound/HeadspaceSoundbank.java \
com/sun/media/sound/MixerClip.java \
com/sun/media/sound/MixerMidiChannel.java \
com/sun/media/sound/MixerSequencer.java \
com/sun/media/sound/MixerSourceLine.java \
com/sun/media/sound/MixerSynth.java \
com/sun/media/sound/MixerThread.java \
com/sun/media/sound/SimpleInputDevice.java \
com/sun/media/sound/SimpleInputDeviceProvider.java
#
# Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
BUILDDIR = ../../..
PACKAGE = javax.sound
LIBRARY = jsoundhs
PRODUCT = sun
CPLUSPLUSLIBRARY = true
include $(BUILDDIR)/common/Defs.gmk
# this Makefile compiles "closed" JavaSound library
ifdef OPENJDK
# precompiled lib will be copied by the rules in Library.gmk instead of compiling.
USE_BINARY_PLUG_LIBRARY=true
build: import-binary-plug-jsound-library
include $(BUILDDIR)/common/internal/BinaryPlugs.gmk
else # OPENJDK
# include defines for sound
include ../SoundDefs.gmk
#
# Add use of mapfile
#
FILES_m = mapfile-vers
include $(BUILDDIR)/common/Mapfile-vers.gmk
#
# Files
#
include FILES.gmk
FILES_c += $(FILES_engine) $(FILES_$(PLATFORM))
#
# Extra cc/linker flags.
#
# flags needed for all platforms
CPPFLAGS += \
-DJAVA_SOUND -DJAVA_THREAD \
-I$(CLOSED_SHARE_SRC)/native/com/sun/media/sound \
-I$(CLOSED_SHARE_SRC)/native/com/sun/media/sound/engine
# system dependent flags
ifeq ($(PLATFORM), windows)
CPPFLAGS += -DUSE_DIRECTSOUND=0 \
-DUSE_EXTERNAL_SYNTH=TRUE
LDLIBS += winmm.lib
endif # PLATFORM windows
ifeq ($(PLATFORM), linux)
endif # PLATFORM linux
ifeq ($(PLATFORM), solaris)
endif # PLATFORM solaris
#
# Add to the ambient VPATH.
#
vpath %.c $(CLOSED_SHARE_SRC)/native/com/sun/media/sound
vpath %.c $(CLOSED_SHARE_SRC)/native/com/sun/media/sound/engine
vpath %.c $(CLOSED_PLATFORM_SRC)/native/com/sun/media/sound/engine
endif # OPENJDK
#
# Include rules
#
include $(BUILDDIR)/common/Library.gmk
#
# Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# Define library interface.
SUNWprivate_1.1 {
global:
Java_com_sun_media_sound_AbstractPlayer_nAddReceiver;
Java_com_sun_media_sound_AbstractPlayer_nClose;
Java_com_sun_media_sound_AbstractPlayer_nLoadInstrument;
Java_com_sun_media_sound_AbstractPlayer_nRemapInstrument;
Java_com_sun_media_sound_AbstractPlayer_nRemoveReceiver;
Java_com_sun_media_sound_AbstractPlayer_nUnloadInstrument;
Java_com_sun_media_sound_HeadspaceMixer_nAllocateVoices;
Java_com_sun_media_sound_HeadspaceMixer_nCloseMixer;
Java_com_sun_media_sound_HeadspaceMixer_nCreateLinkedStreams;
Java_com_sun_media_sound_HeadspaceMixer_nDrain;
Java_com_sun_media_sound_HeadspaceMixer_nFlush;
Java_com_sun_media_sound_HeadspaceMixer_nGetCpuLoad;
Java_com_sun_media_sound_HeadspaceMixer_nGetDefaultBufferSize;
Java_com_sun_media_sound_HeadspaceMixer_nGetLevel;
Java_com_sun_media_sound_HeadspaceMixer_nGetPosition;
Java_com_sun_media_sound_HeadspaceMixer_nGetTotalVoices;
Java_com_sun_media_sound_HeadspaceMixer_nOpenMixer;
Java_com_sun_media_sound_HeadspaceMixer_nPause;
Java_com_sun_media_sound_HeadspaceMixer_nResume;
Java_com_sun_media_sound_HeadspaceMixer_nSetInterpolation;
Java_com_sun_media_sound_HeadspaceMixer_nSetMixerFormat;
Java_com_sun_media_sound_HeadspaceMixer_nSetMixLevel;
Java_com_sun_media_sound_HeadspaceMixer_nSetReverb;
Java_com_sun_media_sound_HeadspaceMixer_nStartLinkedStreams;
Java_com_sun_media_sound_HeadspaceMixer_nStopLinkedStreams;
Java_com_sun_media_sound_HeadspaceSoundbank_nCloseResource;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetInstruments;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetName;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetSamples;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionMajor;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionMinor;
Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionSubMinor;
Java_com_sun_media_sound_HeadspaceSoundbank_nOpenResource;
Java_com_sun_media_sound_HeadspaceSoundbank_nOpenResourceFromByteArray;
Java_com_sun_media_sound_MixerClip_nClose;
Java_com_sun_media_sound_MixerClip_nDrain;
Java_com_sun_media_sound_MixerClip_nFlush;
Java_com_sun_media_sound_MixerClip_nGetPosition;
Java_com_sun_media_sound_MixerClip_nOpen;
Java_com_sun_media_sound_MixerClip_nSetLinearGain;
Java_com_sun_media_sound_MixerClip_nSetPan;
Java_com_sun_media_sound_MixerClip_nSetSampleRate;
Java_com_sun_media_sound_MixerClip_nSetup;
Java_com_sun_media_sound_MixerClip_nStart;
Java_com_sun_media_sound_MixerClip_nStop;
Java_com_sun_media_sound_MixerMidiChannel_nAllNotesOff;
Java_com_sun_media_sound_MixerMidiChannel_nControlChange;
Java_com_sun_media_sound_MixerMidiChannel_nGetController;
Java_com_sun_media_sound_MixerMidiChannel_nGetPitchBend;
Java_com_sun_media_sound_MixerMidiChannel_nGetSolo;
Java_com_sun_media_sound_MixerMidiChannel_nNoteOff;
Java_com_sun_media_sound_MixerMidiChannel_nNoteOn;
Java_com_sun_media_sound_MixerMidiChannel_nProgramChange__JIIIJ;
Java_com_sun_media_sound_MixerMidiChannel_nProgramChange__JIIJ;
Java_com_sun_media_sound_MixerMidiChannel_nResetAllControllers;
Java_com_sun_media_sound_MixerMidiChannel_nSetMute;
Java_com_sun_media_sound_MixerMidiChannel_nSetPitchBend;
Java_com_sun_media_sound_MixerMidiChannel_nSetSolo;
Java_com_sun_media_sound_MixerSequencer_nAddControllerEventCallback;
Java_com_sun_media_sound_MixerSequencer_nGetMasterTempo;
Java_com_sun_media_sound_MixerSequencer_nGetSequenceMicrosecondLength;
Java_com_sun_media_sound_MixerSequencer_nGetSequencerMicrosecondPosition;
Java_com_sun_media_sound_MixerSequencer_nGetSequencerTickPosition;
Java_com_sun_media_sound_MixerSequencer_nGetSequenceTickLength;
Java_com_sun_media_sound_MixerSequencer_nGetTempoInBPM;
Java_com_sun_media_sound_MixerSequencer_nGetTempoInMPQ;
Java_com_sun_media_sound_MixerSequencer_nGetTrackMute;
Java_com_sun_media_sound_MixerSequencer_nGetTrackSolo;
Java_com_sun_media_sound_MixerSequencer_nOpenMidiSequencer;
Java_com_sun_media_sound_MixerSequencer_nOpenRmfSequencer;
Java_com_sun_media_sound_MixerSequencer_nPauseSequencer;
Java_com_sun_media_sound_MixerSequencer_nResumeSequencer;
Java_com_sun_media_sound_MixerSequencer_nSetMasterTempo;
Java_com_sun_media_sound_MixerSequencer_nSetSequencerMicrosecondPosition;
Java_com_sun_media_sound_MixerSequencer_nSetSequencerTickPosition;
Java_com_sun_media_sound_MixerSequencer_nSetTempoInBPM;
Java_com_sun_media_sound_MixerSequencer_nSetTempoInMPQ;
Java_com_sun_media_sound_MixerSequencer_nSetTrackMute;
Java_com_sun_media_sound_MixerSequencer_nSetTrackSolo;
Java_com_sun_media_sound_MixerSequencer_nStartSequencer;
Java_com_sun_media_sound_MixerSourceLine_nClose;
Java_com_sun_media_sound_MixerSourceLine_nDrain;
Java_com_sun_media_sound_MixerSourceLine_nFlush;
Java_com_sun_media_sound_MixerSourceLine_nGetLevel;
Java_com_sun_media_sound_MixerSourceLine_nGetPosition;
Java_com_sun_media_sound_MixerSourceLine_nOpen;
Java_com_sun_media_sound_MixerSourceLine_nPause;
Java_com_sun_media_sound_MixerSourceLine_nResume;
Java_com_sun_media_sound_MixerSourceLine_nSetLinearGain;
Java_com_sun_media_sound_MixerSourceLine_nSetPan;
Java_com_sun_media_sound_MixerSourceLine_nSetSampleRate;
Java_com_sun_media_sound_MixerSourceLine_nStart;
Java_com_sun_media_sound_MixerSynth_nCreateSynthesizer;
Java_com_sun_media_sound_MixerSynth_nDestroySynthesizer;
Java_com_sun_media_sound_MixerSynth_nGetLatency;
Java_com_sun_media_sound_MixerSynth_nLoadInstrument;
Java_com_sun_media_sound_MixerSynth_nRemapInstrument;
Java_com_sun_media_sound_MixerSynth_nStartSynthesizer;
Java_com_sun_media_sound_MixerSynth_nUnloadInstrument;
Java_com_sun_media_sound_MixerThread_runNative;
Java_com_sun_media_sound_SimpleInputDevice_nClose;
Java_com_sun_media_sound_SimpleInputDevice_nDrain;
Java_com_sun_media_sound_SimpleInputDevice_nFlush;
Java_com_sun_media_sound_SimpleInputDevice_nGetBufferSizeInFrames;
Java_com_sun_media_sound_SimpleInputDevice_nGetFormats;
Java_com_sun_media_sound_SimpleInputDevice_nGetNumPorts;
Java_com_sun_media_sound_SimpleInputDevice_nGetPortName;
Java_com_sun_media_sound_SimpleInputDevice_nGetPosition;
Java_com_sun_media_sound_SimpleInputDevice_nOpen;
Java_com_sun_media_sound_SimpleInputDevice_nPause;
Java_com_sun_media_sound_SimpleInputDevice_nResume;
Java_com_sun_media_sound_SimpleInputDevice_nStart;
Java_com_sun_media_sound_SimpleInputDevice_nStop;
Java_com_sun_media_sound_SimpleInputDevice_nSupportsChannels;
Java_com_sun_media_sound_SimpleInputDevice_nSupportsSampleRate;
Java_com_sun_media_sound_SimpleInputDevice_nSupportsSampleSizeInBits;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetDescription;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetName;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetNumDevices;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetVendor;
Java_com_sun_media_sound_SimpleInputDeviceProvider_nGetVersion;
local:
*;
};
......@@ -75,13 +75,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
/**
* This is the device handle returned from native code
*/
/*
* $$rratta Solaris 64 bit holds pointer must be long
*
* $$mp 2003-08-07:
* 'id' is a really bad name. The variable should
* be called nativePointer or something similar.
*/
protected long id = 0;
......@@ -586,7 +579,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
private ArrayList<Transmitter> transmitters = new ArrayList<Transmitter>();
private MidiOutDevice.MidiOutReceiver midiOutReceiver;
private MixerSynth.SynthReceiver mixerSynthReceiver;
// how many transmitters must be present for optimized
// handling
......@@ -621,22 +613,14 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (midiOutReceiver == oldR) {
midiOutReceiver = null;
}
if (mixerSynthReceiver == oldR) {
mixerSynthReceiver = null;
}
if (newR != null) {
if ((newR instanceof MidiOutDevice.MidiOutReceiver)
&& (midiOutReceiver == null)) {
midiOutReceiver = ((MidiOutDevice.MidiOutReceiver) newR);
}
if ((newR instanceof MixerSynth.SynthReceiver)
&& (mixerSynthReceiver == null)) {
mixerSynthReceiver = ((MixerSynth.SynthReceiver) newR);
}
}
optimizedReceiverCount =
((midiOutReceiver!=null)?1:0)
+ ((mixerSynthReceiver!=null)?1:0);
((midiOutReceiver!=null)?1:0);
}
// more potential for optimization here
}
......@@ -670,10 +654,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (TRACE_TRANSMITTER) Printer.println("Sending packed message to MidiOutReceiver");
midiOutReceiver.sendPackedMidiMessage(packedMessage, timeStamp);
}
if (mixerSynthReceiver != null) {
if (TRACE_TRANSMITTER) Printer.println("Sending packed message to MixerSynthReceiver");
mixerSynthReceiver.sendPackedMidiMessage(packedMessage, timeStamp);
}
} else {
if (TRACE_TRANSMITTER) Printer.println("Sending packed message to "+size+" transmitter's receivers");
for (int i = 0; i < size; i++) {
......@@ -682,9 +662,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (optimizedReceiverCount > 0) {
if (receiver instanceof MidiOutDevice.MidiOutReceiver) {
((MidiOutDevice.MidiOutReceiver) receiver).sendPackedMidiMessage(packedMessage, timeStamp);
}
else if (receiver instanceof MixerSynth.SynthReceiver) {
((MixerSynth.SynthReceiver) receiver).sendPackedMidiMessage(packedMessage, timeStamp);
} else {
receiver.send(new FastShortMessage(packedMessage), timeStamp);
}
......@@ -739,10 +716,6 @@ abstract class AbstractMidiDevice implements MidiDevice, ReferenceCountingDevice
if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to MidiOutReceiver");
midiOutReceiver.send(message, timeStamp);
}
if (mixerSynthReceiver != null) {
if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to MixerSynthReceiver");
mixerSynthReceiver.send(message, timeStamp);
}
} else {
if (TRACE_TRANSMITTER) Printer.println("Sending MIDI message to "+size+" transmitter's receivers");
for (int i = 0; i < size; i++) {
......
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
* Soundbank reader that uses audio files as soundbanks.
*
* @author Karl Helgason
*/
public class AudioFileSoundbankReader extends SoundbankReader {
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(url);
Soundbank sbk = getSoundbank(ais);
ais.close();
return sbk;
} catch (UnsupportedAudioFileException e) {
return null;
} catch (IOException e) {
return null;
}
}
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
stream.mark(512);
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(stream);
Soundbank sbk = getSoundbank(ais);
if (sbk != null)
return sbk;
} catch (UnsupportedAudioFileException e) {
} catch (IOException e) {
}
stream.reset();
return null;
}
public Soundbank getSoundbank(AudioInputStream ais)
throws InvalidMidiDataException, IOException {
try {
byte[] buffer;
if (ais.getFrameLength() == -1) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buff = new byte[1024
- (1024 % ais.getFormat().getFrameSize())];
int ret;
while ((ret = ais.read(buff)) != -1) {
baos.write(buff, 0, ret);
}
ais.close();
buffer = baos.toByteArray();
} else {
buffer = new byte[(int) (ais.getFrameLength()
* ais.getFormat().getFrameSize())];
new DataInputStream(ais).readFully(buffer);
}
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
new ModelByteBuffer(buffer), ais.getFormat(), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (Exception e) {
return null;
}
}
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(file);
ais.close();
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(
new ModelByteBuffer(file, 0, file.length()), -4800);
ModelPerformer performer = new ModelPerformer();
performer.getOscillators().add(osc);
SimpleSoundbank sbk = new SimpleSoundbank();
SimpleInstrument ins = new SimpleInstrument();
ins.add(performer);
sbk.addInstrument(ins);
return sbk;
} catch (UnsupportedAudioFileException e1) {
return null;
} catch (IOException e) {
return null;
}
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
* This class is used to create AudioFloatInputStream from AudioInputStream and
* byte buffers.
*
* @author Karl Helgason
*/
public abstract class AudioFloatInputStream {
private static class BytaArrayAudioFloatInputStream
extends AudioFloatInputStream {
private int pos = 0;
private int markpos = 0;
private AudioFloatConverter converter;
private AudioFormat format;
private byte[] buffer;
private int buffer_offset;
private int buffer_len;
private int framesize_pc;
public BytaArrayAudioFloatInputStream(AudioFloatConverter converter,
byte[] buffer, int offset, int len) {
this.converter = converter;
this.format = converter.getFormat();
this.buffer = buffer;
this.buffer_offset = offset;
framesize_pc = format.getFrameSize() / format.getChannels();
this.buffer_len = len / framesize_pc;
}
public AudioFormat getFormat() {
return format;
}
public long getFrameLength() {
return buffer_len;// / format.getFrameSize();
}
public int read(float[] b, int off, int len) throws IOException {
if (b == null)
throw new NullPointerException();
if (off < 0 || len < 0 || len > b.length - off)
throw new IndexOutOfBoundsException();
if (pos >= buffer_len)
return -1;
if (len == 0)
return 0;
if (pos + len > buffer_len)
len = buffer_len - pos;
converter.toFloatArray(buffer, buffer_offset + pos * framesize_pc,
b, off, len);
pos += len;
return len;
}
public long skip(long len) throws IOException {
if (pos >= buffer_len)
return -1;
if (len <= 0)
return 0;
if (pos + len > buffer_len)
len = buffer_len - pos;
pos += len;
return len;
}
public int available() throws IOException {
return buffer_len - pos;
}
public void close() throws IOException {
}
public void mark(int readlimit) {
markpos = pos;
}
public boolean markSupported() {
return true;
}
public void reset() throws IOException {
pos = markpos;
}
}
private static class DirectAudioFloatInputStream
extends AudioFloatInputStream {
private AudioInputStream stream;
private AudioFloatConverter converter;
private int framesize_pc; // framesize / channels
private byte[] buffer;
public DirectAudioFloatInputStream(AudioInputStream stream) {
converter = AudioFloatConverter.getConverter(stream.getFormat());
if (converter == null) {
AudioFormat format = stream.getFormat();
AudioFormat newformat;
AudioFormat[] formats = AudioSystem.getTargetFormats(
AudioFormat.Encoding.PCM_SIGNED, format);
if (formats.length != 0) {
newformat = formats[0];
} else {
float samplerate = format.getSampleRate();
int samplesizeinbits = format.getSampleSizeInBits();
int framesize = format.getFrameSize();
float framerate = format.getFrameRate();
samplesizeinbits = 16;
framesize = format.getChannels() * (samplesizeinbits / 8);
framerate = samplerate;
newformat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED, samplerate,
samplesizeinbits, format.getChannels(), framesize,
framerate, false);
}
stream = AudioSystem.getAudioInputStream(newformat, stream);
converter = AudioFloatConverter.getConverter(stream.getFormat());
}
framesize_pc = stream.getFormat().getFrameSize()
/ stream.getFormat().getChannels();
this.stream = stream;
}
public AudioFormat getFormat() {
return stream.getFormat();
}
public long getFrameLength() {
return stream.getFrameLength();
}
public int read(float[] b, int off, int len) throws IOException {
int b_len = len * framesize_pc;
if (buffer == null || buffer.length < b_len)
buffer = new byte[b_len];
int ret = stream.read(buffer, 0, b_len);
if (ret == -1)
return -1;
converter.toFloatArray(buffer, b, off, ret / framesize_pc);
return ret / framesize_pc;
}
public long skip(long len) throws IOException {
long b_len = len * framesize_pc;
long ret = stream.skip(b_len);
if (ret == -1)
return -1;
return ret / framesize_pc;
}
public int available() throws IOException {
return stream.available() / framesize_pc;
}
public void close() throws IOException {
stream.close();
}
public void mark(int readlimit) {
stream.mark(readlimit * framesize_pc);
}
public boolean markSupported() {
return stream.markSupported();
}
public void reset() throws IOException {
stream.reset();
}
}
public static AudioFloatInputStream getInputStream(URL url)
throws UnsupportedAudioFileException, IOException {
return new DirectAudioFloatInputStream(AudioSystem
.getAudioInputStream(url));
}
public static AudioFloatInputStream getInputStream(File file)
throws UnsupportedAudioFileException, IOException {
return new DirectAudioFloatInputStream(AudioSystem
.getAudioInputStream(file));
}
public static AudioFloatInputStream getInputStream(InputStream stream)
throws UnsupportedAudioFileException, IOException {
return new DirectAudioFloatInputStream(AudioSystem
.getAudioInputStream(stream));
}
public static AudioFloatInputStream getInputStream(
AudioInputStream stream) {
return new DirectAudioFloatInputStream(stream);
}
public static AudioFloatInputStream getInputStream(AudioFormat format,
byte[] buffer, int offset, int len) {
AudioFloatConverter converter = AudioFloatConverter
.getConverter(format);
if (converter != null)
return new BytaArrayAudioFloatInputStream(converter, buffer,
offset, len);
InputStream stream = new ByteArrayInputStream(buffer, offset, len);
long aLen = format.getFrameSize() == AudioSystem.NOT_SPECIFIED
? AudioSystem.NOT_SPECIFIED : len / format.getFrameSize();
AudioInputStream astream = new AudioInputStream(stream, format, aLen);
return getInputStream(astream);
}
public abstract AudioFormat getFormat();
public abstract long getFrameLength();
public abstract int read(float[] b, int off, int len) throws IOException;
public int read(float[] b) throws IOException {
return read(b, 0, b.length);
}
public float read() throws IOException {
float[] b = new float[1];
int ret = read(b, 0, 1);
if (ret == -1 || ret == 0)
return 0;
return b[0];
}
public abstract long skip(long len) throws IOException;
public abstract int available() throws IOException;
public abstract void close() throws IOException;
public abstract void mark(int readlimit);
public abstract boolean markSupported();
public abstract void reset() throws IOException;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.Map;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Synthesizer;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.SourceDataLine;
/**
* <code>AudioSynthesizer</code> is a <code>Synthesizer</code>
* which renders it's output audio into <code>SourceDataLine</code>
* or <code>AudioInputStream</code>.
*
* @see MidiSystem#getSynthesizer
* @see Synthesizer
*
* @author Karl Helgason
*/
public interface AudioSynthesizer extends Synthesizer {
/**
* Obtains the current format (encoding, sample rate, number of channels,
* etc.) of the synthesizer audio data.
*
* <p>If the synthesizer is not open and has never been opened, it returns
* the default format.
*
* @return current audio data format
* @see AudioFormat
*/
public AudioFormat getFormat();
/**
* Gets information about the possible properties for the synthesizer.
*
* @param info a proposed list of tag/value pairs that will be sent on open.
* @return an array of <code>AudioSynthesizerPropertyInfo</code> objects
* describing possible properties. This array may be an empty array if
* no properties are required.
*/
public AudioSynthesizerPropertyInfo[] getPropertyInfo(
Map<String, Object> info);
/**
* Opens the synthesizer and starts rendering audio into
* <code>SourceDataLine</code>.
*
* <p>An application opening a synthesizer explicitly with this call
* has to close the synthesizer by calling {@link #close}. This is
* necessary to release system resources and allow applications to
* exit cleanly.
*
* <p>Note that some synthesizers, once closed, cannot be reopened.
* Attempts to reopen such a synthesizer will always result in
* a <code>MidiUnavailableException</code>.
*
* @param line which <code>AudioSynthesizer</code> writes output audio into.
* If <code>line</code> is null, then line from system default mixer is used.
* @param info a <code>Map<String,Object></code> object containing
* properties for additional configuration supported by synthesizer.
* If <code>info</code> is null then default settings are used.
*
* @throws MidiUnavailableException thrown if the synthesizer cannot be
* opened due to resource restrictions.
* @throws SecurityException thrown if the synthesizer cannot be
* opened due to security restrictions.
*
* @see #close
* @see #isOpen
*/
public void open(SourceDataLine line, Map<String, Object> info)
throws MidiUnavailableException;
/**
* Opens the synthesizer and renders audio into returned
* <code>AudioInputStream</code>.
*
* <p>An application opening a synthesizer explicitly with this call
* has to close the synthesizer by calling {@link #close}. This is
* necessary to release system resources and allow applications to
* exit cleanly.
*
* <p>Note that some synthesizers, once closed, cannot be reopened.
* Attempts to reopen such a synthesizer will always result in
* a <code>MidiUnavailableException<code>.
*
* @param targetFormat specifies the <code>AudioFormat</code>
* used in returned <code>AudioInputStream</code>.
* @param info a <code>Map<String,Object></code> object containing
* properties for additional configuration supported by synthesizer.
* If <code>info</code> is null then default settings are used.
*
* @throws MidiUnavailableException thrown if the synthesizer cannot be
* opened due to resource restrictions.
* @throws SecurityException thrown if the synthesizer cannot be
* opened due to security restrictions.
*
* @see #close
* @see #isOpen
*/
public AudioInputStream openStream(AudioFormat targetFormat,
Map<String, Object> info) throws MidiUnavailableException;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* Information about property used in opening <code>AudioSynthesizer</code>.
*
* @author Karl Helgason
*/
public class AudioSynthesizerPropertyInfo {
/**
* Constructs a <code>AudioSynthesizerPropertyInfo</code> object with a given
* name and value. The <code>description</code> and <code>choices</code>
* are intialized by <code>null</code> values.
*
* @param name the name of the property
* @param value the current value or class used for values.
*
*/
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();
}
/**
* The name of the property.
*/
public String name;
/**
* A brief description of the property, which may be null.
*/
public String description = null;
/**
* The <code>value</code> field specifies the current value of
* the property.
*/
public Object value = null;
/**
* The <code>valueClass</code> field specifies class
* used in <code>value</code> field.
*/
public Class valueClass = null;
/**
* An array of possible values if the value for the field
* <code>AudioSynthesizerPropertyInfo.value</code> may be selected
* from a particular set of values; otherwise null.
*/
public Object[] choices = null;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to store information to describe soundbanks, instruments
* and samples. It is stored inside a "INFO" List Chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSInfo {
/**
* (INAM) Title or subject.
*/
public String name = "untitled";
/**
* (ICRD) Date of creation, the format is: YYYY-MM-DD.
* For example 2007-01-01 for 1. january of year 2007.
*/
public String creationDate = null;
/**
* (IENG) Name of engineer who created the object.
*/
public String engineers = null;
/**
* (IPRD) Name of the product which the object is intended for.
*/
public String product = null;
/**
* (ICOP) Copyright information.
*/
public String copyright = null;
/**
* (ICMT) General comments. Doesn't contain newline characters.
*/
public String comments = null;
/**
* (ISFT) Name of software package used to create the file.
*/
public String tools = null;
/**
* (IARL) Where content is archived.
*/
public String archival_location = null;
/**
* (IART) Artists of original content.
*/
public String artist = null;
/**
* (ICMS) Names of persons or orginizations who commissioned the file.
*/
public String commissioned = null;
/**
* (IGNR) Genre of the work.
* Example: jazz, classical, rock, etc.
*/
public String genre = null;
/**
* (IKEY) List of keyword that describe the content.
* Examples: FX, bird, piano, etc.
*/
public String keywords = null;
/**
* (IMED) Describes original medium of the data.
* For example: record, CD, etc.
*/
public String medium = null;
/**
* (ISBJ) Description of the content.
*/
public String subject = null;
/**
* (ISRC) Name of person or orginization who supplied
* orginal material for the file.
*/
public String source = null;
/**
* (ISRF) Source media for sample data is from.
* For example: CD, TV, etc.
*/
public String source_form = null;
/**
* (ITCH) Technician who sample the file/object.
*/
public String technician = null;
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sound.midi.Patch;
/**
* This class is used to store information to describe instrument.
* It contains list of regions and modulators.
* It is stored inside a "ins " List Chunk inside DLS files.
* In the DLS documentation a modulator is called articulator.
*
* @author Karl Helgason
*/
public class DLSInstrument extends ModelInstrument {
protected int preset = 0;
protected int bank = 0;
protected boolean druminstrument = false;
protected byte[] guid = null;
protected DLSInfo info = new DLSInfo();
protected List<DLSRegion> regions = new ArrayList<DLSRegion>();
protected List<DLSModulator> modulators = new ArrayList<DLSModulator>();
public DLSInstrument() {
super(null, null, null, null);
}
public DLSInstrument(DLSSoundbank soundbank) {
super(soundbank, null, null, null);
}
public DLSInfo getInfo() {
return info;
}
public String getName() {
return info.name;
}
public void setName(String name) {
info.name = name;
}
public ModelPatch getPatch() {
return new ModelPatch(bank, preset, druminstrument);
}
public void setPatch(Patch patch) {
if (patch instanceof ModelPatch && ((ModelPatch)patch).isPercussion()) {
druminstrument = true;
bank = patch.getBank();
preset = patch.getProgram();
} else {
druminstrument = false;
bank = patch.getBank();
preset = patch.getProgram();
}
}
public Object getData() {
return null;
}
public List<DLSRegion> getRegions() {
return regions;
}
public List<DLSModulator> getModulators() {
return modulators;
}
public String toString() {
if (druminstrument)
return "Drumkit: " + info.name
+ " bank #" + bank + " preset #" + preset;
else
return "Instrument: " + info.name
+ " bank #" + bank + " preset #" + preset;
}
private ModelIdentifier convertToModelDest(int dest) {
if (dest == DLSModulator.CONN_DST_NONE)
return null;
if (dest == DLSModulator.CONN_DST_GAIN)
return ModelDestination.DESTINATION_GAIN;
if (dest == DLSModulator.CONN_DST_PITCH)
return ModelDestination.DESTINATION_PITCH;
if (dest == DLSModulator.CONN_DST_PAN)
return ModelDestination.DESTINATION_PAN;
if (dest == DLSModulator.CONN_DST_LFO_FREQUENCY)
return ModelDestination.DESTINATION_LFO1_FREQ;
if (dest == DLSModulator.CONN_DST_LFO_STARTDELAY)
return ModelDestination.DESTINATION_LFO1_DELAY;
if (dest == DLSModulator.CONN_DST_EG1_ATTACKTIME)
return ModelDestination.DESTINATION_EG1_ATTACK;
if (dest == DLSModulator.CONN_DST_EG1_DECAYTIME)
return ModelDestination.DESTINATION_EG1_DECAY;
if (dest == DLSModulator.CONN_DST_EG1_RELEASETIME)
return ModelDestination.DESTINATION_EG1_RELEASE;
if (dest == DLSModulator.CONN_DST_EG1_SUSTAINLEVEL)
return ModelDestination.DESTINATION_EG1_SUSTAIN;
if (dest == DLSModulator.CONN_DST_EG2_ATTACKTIME)
return ModelDestination.DESTINATION_EG2_ATTACK;
if (dest == DLSModulator.CONN_DST_EG2_DECAYTIME)
return ModelDestination.DESTINATION_EG2_DECAY;
if (dest == DLSModulator.CONN_DST_EG2_RELEASETIME)
return ModelDestination.DESTINATION_EG2_RELEASE;
if (dest == DLSModulator.CONN_DST_EG2_SUSTAINLEVEL)
return ModelDestination.DESTINATION_EG2_SUSTAIN;
// DLS2 Destinations
if (dest == DLSModulator.CONN_DST_KEYNUMBER)
return ModelDestination.DESTINATION_KEYNUMBER;
if (dest == DLSModulator.CONN_DST_CHORUS)
return ModelDestination.DESTINATION_CHORUS;
if (dest == DLSModulator.CONN_DST_REVERB)
return ModelDestination.DESTINATION_REVERB;
if (dest == DLSModulator.CONN_DST_VIB_FREQUENCY)
return ModelDestination.DESTINATION_LFO2_FREQ;
if (dest == DLSModulator.CONN_DST_VIB_STARTDELAY)
return ModelDestination.DESTINATION_LFO2_DELAY;
if (dest == DLSModulator.CONN_DST_EG1_DELAYTIME)
return ModelDestination.DESTINATION_EG1_DELAY;
if (dest == DLSModulator.CONN_DST_EG1_HOLDTIME)
return ModelDestination.DESTINATION_EG1_HOLD;
if (dest == DLSModulator.CONN_DST_EG1_SHUTDOWNTIME)
return ModelDestination.DESTINATION_EG1_SHUTDOWN;
if (dest == DLSModulator.CONN_DST_EG2_DELAYTIME)
return ModelDestination.DESTINATION_EG2_DELAY;
if (dest == DLSModulator.CONN_DST_EG2_HOLDTIME)
return ModelDestination.DESTINATION_EG2_HOLD;
if (dest == DLSModulator.CONN_DST_FILTER_CUTOFF)
return ModelDestination.DESTINATION_FILTER_FREQ;
if (dest == DLSModulator.CONN_DST_FILTER_Q)
return ModelDestination.DESTINATION_FILTER_Q;
return null;
}
private ModelIdentifier convertToModelSrc(int src) {
if (src == DLSModulator.CONN_SRC_NONE)
return null;
if (src == DLSModulator.CONN_SRC_LFO)
return ModelSource.SOURCE_LFO1;
if (src == DLSModulator.CONN_SRC_KEYONVELOCITY)
return ModelSource.SOURCE_NOTEON_VELOCITY;
if (src == DLSModulator.CONN_SRC_KEYNUMBER)
return ModelSource.SOURCE_NOTEON_KEYNUMBER;
if (src == DLSModulator.CONN_SRC_EG1)
return ModelSource.SOURCE_EG1;
if (src == DLSModulator.CONN_SRC_EG2)
return ModelSource.SOURCE_EG2;
if (src == DLSModulator.CONN_SRC_PITCHWHEEL)
return ModelSource.SOURCE_MIDI_PITCH;
if (src == DLSModulator.CONN_SRC_CC1)
return new ModelIdentifier("midi_cc", "1", 0);
if (src == DLSModulator.CONN_SRC_CC7)
return new ModelIdentifier("midi_cc", "7", 0);
if (src == DLSModulator.CONN_SRC_CC10)
return new ModelIdentifier("midi_cc", "10", 0);
if (src == DLSModulator.CONN_SRC_CC11)
return new ModelIdentifier("midi_cc", "11", 0);
if (src == DLSModulator.CONN_SRC_RPN0)
return new ModelIdentifier("midi_rpn", "0", 0);
if (src == DLSModulator.CONN_SRC_RPN1)
return new ModelIdentifier("midi_rpn", "1", 0);
if (src == DLSModulator.CONN_SRC_POLYPRESSURE)
return ModelSource.SOURCE_MIDI_POLY_PRESSURE;
if (src == DLSModulator.CONN_SRC_CHANNELPRESSURE)
return ModelSource.SOURCE_MIDI_CHANNEL_PRESSURE;
if (src == DLSModulator.CONN_SRC_VIBRATO)
return ModelSource.SOURCE_LFO2;
if (src == DLSModulator.CONN_SRC_MONOPRESSURE)
return ModelSource.SOURCE_MIDI_CHANNEL_PRESSURE;
if (src == DLSModulator.CONN_SRC_CC91)
return new ModelIdentifier("midi_cc", "91", 0);
if (src == DLSModulator.CONN_SRC_CC93)
return new ModelIdentifier("midi_cc", "93", 0);
return null;
}
private ModelConnectionBlock convertToModel(DLSModulator mod) {
ModelIdentifier source = convertToModelSrc(mod.getSource());
ModelIdentifier control = convertToModelSrc(mod.getControl());
ModelIdentifier destination_id =
convertToModelDest(mod.getDestination());
int scale = mod.getScale();
double f_scale;
if (scale == Integer.MIN_VALUE)
f_scale = Double.NEGATIVE_INFINITY;
else
f_scale = scale / 65536.0;
if (destination_id != null) {
ModelSource src = null;
ModelSource ctrl = null;
ModelConnectionBlock block = new ModelConnectionBlock();
if (control != null) {
ModelSource s = new ModelSource();
if (control == ModelSource.SOURCE_MIDI_PITCH) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
} else if (control == ModelSource.SOURCE_LFO1
|| control == ModelSource.SOURCE_LFO2) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
}
s.setIdentifier(control);
block.addSource(s);
ctrl = s;
}
if (source != null) {
ModelSource s = new ModelSource();
if (source == ModelSource.SOURCE_MIDI_PITCH) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
} else if (source == ModelSource.SOURCE_LFO1
|| source == ModelSource.SOURCE_LFO2) {
((ModelStandardTransform)s.getTransform()).setPolarity(
ModelStandardTransform.POLARITY_BIPOLAR);
}
s.setIdentifier(source);
block.addSource(s);
src = s;
}
ModelDestination destination = new ModelDestination();
destination.setIdentifier(destination_id);
block.setDestination(destination);
if (mod.getVersion() == 1) {
//if (mod.getTransform() == DLSModulator.CONN_TRN_CONCAVE) {
// ((ModelStandardTransform)destination.getTransform())
// .setTransform(
// ModelStandardTransform.TRANSFORM_CONCAVE);
//}
if (mod.getTransform() == DLSModulator.CONN_TRN_CONCAVE) {
if (src != null) {
((ModelStandardTransform)src.getTransform())
.setTransform(
ModelStandardTransform.TRANSFORM_CONCAVE);
((ModelStandardTransform)src.getTransform())
.setDirection(
ModelStandardTransform.DIRECTION_MAX2MIN);
}
if (ctrl != null) {
((ModelStandardTransform)ctrl.getTransform())
.setTransform(
ModelStandardTransform.TRANSFORM_CONCAVE);
((ModelStandardTransform)ctrl.getTransform())
.setDirection(
ModelStandardTransform.DIRECTION_MAX2MIN);
}
}
} else if (mod.getVersion() == 2) {
int transform = mod.getTransform();
int src_transform_invert = (transform >> 15) & 1;
int src_transform_bipolar = (transform >> 14) & 1;
int src_transform = (transform >> 10) & 8;
int ctr_transform_invert = (transform >> 9) & 1;
int ctr_transform_bipolar = (transform >> 8) & 1;
int ctr_transform = (transform >> 4) & 8;
if (src != null) {
int trans = ModelStandardTransform.TRANSFORM_LINEAR;
if (src_transform == DLSModulator.CONN_TRN_SWITCH)
trans = ModelStandardTransform.TRANSFORM_SWITCH;
if (src_transform == DLSModulator.CONN_TRN_CONCAVE)
trans = ModelStandardTransform.TRANSFORM_CONCAVE;
if (src_transform == DLSModulator.CONN_TRN_CONVEX)
trans = ModelStandardTransform.TRANSFORM_CONVEX;
((ModelStandardTransform)src.getTransform())
.setTransform(trans);
((ModelStandardTransform)src.getTransform())
.setPolarity(src_transform_bipolar == 1);
((ModelStandardTransform)src.getTransform())
.setDirection(src_transform_invert == 1);
}
if (ctrl != null) {
int trans = ModelStandardTransform.TRANSFORM_LINEAR;
if (ctr_transform == DLSModulator.CONN_TRN_SWITCH)
trans = ModelStandardTransform.TRANSFORM_SWITCH;
if (ctr_transform == DLSModulator.CONN_TRN_CONCAVE)
trans = ModelStandardTransform.TRANSFORM_CONCAVE;
if (ctr_transform == DLSModulator.CONN_TRN_CONVEX)
trans = ModelStandardTransform.TRANSFORM_CONVEX;
((ModelStandardTransform)ctrl.getTransform())
.setTransform(trans);
((ModelStandardTransform)ctrl.getTransform())
.setPolarity(ctr_transform_bipolar == 1);
((ModelStandardTransform)ctrl.getTransform())
.setDirection(ctr_transform_invert == 1);
}
/* No output transforms are defined the DLS Level 2
int out_transform = transform % 8;
int trans = ModelStandardTransform.TRANSFORM_LINEAR;
if (out_transform == DLSModulator.CONN_TRN_SWITCH)
trans = ModelStandardTransform.TRANSFORM_SWITCH;
if (out_transform == DLSModulator.CONN_TRN_CONCAVE)
trans = ModelStandardTransform.TRANSFORM_CONCAVE;
if (out_transform == DLSModulator.CONN_TRN_CONVEX)
trans = ModelStandardTransform.TRANSFORM_CONVEX;
if (ctrl != null) {
((ModelStandardTransform)destination.getTransform())
.setTransform(trans);
}
*/
}
block.setScale(f_scale);
return block;
}
return null;
}
public ModelPerformer[] getPerformers() {
List<ModelPerformer> performers = new ArrayList<ModelPerformer>();
Map<String, DLSModulator> modmap = new HashMap<String, DLSModulator>();
for (DLSModulator mod: getModulators()) {
modmap.put(mod.getSource() + "x" + mod.getControl() + "=" +
mod.getDestination(), mod);
}
Map<String, DLSModulator> insmodmap =
new HashMap<String, DLSModulator>();
for (DLSRegion zone: regions) {
ModelPerformer performer = new ModelPerformer();
performer.setName(zone.getSample().getName());
performer.setSelfNonExclusive((zone.getFusoptions() &
DLSRegion.OPTION_SELFNONEXCLUSIVE) != 0);
performer.setExclusiveClass(zone.getExclusiveClass());
performer.setKeyFrom(zone.getKeyfrom());
performer.setKeyTo(zone.getKeyto());
performer.setVelFrom(zone.getVelfrom());
performer.setVelTo(zone.getVelto());
insmodmap.clear();
insmodmap.putAll(modmap);
for (DLSModulator mod: zone.getModulators()) {
insmodmap.put(mod.getSource() + "x" + mod.getControl() + "=" +
mod.getDestination(), mod);
}
List<ModelConnectionBlock> blocks = performer.getConnectionBlocks();
for (DLSModulator mod: insmodmap.values()) {
ModelConnectionBlock p = convertToModel(mod);
if (p != null)
blocks.add(p);
}
DLSSample sample = zone.getSample();
DLSSampleOptions sampleopt = zone.getSampleoptions();
if (sampleopt == null)
sampleopt = sample.getSampleoptions();
ModelByteBuffer buff = sample.getDataBuffer();
float pitchcorrection = (-sampleopt.unitynote * 100) +
sampleopt.finetune;
ModelByteBufferWavetable osc = new ModelByteBufferWavetable(buff,
sample.getFormat(), pitchcorrection);
osc.setAttenuation(osc.getAttenuation() / 65536f);
if (sampleopt.getLoops().size() != 0) {
DLSSampleLoop loop = sampleopt.getLoops().get(0);
osc.setLoopStart((int)loop.getStart());
osc.setLoopLength((int)loop.getLength());
if (loop.getType() == DLSSampleLoop.LOOP_TYPE_FORWARD)
osc.setLoopType(ModelWavetable.LOOP_TYPE_FORWARD);
if (loop.getType() == DLSSampleLoop.LOOP_TYPE_RELEASE)
osc.setLoopType(ModelWavetable.LOOP_TYPE_RELEASE);
else
osc.setLoopType(ModelWavetable.LOOP_TYPE_FORWARD);
}
performer.getConnectionBlocks().add(
new ModelConnectionBlock(SoftFilter.FILTERTYPE_LP12,
new ModelDestination(
new ModelIdentifier("filter", "type", 1))));
performer.getOscillators().add(osc);
performers.add(performer);
}
return performers.toArray(new ModelPerformer[performers.size()]);
}
public byte[] getGuid() {
return guid;
}
public void setGuid(byte[] guid) {
this.guid = guid;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to store modulator/artiuclation data.
* A modulator connects one synthesizer source to
* a destination. For example a note on velocity
* can be mapped to the gain of the synthesized voice.
* It is stored as a "art1" or "art2" chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSModulator {
// DLS1 Destinations
public static final int CONN_DST_NONE = 0x000; // 0
public static final int CONN_DST_GAIN = 0x001; // cB
public static final int CONN_DST_PITCH = 0x003; // cent
public static final int CONN_DST_PAN = 0x004; // 0.1%
public static final int CONN_DST_LFO_FREQUENCY = 0x104; // cent (default 5 Hz)
public static final int CONN_DST_LFO_STARTDELAY = 0x105; // timecent
public static final int CONN_DST_EG1_ATTACKTIME = 0x206; // timecent
public static final int CONN_DST_EG1_DECAYTIME = 0x207; // timecent
public static final int CONN_DST_EG1_RELEASETIME = 0x209; // timecent
public static final int CONN_DST_EG1_SUSTAINLEVEL = 0x20A; // 0.1%
public static final int CONN_DST_EG2_ATTACKTIME = 0x30A; // timecent
public static final int CONN_DST_EG2_DECAYTIME = 0x30B; // timecent
public static final int CONN_DST_EG2_RELEASETIME = 0x30D; // timecent
public static final int CONN_DST_EG2_SUSTAINLEVEL = 0x30E; // 0.1%
// DLS2 Destinations
public static final int CONN_DST_KEYNUMBER = 0x005;
public static final int CONN_DST_LEFT = 0x010; // 0.1%
public static final int CONN_DST_RIGHT = 0x011; // 0.1%
public static final int CONN_DST_CENTER = 0x012; // 0.1%
public static final int CONN_DST_LEFTREAR = 0x013; // 0.1%
public static final int CONN_DST_RIGHTREAR = 0x014; // 0.1%
public static final int CONN_DST_LFE_CHANNEL = 0x015; // 0.1%
public static final int CONN_DST_CHORUS = 0x080; // 0.1%
public static final int CONN_DST_REVERB = 0x081; // 0.1%
public static final int CONN_DST_VIB_FREQUENCY = 0x114; // cent
public static final int CONN_DST_VIB_STARTDELAY = 0x115; // dB
public static final int CONN_DST_EG1_DELAYTIME = 0x20B; // timecent
public static final int CONN_DST_EG1_HOLDTIME = 0x20C; // timecent
public static final int CONN_DST_EG1_SHUTDOWNTIME = 0x20D; // timecent
public static final int CONN_DST_EG2_DELAYTIME = 0x30F; // timecent
public static final int CONN_DST_EG2_HOLDTIME = 0x310; // timecent
public static final int CONN_DST_FILTER_CUTOFF = 0x500; // cent
public static final int CONN_DST_FILTER_Q = 0x501; // dB
// DLS1 Sources
public static final int CONN_SRC_NONE = 0x000; // 1
public static final int CONN_SRC_LFO = 0x001; // linear (sine wave)
public static final int CONN_SRC_KEYONVELOCITY = 0x002; // ??db or velocity??
public static final int CONN_SRC_KEYNUMBER = 0x003; // ??cent or keynumber??
public static final int CONN_SRC_EG1 = 0x004; // linear direct from eg
public static final int CONN_SRC_EG2 = 0x005; // linear direct from eg
public static final int CONN_SRC_PITCHWHEEL = 0x006; // linear -1..1
public static final int CONN_SRC_CC1 = 0x081; // linear 0..1
public static final int CONN_SRC_CC7 = 0x087; // linear 0..1
public static final int CONN_SRC_CC10 = 0x08A; // linear 0..1
public static final int CONN_SRC_CC11 = 0x08B; // linear 0..1
public static final int CONN_SRC_RPN0 = 0x100; // ?? // Pitch Bend Range
public static final int CONN_SRC_RPN1 = 0x101; // ?? // Fine Tune
public static final int CONN_SRC_RPN2 = 0x102; // ?? // Course Tune
// DLS2 Sources
public static final int CONN_SRC_POLYPRESSURE = 0x007; // linear 0..1
public static final int CONN_SRC_CHANNELPRESSURE = 0x008; // linear 0..1
public static final int CONN_SRC_VIBRATO = 0x009; // linear 0..1
public static final int CONN_SRC_MONOPRESSURE = 0x00A; // linear 0..1
public static final int CONN_SRC_CC91 = 0x0DB; // linear 0..1
public static final int CONN_SRC_CC93 = 0x0DD; // linear 0..1
// DLS1 Transforms
public static final int CONN_TRN_NONE = 0x000;
public static final int CONN_TRN_CONCAVE = 0x001;
// DLS2 Transforms
public static final int CONN_TRN_CONVEX = 0x002;
public static final int CONN_TRN_SWITCH = 0x003;
public static final int DST_FORMAT_CB = 1;
public static final int DST_FORMAT_CENT = 1;
public static final int DST_FORMAT_TIMECENT = 2;
public static final int DST_FORMAT_PERCENT = 3;
protected int source;
protected int control;
protected int destination;
protected int transform;
protected int scale;
protected int version = 1;
public int getControl() {
return control;
}
public void setControl(int control) {
this.control = control;
}
public static int getDestinationFormat(int destination) {
if (destination == CONN_DST_GAIN)
return DST_FORMAT_CB;
if (destination == CONN_DST_PITCH)
return DST_FORMAT_CENT;
if (destination == CONN_DST_PAN)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_LFO_FREQUENCY)
return DST_FORMAT_CENT;
if (destination == CONN_DST_LFO_STARTDELAY)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_ATTACKTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_DECAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_RELEASETIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_SUSTAINLEVEL)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_EG2_ATTACKTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_DECAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_RELEASETIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_SUSTAINLEVEL)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_KEYNUMBER)
return DST_FORMAT_CENT; // NOT SURE WITHOUT DLS 2 SPEC
if (destination == CONN_DST_LEFT)
return DST_FORMAT_CB;
if (destination == CONN_DST_RIGHT)
return DST_FORMAT_CB;
if (destination == CONN_DST_CENTER)
return DST_FORMAT_CB;
if (destination == CONN_DST_LEFTREAR)
return DST_FORMAT_CB;
if (destination == CONN_DST_RIGHTREAR)
return DST_FORMAT_CB;
if (destination == CONN_DST_LFE_CHANNEL)
return DST_FORMAT_CB;
if (destination == CONN_DST_CHORUS)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_REVERB)
return DST_FORMAT_PERCENT;
if (destination == CONN_DST_VIB_FREQUENCY)
return DST_FORMAT_CENT;
if (destination == CONN_DST_VIB_STARTDELAY)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_DELAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_HOLDTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG1_SHUTDOWNTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_DELAYTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_EG2_HOLDTIME)
return DST_FORMAT_TIMECENT;
if (destination == CONN_DST_FILTER_CUTOFF)
return DST_FORMAT_CENT;
if (destination == CONN_DST_FILTER_Q)
return DST_FORMAT_CB;
return -1;
}
public static String getDestinationName(int destination) {
if (destination == CONN_DST_GAIN)
return "gain";
if (destination == CONN_DST_PITCH)
return "pitch";
if (destination == CONN_DST_PAN)
return "pan";
if (destination == CONN_DST_LFO_FREQUENCY)
return "lfo1.freq";
if (destination == CONN_DST_LFO_STARTDELAY)
return "lfo1.delay";
if (destination == CONN_DST_EG1_ATTACKTIME)
return "eg1.attack";
if (destination == CONN_DST_EG1_DECAYTIME)
return "eg1.decay";
if (destination == CONN_DST_EG1_RELEASETIME)
return "eg1.release";
if (destination == CONN_DST_EG1_SUSTAINLEVEL)
return "eg1.sustain";
if (destination == CONN_DST_EG2_ATTACKTIME)
return "eg2.attack";
if (destination == CONN_DST_EG2_DECAYTIME)
return "eg2.decay";
if (destination == CONN_DST_EG2_RELEASETIME)
return "eg2.release";
if (destination == CONN_DST_EG2_SUSTAINLEVEL)
return "eg2.sustain";
if (destination == CONN_DST_KEYNUMBER)
return "keynumber";
if (destination == CONN_DST_LEFT)
return "left";
if (destination == CONN_DST_RIGHT)
return "right";
if (destination == CONN_DST_CENTER)
return "center";
if (destination == CONN_DST_LEFTREAR)
return "leftrear";
if (destination == CONN_DST_RIGHTREAR)
return "rightrear";
if (destination == CONN_DST_LFE_CHANNEL)
return "lfe_channel";
if (destination == CONN_DST_CHORUS)
return "chorus";
if (destination == CONN_DST_REVERB)
return "reverb";
if (destination == CONN_DST_VIB_FREQUENCY)
return "vib.freq";
if (destination == CONN_DST_VIB_STARTDELAY)
return "vib.delay";
if (destination == CONN_DST_EG1_DELAYTIME)
return "eg1.delay";
if (destination == CONN_DST_EG1_HOLDTIME)
return "eg1.hold";
if (destination == CONN_DST_EG1_SHUTDOWNTIME)
return "eg1.shutdown";
if (destination == CONN_DST_EG2_DELAYTIME)
return "eg2.delay";
if (destination == CONN_DST_EG2_HOLDTIME)
return "eg.2hold";
if (destination == CONN_DST_FILTER_CUTOFF)
return "filter.cutoff"; // NOT SURE WITHOUT DLS 2 SPEC
if (destination == CONN_DST_FILTER_Q)
return "filter.q"; // NOT SURE WITHOUT DLS 2 SPEC
return null;
}
public static String getSourceName(int source) {
if (source == CONN_SRC_NONE)
return "none";
if (source == CONN_SRC_LFO)
return "lfo";
if (source == CONN_SRC_KEYONVELOCITY)
return "keyonvelocity";
if (source == CONN_SRC_KEYNUMBER)
return "keynumber";
if (source == CONN_SRC_EG1)
return "eg1";
if (source == CONN_SRC_EG2)
return "eg2";
if (source == CONN_SRC_PITCHWHEEL)
return "pitchweel";
if (source == CONN_SRC_CC1)
return "cc1";
if (source == CONN_SRC_CC7)
return "cc7";
if (source == CONN_SRC_CC10)
return "c10";
if (source == CONN_SRC_CC11)
return "cc11";
if (source == CONN_SRC_POLYPRESSURE)
return "polypressure";
if (source == CONN_SRC_CHANNELPRESSURE)
return "channelpressure";
if (source == CONN_SRC_VIBRATO)
return "vibrato";
if (source == CONN_SRC_MONOPRESSURE)
return "monopressure";
if (source == CONN_SRC_CC91)
return "cc91";
if (source == CONN_SRC_CC93)
return "cc93";
return null;
}
public int getDestination() {
return destination;
}
public void setDestination(int destination) {
this.destination = destination;
}
public int getScale() {
return scale;
}
public void setScale(int scale) {
this.scale = scale;
}
public int getSource() {
return source;
}
public void setSource(int source) {
this.source = source;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public int getTransform() {
return transform;
}
public void setTransform(int transform) {
this.transform = transform;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.ArrayList;
import java.util.List;
/**
* This class is used to store region parts for instrument.
* A region has a velocity and key range which it response to.
* And it has a list of modulators/articulators which
* is used how to synthesize a single voice.
* It is stored inside a "rgn " List Chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSRegion {
public final static int OPTION_SELFNONEXCLUSIVE = 0x0001;
protected List<DLSModulator> modulators = new ArrayList<DLSModulator>();
protected int keyfrom;
protected int keyto;
protected int velfrom;
protected int velto;
protected int options;
protected int exclusiveClass;
protected int fusoptions;
protected int phasegroup;
protected long channel;
protected DLSSample sample = null;
protected DLSSampleOptions sampleoptions;
public List<DLSModulator> getModulators() {
return modulators;
}
public long getChannel() {
return channel;
}
public void setChannel(long channel) {
this.channel = channel;
}
public int getExclusiveClass() {
return exclusiveClass;
}
public void setExclusiveClass(int exclusiveClass) {
this.exclusiveClass = exclusiveClass;
}
public int getFusoptions() {
return fusoptions;
}
public void setFusoptions(int fusoptions) {
this.fusoptions = fusoptions;
}
public int getKeyfrom() {
return keyfrom;
}
public void setKeyfrom(int keyfrom) {
this.keyfrom = keyfrom;
}
public int getKeyto() {
return keyto;
}
public void setKeyto(int keyto) {
this.keyto = keyto;
}
public int getOptions() {
return options;
}
public void setOptions(int options) {
this.options = options;
}
public int getPhasegroup() {
return phasegroup;
}
public void setPhasegroup(int phasegroup) {
this.phasegroup = phasegroup;
}
public DLSSample getSample() {
return sample;
}
public void setSample(DLSSample sample) {
this.sample = sample;
}
public int getVelfrom() {
return velfrom;
}
public void setVelfrom(int velfrom) {
this.velfrom = velfrom;
}
public int getVelto() {
return velto;
}
public void setVelto(int velto) {
this.velto = velto;
}
public void setModulators(List<DLSModulator> modulators) {
this.modulators = modulators;
}
public DLSSampleOptions getSampleoptions() {
return sampleoptions;
}
public void setSampleoptions(DLSSampleOptions sampleOptions) {
this.sampleoptions = sampleOptions;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.InputStream;
import javax.sound.midi.Soundbank;
import javax.sound.midi.SoundbankResource;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
/**
* This class is used to store the sample data itself.
* A sample is encoded as PCM audio stream
* and in DLS Level 1 files it is always a mono 8/16 bit stream.
* They are stored just like RIFF WAVE files are stored.
* It is stored inside a "wave" List Chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSSample extends SoundbankResource {
protected byte[] guid = null;
protected DLSInfo info = new DLSInfo();
protected DLSSampleOptions sampleoptions;
protected ModelByteBuffer data;
protected AudioFormat format;
public DLSSample(Soundbank soundBank) {
super(soundBank, null, AudioInputStream.class);
}
public DLSSample() {
super(null, null, AudioInputStream.class);
}
public DLSInfo getInfo() {
return info;
}
public Object getData() {
AudioFormat format = getFormat();
InputStream is = data.getInputStream();
if (is == null)
return null;
return new AudioInputStream(is, format, data.capacity());
}
public ModelByteBuffer getDataBuffer() {
return data;
}
public AudioFormat getFormat() {
return format;
}
public void setFormat(AudioFormat format) {
this.format = format;
}
public void setData(ModelByteBuffer data) {
this.data = data;
}
public void setData(byte[] data) {
this.data = new ModelByteBuffer(data);
}
public void setData(byte[] data, int offset, int length) {
this.data = new ModelByteBuffer(data, offset, length);
}
public String getName() {
return info.name;
}
public void setName(String name) {
info.name = name;
}
public DLSSampleOptions getSampleoptions() {
return sampleoptions;
}
public void setSampleoptions(DLSSampleOptions sampleOptions) {
this.sampleoptions = sampleOptions;
}
public String toString() {
return "Sample: " + info.name;
}
public byte[] getGuid() {
return guid;
}
public void setGuid(byte[] guid) {
this.guid = guid;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to store loop points inside DLSSampleOptions class.
*
* @author Karl Helgason
*/
public class DLSSampleLoop {
public final static int LOOP_TYPE_FORWARD = 0;
public final static int LOOP_TYPE_RELEASE = 1;
protected long type;
protected long start;
protected long length;
public long getLength() {
return length;
}
public void setLength(long length) {
this.length = length;
}
public long getStart() {
return start;
}
public void setStart(long start) {
this.start = start;
}
public long getType() {
return type;
}
public void setType(long type) {
this.type = type;
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.util.ArrayList;
import java.util.List;
/**
* This class stores options how to playback sampled data like pitch/tuning,
* attenuation and loops.
* It is stored as a "wsmp" chunk inside DLS files.
*
* @author Karl Helgason
*/
public class DLSSampleOptions {
protected int unitynote;
protected short finetune;
protected int attenuation;
protected long options;
protected List<DLSSampleLoop> loops = new ArrayList<DLSSampleLoop>();
public int getAttenuation() {
return attenuation;
}
public void setAttenuation(int attenuation) {
this.attenuation = attenuation;
}
public short getFinetune() {
return finetune;
}
public void setFinetune(short finetune) {
this.finetune = finetune;
}
public List<DLSSampleLoop> getLoops() {
return loops;
}
public long getOptions() {
return options;
}
public void setOptions(long options) {
this.options = options;
}
public int getUnitynote() {
return unitynote;
}
public void setUnitynote(int unitynote) {
this.unitynote = unitynote;
}
}
此差异已折叠。
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;
/**
* This class is used to connect the DLSSoundBank class
* to the SoundbankReader SPI interface.
*
* @author Karl Helgason
*/
public class DLSSoundbankReader extends SoundbankReader {
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
try {
return new DLSSoundbank(url);
} catch (RIFFInvalidFormatException e) {
return null;
} catch(IOException ioe) {
return null;
}
}
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
try {
stream.mark(512);
return new DLSSoundbank(stream);
} catch (RIFFInvalidFormatException e) {
stream.reset();
return null;
}
}
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
try {
return new DLSSoundbank(file);
} catch (RIFFInvalidFormatException e) {
return null;
}
}
}
......@@ -394,7 +394,12 @@ class DirectAudioDevice extends AbstractMixer {
private float leftGain, rightGain;
protected volatile boolean noService = false; // do not run the nService method
// Guards all native calls.
protected Object lockNative = new Object();
// Guards the lastOpened static variable in implOpen and implClose.
protected static Object lockLast = new Object();
// Keeps track of last opened line, see implOpen "trick".
protected static DirectDL lastOpened;
// CONSTRUCTOR
protected DirectDL(DataLine.Info info,
......@@ -496,20 +501,50 @@ class DirectAudioDevice extends AbstractMixer {
// align buffer to full frames
bufferSize = ((int) bufferSize / format.getFrameSize()) * format.getFrameSize();
id = nOpen(mixerIndex, deviceID, isSource,
encoding,
hardwareFormat.getSampleRate(),
hardwareFormat.getSampleSizeInBits(),
hardwareFormat.getFrameSize(),
hardwareFormat.getChannels(),
hardwareFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED),
hardwareFormat.isBigEndian(),
bufferSize);
synchronized(lockLast) {
id = nOpen(mixerIndex, deviceID, isSource,
encoding,
hardwareFormat.getSampleRate(),
hardwareFormat.getSampleSizeInBits(),
hardwareFormat.getFrameSize(),
hardwareFormat.getChannels(),
hardwareFormat.getEncoding().equals(
AudioFormat.Encoding.PCM_SIGNED),
hardwareFormat.isBigEndian(),
bufferSize);
if (id == 0) {
// Bah... Dirty trick. The most likely cause is an application
// already having a line open for this particular hardware
// format and forgetting about it. If so, silently close that
// implementation and try again. Unfortuantely we can only
// open one line per hardware format currently.
if (lastOpened != null
&& hardwareFormat.matches(lastOpened.hardwareFormat)) {
lastOpened.implClose();
lastOpened = null;
id = nOpen(mixerIndex, deviceID, isSource,
encoding,
hardwareFormat.getSampleRate(),
hardwareFormat.getSampleSizeInBits(),
hardwareFormat.getFrameSize(),
hardwareFormat.getChannels(),
hardwareFormat.getEncoding().equals(
AudioFormat.Encoding.PCM_SIGNED),
hardwareFormat.isBigEndian(),
bufferSize);
}
if (id == 0) {
// TODO: nicer error messages...
throw new LineUnavailableException("line with format "+format+" not supported.");
if (id == 0) {
// TODO: nicer error messages...
throw new LineUnavailableException(
"line with format "+format+" not supported.");
}
}
lastOpened = this;
}
this.bufferSize = nGetBufferSize(id, isSource);
if (this.bufferSize < 1) {
// this is an error!
......@@ -580,12 +615,12 @@ class DirectAudioDevice extends AbstractMixer {
}
synchronized (lockNative) {
nStop(id, isSource);
}
// need to set doIO to false before notifying the
// read/write thread, that's why isStartedRunning()
// cannot be used
doIO = false;
// need to set doIO to false before notifying the
// read/write thread, that's why isStartedRunning()
// cannot be used
doIO = false;
}
// wake up any waiting threads
synchronized(lock) {
lock.notifyAll();
......@@ -614,8 +649,12 @@ class DirectAudioDevice extends AbstractMixer {
doIO = false;
long oldID = id;
id = 0;
synchronized (lockNative) {
nClose(oldID, isSource);
synchronized (lockLast) {
synchronized (lockNative) {
nClose(oldID, isSource);
if (lastOpened == this)
lastOpened = null;
}
}
bytePosition = 0;
softwareConversionSize = 0;
......@@ -630,7 +669,8 @@ class DirectAudioDevice extends AbstractMixer {
}
int a = 0;
synchronized (lockNative) {
a = nAvailable(id, isSource);
if (doIO)
a = nAvailable(id, isSource);
}
return a;
}
......@@ -644,9 +684,9 @@ class DirectAudioDevice extends AbstractMixer {
int counter = 0;
long startPos = getLongFramePosition();
boolean posChanged = false;
while (!drained && doIO) {
while (!drained) {
synchronized (lockNative) {
if ((id == 0) || !nIsStillDraining(id, isSource))
if ((id == 0) || (!doIO) || !nIsStillDraining(id, isSource))
break;
}
// check every now and then for a new position
......@@ -686,7 +726,7 @@ class DirectAudioDevice extends AbstractMixer {
lock.notifyAll();
}
synchronized (lockNative) {
if (id != 0) {
if (id != 0 && doIO) {
// then flush native buffers
nFlush(id, isSource);
}
......@@ -697,9 +737,10 @@ class DirectAudioDevice extends AbstractMixer {
// replacement for getFramePosition (see AbstractDataLine)
public long getLongFramePosition() {
long pos;
long pos = 0;
synchronized (lockNative) {
pos = nGetBytePosition(id, isSource, bytePosition);
if (doIO)
pos = nGetBytePosition(id, isSource, bytePosition);
}
// hack because ALSA sometimes reports wrong framepos
if (pos < 0) {
......@@ -745,11 +786,12 @@ class DirectAudioDevice extends AbstractMixer {
}
int written = 0;
while (!flushing) {
int thisWritten;
int thisWritten = 0;
synchronized (lockNative) {
thisWritten = nWrite(id, b, off, len,
softwareConversionSize,
leftGain, rightGain);
if (doIO)
thisWritten = nWrite(id, b, off, len,
softwareConversionSize,
leftGain, rightGain);
if (thisWritten < 0) {
// error in native layer
break;
......@@ -972,9 +1014,10 @@ class DirectAudioDevice extends AbstractMixer {
}
int read = 0;
while (doIO && !flushing) {
int thisRead;
int thisRead = 0;
synchronized (lockNative) {
thisRead = nRead(id, b, off, len, softwareConversionSize);
if (doIO)
thisRead = nRead(id, b, off, len, softwareConversionSize);
if (thisRead < 0) {
// error in native layer
break;
......@@ -1209,7 +1252,8 @@ class DirectAudioDevice extends AbstractMixer {
// set new native position (if necessary)
// this must come after the flush!
synchronized (lockNative) {
nSetBytePosition(id, isSource, frames * frameSize);
if (doIO)
nSetBytePosition(id, isSource, frames * frameSize);
}
if (Printer.debug) Printer.debug(" DirectClip.setFramePosition: "
......
此差异已折叠。
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.IOException;
/**
* This exception is used when a file contains illegal or unexpected data.
*
* @author Karl Helgason
*/
public class InvalidDataException extends IOException {
private static final long serialVersionUID = 1L;
public InvalidDataException() {
super("Invalid Data!");
}
public InvalidDataException(String s) {
super(s);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This exception is used when a reader is used to read file of a format
* it doesn't unterstand or support.
*
* @author Karl Helgason
*/
public class InvalidFormatException extends InvalidDataException {
private static final long serialVersionUID = 1L;
public InvalidFormatException() {
super("Invalid format!");
}
public InvalidFormatException(String s) {
super(s);
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;
/**
* JarSoundbankReader is used to read sounbank object from jar files.
*
* @author Karl Helgason
*/
public class JARSoundbankReader extends SoundbankReader {
public boolean isZIP(URL url) {
boolean ok = false;
try {
InputStream stream = url.openStream();
try {
byte[] buff = new byte[4];
ok = stream.read(buff) == 4;
if (ok) {
ok = (buff[0] == 0x50
&& buff[1] == 0x4b
&& buff[2] == 0x03
&& buff[3] == 0x04);
}
} finally {
stream.close();
}
} catch (IOException e) {
}
return ok;
}
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
if (!isZIP(url))
return null;
ArrayList<Soundbank> soundbanks = new ArrayList<Soundbank>();
URLClassLoader ucl = URLClassLoader.newInstance(new URL[]{url});
InputStream stream = ucl.getResourceAsStream(
"META-INF/services/javax.sound.midi.Soundbank");
if (stream == null)
return null;
try
{
BufferedReader r = new BufferedReader(new InputStreamReader(stream));
String line = r.readLine();
while (line != null) {
if (!line.startsWith("#")) {
try {
Class c = Class.forName(line.trim(), true, ucl);
Object o = c.newInstance();
if (o instanceof Soundbank) {
soundbanks.add((Soundbank) o);
}
} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
}
line = r.readLine();
}
}
finally
{
stream.close();
}
if (soundbanks.size() == 0)
return null;
if (soundbanks.size() == 1)
return soundbanks.get(0);
SimpleSoundbank sbk = new SimpleSoundbank();
for (Soundbank soundbank : soundbanks)
sbk.addAllInstruments(soundbank);
return sbk;
}
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
return null;
}
public Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException {
return getSoundbank(file.toURI().toURL());
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* ModelAbstractChannelMixer is ready for use class to implement
* ModelChannelMixer interface.
*
* @author Karl Helgason
*/
public abstract class ModelAbstractChannelMixer implements ModelChannelMixer {
public abstract boolean process(float[][] buffer, int offset, int len);
public abstract void stop();
public void allNotesOff() {
}
public void allSoundOff() {
}
public void controlChange(int controller, int value) {
}
public int getChannelPressure() {
return 0;
}
public int getController(int controller) {
return 0;
}
public boolean getMono() {
return false;
}
public boolean getMute() {
return false;
}
public boolean getOmni() {
return false;
}
public int getPitchBend() {
return 0;
}
public int getPolyPressure(int noteNumber) {
return 0;
}
public int getProgram() {
return 0;
}
public boolean getSolo() {
return false;
}
public boolean localControl(boolean on) {
return false;
}
public void noteOff(int noteNumber) {
}
public void noteOff(int noteNumber, int velocity) {
}
public void noteOn(int noteNumber, int velocity) {
}
public void programChange(int program) {
}
public void programChange(int bank, int program) {
}
public void resetAllControllers() {
}
public void setChannelPressure(int pressure) {
}
public void setMono(boolean on) {
}
public void setMute(boolean mute) {
}
public void setOmni(boolean on) {
}
public void setPitchBend(int bend) {
}
public void setPolyPressure(int noteNumber, int pressure) {
}
public void setSolo(boolean soloState) {
}
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
import javax.sound.midi.MidiChannel;
/**
* ModelChannelMixer is used to process channel voice mix output before going
* to master output.<br>
* It can be used to:<br>
* <ul>
* <li>Implement non-voice oriented instruments.</li>
* <li>Add insert effect to instruments; for example distortion effect.</li>
* </ui>
* <p>
* <b>Warning! Classes that implements ModelChannelMixer must be thread-safe.</b>
*
* @author Karl Helgason
*/
public interface ModelChannelMixer extends MidiChannel {
// Used to process input audio from voices mix.
public boolean process(float[][] buffer, int offset, int len);
// Is used to trigger that this mixer is not be used
// and it should fade out.
public void stop();
}
/*
* Copyright 2007 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.media.sound;
/**
* This class is used to identify destinations in connection blocks,
* see ModelConnectionBlock.
*
* @author Karl Helgason
*/
public class ModelDestination {
public static final ModelIdentifier DESTINATION_NONE = null;
public static final ModelIdentifier DESTINATION_KEYNUMBER
= new ModelIdentifier("noteon", "keynumber");
public static final ModelIdentifier DESTINATION_VELOCITY
= new ModelIdentifier("noteon", "velocity");
public static final ModelIdentifier DESTINATION_PITCH
= new ModelIdentifier("osc", "pitch"); // cent
public static final ModelIdentifier DESTINATION_GAIN
= new ModelIdentifier("mixer", "gain"); // cB
public static final ModelIdentifier DESTINATION_PAN
= new ModelIdentifier("mixer", "pan"); // 0.1 %
public static final ModelIdentifier DESTINATION_REVERB
= new ModelIdentifier("mixer", "reverb"); // 0.1 %
public static final ModelIdentifier DESTINATION_CHORUS
= new ModelIdentifier("mixer", "chorus"); // 0.1 %
public static final ModelIdentifier DESTINATION_LFO1_DELAY
= new ModelIdentifier("lfo", "delay", 0); // timecent
public static final ModelIdentifier DESTINATION_LFO1_FREQ
= new ModelIdentifier("lfo", "freq", 0); // cent
public static final ModelIdentifier DESTINATION_LFO2_DELAY
= new ModelIdentifier("lfo", "delay", 1); // timecent
public static final ModelIdentifier DESTINATION_LFO2_FREQ
= new ModelIdentifier("lfo", "freq", 1); // cent
public static final ModelIdentifier DESTINATION_EG1_DELAY
= new ModelIdentifier("eg", "delay", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_ATTACK
= new ModelIdentifier("eg", "attack", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_HOLD
= new ModelIdentifier("eg", "hold", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_DECAY
= new ModelIdentifier("eg", "decay", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_SUSTAIN
= new ModelIdentifier("eg", "sustain", 0);
// 0.1 % (I want this to be value not %)
public static final ModelIdentifier DESTINATION_EG1_RELEASE
= new ModelIdentifier("eg", "release", 0); // timecent
public static final ModelIdentifier DESTINATION_EG1_SHUTDOWN
= new ModelIdentifier("eg", "shutdown", 0); // timecent
public static final ModelIdentifier DESTINATION_EG2_DELAY
= new ModelIdentifier("eg", "delay", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_ATTACK
= new ModelIdentifier("eg", "attack", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_HOLD
= new ModelIdentifier("eg", "hold", 1); // 0.1 %
public static final ModelIdentifier DESTINATION_EG2_DECAY
= new ModelIdentifier("eg", "decay", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_SUSTAIN
= new ModelIdentifier("eg", "sustain", 1);
// 0.1 % ( I want this to be value not %)
public static final ModelIdentifier DESTINATION_EG2_RELEASE
= new ModelIdentifier("eg", "release", 1); // timecent
public static final ModelIdentifier DESTINATION_EG2_SHUTDOWN
= new ModelIdentifier("eg", "shutdown", 1); // timecent
public static final ModelIdentifier DESTINATION_FILTER_FREQ
= new ModelIdentifier("filter", "freq", 0); // cent
public static final ModelIdentifier DESTINATION_FILTER_Q
= new ModelIdentifier("filter", "q", 0); // cB
private ModelIdentifier destination = DESTINATION_NONE;
private ModelTransform transform = new ModelStandardTransform();
public ModelDestination() {
}
public ModelDestination(ModelIdentifier id) {
destination = id;
}
public ModelIdentifier getIdentifier() {
return destination;
}
public void setIdentifier(ModelIdentifier destination) {
this.destination = destination;
}
public ModelTransform getTransform() {
return transform;
}
public void setTransform(ModelTransform transform) {
this.transform = transform;
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册