本文整理汇总了Java中com.sun.media.sound.SF2Soundbank类的典型用法代码示例。如果您正苦于以下问题:Java SF2Soundbank类的具体用法?Java SF2Soundbank怎么用?Java SF2Soundbank使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SF2Soundbank类属于com.sun.media.sound包,在下文中一共展示了SF2Soundbank类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newInstrument
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public SF2Instrument newInstrument(SF2Soundbank sf2, String name,
Patch patch, SF2Layer... layers) {
/*
* Create SoundFont2 instrument.
*/
SF2Instrument ins = new SF2Instrument(sf2);
ins.setPatch(patch);
ins.setName(name);
sf2.addInstrument(ins);
/*
* Create region for instrument.
*/
for (int i = 0; i < layers.length; i++) {
SF2InstrumentRegion insregion = new SF2InstrumentRegion();
insregion.setLayer(layers[i]);
ins.getRegions().add(insregion);
}
return ins;
}
示例2: createTestSoundbank
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public static SF2Soundbank createTestSoundbank() {
// Create impulse instrument
// used to measure timing of note-on playback
SF2Soundbank soundbank = new SF2Soundbank();
float[] data = new float[100];
Arrays.fill(data, 0);
data[0] = 1.0f;
byte[] bdata = new byte[data.length * format.getFrameSize()];
AudioFloatConverter.getConverter(format).toByteArray(data, bdata);
SF2Sample sample = new SF2Sample(soundbank);
sample.setName("Test Sample");
sample.setData(bdata);
sample.setSampleRate((long) format.getSampleRate());
sample.setOriginalPitch(69);
soundbank.addResource(sample);
SF2Layer layer = new SF2Layer(soundbank);
layer.setName("Test Layer");
soundbank.addResource(layer);
SF2LayerRegion region = new SF2LayerRegion();
region.setSample(sample);
layer.getRegions().add(region);
SF2Instrument ins = new SF2Instrument(soundbank);
ins.setName("Test Instrument");
soundbank.addInstrument(ins);
SF2InstrumentRegion insregion = new SF2InstrumentRegion();
insregion.setLayer(layer);
ins.getRegions().add(insregion);
return soundbank;
}
示例3: createTestSoundbankWithChannelMixer
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public static Soundbank createTestSoundbankWithChannelMixer() {
SF2Soundbank soundbank = createTestSoundbank();
SimpleSoundbank simplesoundbank = new SimpleSoundbank();
SimpleInstrument simpleinstrument = new SimpleInstrument() {
public ModelChannelMixer getChannelMixer(MidiChannel channel,
AudioFormat format) {
return new ModelAbstractChannelMixer() {
boolean active = true;
public boolean process(float[][] buffer, int offset, int len) {
for (int i = 0; i < buffer.length; i++) {
float[] cbuffer = buffer[i];
for (int j = 0; j < cbuffer.length; j++) {
cbuffer[j] = -cbuffer[j];
}
}
return active;
}
public void stop() {
active = false;
}
};
}
};
simpleinstrument.add(soundbank.getInstruments()[0]);
simplesoundbank.addInstrument(simpleinstrument);
return simplesoundbank;
}
示例4: getSoundbank
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
try {
return new SF2Soundbank(url);
} catch (RIFFInvalidFormatException e) {
return null;
}
}
示例5: loadInstruments
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
private boolean loadInstruments() {
try {
SF2Soundbank soundbank = new SF2Soundbank(new FileInputStream(
new File(getConfig().getString("SoundFont"))));
synthesizer.loadAllInstruments(soundbank);
} catch (IOException e) {
return false;
}
for (javax.sound.midi.Instrument instrument : synthesizer
.getLoadedInstruments()) {
instruments.add(new Instrument(instrument.getPatch().getProgram(),
new InstrumentInformation(instrument.getName(), "")));
}
return true;
}
示例6: newSimpleFFTSample
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public SF2Sample newSimpleFFTSample(SF2Soundbank sf2, String name,
double[] data, double base, int fadeuptime) {
int fftsize = data.length / 2;
AudioFormat format = new AudioFormat(44100, 16, 1, true, false);
double basefreq = (base / fftsize) * format.getSampleRate() * 0.5;
randomPhase(data);
ifft(data);
data = realPart(data);
normalize(data, 0.9);
float[] fdata = toFloat(data);
fdata = loopExtend(fdata, fdata.length + 512);
fadeUp(fdata, fadeuptime);
byte[] bdata = toBytes(fdata, format);
/*
* Create SoundFont2 sample.
*/
SF2Sample sample = new SF2Sample(sf2);
sample.setName(name);
sample.setData(bdata);
sample.setStartLoop(256);
sample.setEndLoop(fftsize + 256);
sample.setSampleRate((long) format.getSampleRate());
double orgnote = (69 + 12)
+ (12 * Math.log(basefreq / 440.0) / Math.log(2));
sample.setOriginalPitch((int) orgnote);
sample.setPitchCorrection((byte) (-(orgnote - (int) orgnote) * 100.0));
sf2.addResource(sample);
return sample;
}
示例7: newLayer
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public SF2Layer newLayer(SF2Soundbank sf2, String name, SF2Sample sample) {
SF2LayerRegion region = new SF2LayerRegion();
region.setSample(sample);
SF2Layer layer = new SF2Layer(sf2);
layer.setName(name);
layer.getRegions().add(region);
sf2.addResource(layer);
return layer;
}
示例8: main
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
// Create instance of the synthesizer with very low polyphony
AudioSynthesizer synth = new SoftSynthesizer();
AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
Map<String, Object> p = new HashMap<String, Object>();
p.put("max polyphony", new Integer(5));
AudioInputStream stream = synth.openStream(format, p);
// Create instrument with too many regions (more than max polyphony)
SF2Soundbank sf2 = new SF2Soundbank();
SF2Sample sample = new SF2Sample(sf2);
sample.setName("test sample");
sample.setData(new byte[100]);
sample.setSampleRate(44100);
sample.setOriginalPitch(20);
sf2.addResource(sample);
SF2Layer layer = new SF2Layer(sf2);
layer.setName("test layer");
sf2.addResource(layer);
for (int i = 0; i < 100; i++) {
SF2LayerRegion region = new SF2LayerRegion();
region.setSample(sample);
layer.getRegions().add(region);
}
SF2Instrument ins = new SF2Instrument(sf2);
ins.setPatch(new Patch(0,0));
ins.setName("test instrument");
sf2.addInstrument(ins);
SF2InstrumentRegion insregion = new SF2InstrumentRegion();
insregion.setLayer(layer);
ins.getRegions().add(insregion);
// Load the test soundbank into the synthesizer
synth.unloadAllInstruments(synth.getDefaultSoundbank());
synth.loadAllInstruments(sf2);
// Send out one midi on message
MidiChannel ch1 = synth.getChannels()[0];
ch1.programChange(0);
ch1.noteOn(64, 64);
// Read 1 sec from stream
stream.skip(format.getFrameSize() * ((int)(format.getFrameRate() * 2)));
// Close the synthesizer after use
synth.close();
}
示例9: SF2Instrument
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public SF2Instrument(SF2Soundbank soundbank) {
super(soundbank, null, null, null);
}
示例10: SF2Layer
import com.sun.media.sound.SF2Soundbank; //导入依赖的package包/类
public SF2Layer(SF2Soundbank soundBank) {
super(soundBank, null, null);
}