/** Obtain the value of a default provider property.
@param typeClass The type of the default provider property. This
should be one of Receiver.class, Transmitter.class, Sequencer.class,
Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
Clip.class or Port.class.
@return The complete value of the property, if available.
If the property is not set, null is returned.
*/
private static synchronized String getDefaultProvider(Class typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String name = typeClass.getName();
String value = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(name));
if (value == null) {
value = getProperties().getProperty(name);
}
if ("".equals(value)) {
value = null;
}
return value;
}
java类javax.sound.sampled.TargetDataLine的实例源码
JDK13Services.java 文件源码
项目:jdk8u-dev-jdk
阅读 26
收藏 0
点赞 0
评论 0
JVSTSynthMidiDeviceTest.java 文件源码
项目:frinika
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void testOpenMidiDevice() throws Exception
{
FrinikaJVSTSynth synth = (FrinikaJVSTSynth) MidiSystem.getMidiDevice(new FrinikaJVSTSynthProvider.FrinikaJVSTSynthProviderInfo());
final TargetDataLine line = (TargetDataLine)((Mixer)synth).getLine( new Line.Info(TargetDataLine.class));
AudioFormat.Encoding PCM_FLOAT = new AudioFormat.Encoding("PCM_FLOAT");
AudioFormat format = new AudioFormat(PCM_FLOAT, 44100, 32, 2, 4*2, 44100, ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN));
line.open(format);
AudioInputStream ais = new AudioInputStream(line);
assertTrue(AudioSystem.isConversionSupported(Encoding.PCM_SIGNED, ais.getFormat()));
AudioInputStream convertedAis = AudioSystem.getAudioInputStream(Encoding.PCM_SIGNED, ais);
SourceDataLine sdl = AudioSystem.getSourceDataLine(convertedAis.getFormat());
sdl.open();
sdl.start();
byte[] buf = new byte[16384];
ShortMessage shm = new ShortMessage();
shm.setMessage(ShortMessage.NOTE_ON, 1, 40, 127);
synth.getReceiver().send(shm,-1);
for(int n=0;n<20;n++)
{
int read = convertedAis.read(buf);
sdl.write(buf, 0, read);
}
}
MixerAudioDeviceHandle.java 文件源码
项目:frinika
阅读 16
收藏 0
点赞 0
评论 0
/**
*@deprecated To be rpelaced with COnnections
*/
public TargetDataLine getLine() { // DataLine.Info infoIn) {
try {
System.out.println(this + " **** " + af);
DataLine.Info infoIn = new DataLine.Info(TargetDataLine.class, af);
// lineIn =
// (TargetDataLine)AudioSystem.getMixer(mixers.get(0)).getLine(infoIn);
line = (TargetDataLine) mixer.getLine(infoIn);
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
JavaSoundAudioGrabber.java 文件源码
项目:openimaj
阅读 17
收藏 0
点赞 0
评论 0
/**
* Open a line to the Java Sound APIs.
*
* @throws Exception
* if the Java sound system could not be initialised.
*/
private void openJavaSound() throws Exception {
// Convert the OpenIMAJ audio format to a Java Sound audio format object
final javax.sound.sampled.AudioFormat audioFormat = new javax.sound.sampled.AudioFormat(
(int) (this.getFormat().getSampleRateKHz() * 1000), this
.getFormat().getNBits(), this.getFormat()
.getNumChannels(), this.getFormat().isSigned(), this
.getFormat().isBigEndian());
System.out.println("Creating Java Sound Line with " + this.getFormat());
// Create info to create an output data line
final DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
try {
// Get the output line to write to using the given
// sample format we just created.
this.mLine = (TargetDataLine) AudioSystem.getLine(info);
// If no exception has been thrown we open the line.
this.mLine.open(audioFormat);
} catch (final LineUnavailableException e) {
throw new Exception("Could not open Java Sound audio line for"
+ " the audio format " + this.getFormat());
}
}
JavaSoundAudioDevice.java 文件源码
项目:jsyn
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void start() {
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
if (!AudioSystem.isLineSupported(info)) {
// Handle the error.
logger.severe("JavaSoundInputStream - not supported." + format);
} else {
try {
line = (TargetDataLine) getDataLine(info);
int bufferSize = calculateBufferSize(suggestedInputLatency);
line.open(format, bufferSize);
logger.fine("Input buffer size = " + bufferSize + " bytes.");
line.start();
} catch (Exception e) {
e.printStackTrace();
line = null;
}
}
}
JDK13Services.java 文件源码
项目:jdk7-jdk
阅读 22
收藏 0
点赞 0
评论 0
/** Obtain the value of a default provider property.
@param typeClass The type of the default provider property. This
should be one of Receiver.class, Transmitter.class, Sequencer.class,
Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
Clip.class or Port.class.
@return The complete value of the property, if available.
If the property is not set, null is returned.
*/
private static synchronized String getDefaultProvider(Class typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String value;
String propertyName = typeClass.getName();
value = JSSecurityManager.getProperty(propertyName);
if (value == null) {
value = getProperties().getProperty(propertyName);
}
if ("".equals(value)) {
value = null;
}
return value;
}
SimpleTuner.java 文件源码
项目:simpleguitartuner
阅读 18
收藏 0
点赞 0
评论 0
public void start() {
System.out.println("Simple Guitar Tuner");
System.out.println("To exit the progeramm, press <CTRL> + <C>");
System.out.println("Which guitar string you want to tune: \033[0;1me1, a, d, g, h, e2\033[0;0m?");
AudioFormat audioFormat = new AudioFormat(8000.0F, 8, 1, true, false);
DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
try {
TargetDataLine targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
targetDataLine.open(audioFormat);
CaptureThread captureThread = new CaptureThread(targetDataLine);
UserKeyboardInputThread ukit = new UserKeyboardInputThread(captureThread);
ukit.start();
captureThread.start();
} catch (Exception e2) {
System.out.println("Error: Unable to start sound data acqusition: " + e2.getLocalizedMessage());
}
}
Recorder.java 文件源码
项目:SoundCenterClient
阅读 30
收藏 0
点赞 0
评论 0
public Recorder() {
try {
//Get microphone targetline
AudioFormat format = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, format, bufferSize);
targetLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
targetLine.open(getAudioFormat(), bufferSize);
} catch (LineUnavailableException e) {
App.logger.w("No supported microphone found.", e);
}
//Initialize the speex encoder
if (!mEncoder.init(1, 8, 16000, 1)) {
App.logger.w("Failed to initialize speex encoder!", null);
}
}
JDK13Services.java 文件源码
项目:openjdk-source-code-learn
阅读 19
收藏 0
点赞 0
评论 0
/** Obtain the value of a default provider property.
@param typeClass The type of the default provider property. This
should be one of Receiver.class, Transmitter.class, Sequencer.class,
Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
Clip.class or Port.class.
@return The complete value of the property, if available.
If the property is not set, null is returned.
*/
private static synchronized String getDefaultProvider(Class typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String value;
String propertyName = typeClass.getName();
value = JSSecurityManager.getProperty(propertyName);
if (value == null) {
value = getProperties().getProperty(propertyName);
}
if ("".equals(value)) {
value = null;
}
return value;
}
AudioCapture.java 文件源码
项目:myrobotlab
阅读 21
收藏 0
点赞 0
评论 0
public void captureAudio() {
try {
// Get everything set up for
// capture
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
targetDataLine.open(audioFormat);
targetDataLine.start();
// Create a thread to capture the
// microphone data and start it
// running. It will run until
// the Stop button is clicked.
Thread captureThread = new Thread(new CaptureThread());
captureThread.start();
} catch (Exception e) {
Logging.logError(e);
}
broadcastState();
// end catch
}