本文整理汇总了Java中javax.sound.sampled.DataLine类的典型用法代码示例。如果您正苦于以下问题:Java DataLine类的具体用法?Java DataLine怎么用?Java DataLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataLine类属于javax.sound.sampled包,在下文中一共展示了DataLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: VirtualDrummerMicrophoneInput
import javax.sound.sampled.DataLine; //导入依赖的package包/类
/** Creates a new instance of test. Opens the microphone input as the target line.
* To start the reporting, {@link #start} the thread.
* @throws LineUnavailableException if microphone input is not available
*/
public VirtualDrummerMicrophoneInput () throws LineUnavailableException{
// getAudioInfo(); // prints lots of useless information
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,sampleRate,8,1,1,sampleRate,false);
DataLine.Info dlinfo = new DataLine.Info(TargetDataLine.class,
format);
if ( AudioSystem.isLineSupported(dlinfo) ){
targetDataLine = (TargetDataLine)AudioSystem.getLine(dlinfo);
}
targetDataLine.open(format,bufferSize);
bufferSize=targetDataLine.getBufferSize();
gui = new DrumSoundDetectorDemo();
gui.setVirtualDrummerMicrophoneInput(this);
}
示例2: init
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private static void init() {
try {
// 44,100 samples per second, 16-bit audio, mono, signed PCM, little
// Endian
AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE);
// the internal buffer is a fraction of the actual buffer size, this
// choice is arbitrary
// it gets divided because we can't expect the buffered data to line
// up exactly with when
// the sound card decides to push out its samples.
buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE / 3];
} catch (LineUnavailableException e) {
System.out.println(e.getMessage());
}
// no sound gets made before this call
line.start();
}
示例3: main
import javax.sound.sampled.DataLine; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
AbstractRcomArgs a=new AbstractRcomArgs();
UtilCli.parse(a, args, true);
File folder=new File("/home/rizsi/tmp/video");
byte[] data=UtilFile.loadFile(new File(folder, "remote.sw"));
AudioFormat format=ManualTestEchoCancel.getFormat();
final Mixer mixer = AudioSystem.getMixer(null);
DataLine.Info info2= new DataLine.Info(SourceDataLine.class, format);
SourceDataLine s=(SourceDataLine) mixer.getLine(info2);
s.open(format, framesamples*2);
s.start();
try(LoopInputStream lis=new LoopInputStream(data))
{
try(JitterResampler rs=new JitterResampler(a, 8000, framesamples, 2))
{
new FeedThread(lis, rs).start();
final byte[] buffer=new byte[framesamples*2];;
while(true)
{
rs.readOutput(buffer);
s.write(buffer, 0, buffer.length);
}
}
}
}
示例4: createSourceDataLine
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private boolean createSourceDataLine() {
if (DEBUG || Printer.debug)Printer.debug("JavaSoundAudioClip.createSourceDataLine()");
try {
DataLine.Info info = new DataLine.Info(SourceDataLine.class, loadedAudioFormat);
if (!(AudioSystem.isLineSupported(info)) ) {
if (DEBUG || Printer.err)Printer.err("Line not supported: "+loadedAudioFormat);
// fail silently
return false;
}
SourceDataLine source = (SourceDataLine) AudioSystem.getLine(info);
datapusher = new DataPusher(source, loadedAudioFormat, loadedAudio, loadedAudioByteLength);
} catch (Exception e) {
if (DEBUG || Printer.err)e.printStackTrace();
// fail silently
return false;
}
if (datapusher==null) {
// fail silently
return false;
}
if (DEBUG || Printer.debug)Printer.debug("Created SourceDataLine.");
return true;
}
示例5: ExtendedClip
import javax.sound.sampled.DataLine; //导入依赖的package包/类
public ExtendedClip(JuggleMasterPro objPjuggleMasterPro, byte bytPsoundFileIndex) {
this.bytGsoundFileIndex = bytPsoundFileIndex;
try {
final AudioInputStream objLaudioInputStream =
AudioSystem.getAudioInputStream(new File(Strings.doConcat( objPjuggleMasterPro.strS_CODE_BASE,
Constants.strS_FILE_NAME_A[Constants.intS_FILE_FOLDER_SOUNDS],
objPjuggleMasterPro.chrGpathSeparator,
Constants.strS_FILE_SOUND_NAME_A[bytPsoundFileIndex])));
final AudioFormat objLaudioFormat = objLaudioInputStream.getFormat();
final DataLine.Info objLdataLineInfo =
new DataLine.Info(Clip.class, objLaudioFormat, (int) objLaudioInputStream.getFrameLength()
* objLaudioFormat.getFrameSize());
this.objGclip = (Clip) AudioSystem.getLine(objLdataLineInfo);
this.objGclip.open(objLaudioInputStream);
} catch (final Throwable objPthrowable) {
Tools.err("Error while initializing sound : ", Constants.strS_FILE_SOUND_NAME_A[bytPsoundFileIndex]);
this.objGclip = null;
}
}
示例6: getMaxLines
import javax.sound.sampled.DataLine; //导入依赖的package包/类
@Override
public int getMaxLines(Line.Info info) {
Line.Info fullInfo = getLineInfo(info);
// if it's not supported at all, return 0.
if (fullInfo == null) {
return 0;
}
if (fullInfo instanceof DataLine.Info) {
// DirectAudioDevices should mix !
return getMaxSimulLines();
}
return 0;
}
示例7: startPlayback
import javax.sound.sampled.DataLine; //导入依赖的package包/类
@Override
public void startPlayback(final ISyncAudioSource resampler) {
final AudioFormat format = StreamSourceAudio.getFormat();
new Thread("Audio output") {
private byte[] buffer;
public void run() {
try {
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
try(SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info))
{
line.open(format, StreamSourceAudio.requestBufferSize);
line.start();
buffer=new byte[line.getBufferSize()];
while(!resampler.isClosed())
{
resampler.readOutput(buffer);
line.write(buffer, 0, buffer.length);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
}
示例8: test
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private static void test(final AudioFormat format, final byte[] data)
throws Exception {
final Line.Info info = new DataLine.Info(Clip.class, format);
final Clip clip = (Clip) AudioSystem.getLine(info);
go = new CountDownLatch(1);
clip.addLineListener(event -> {
if (event.getType().equals(LineEvent.Type.START)) {
go.countDown();
}
});
clip.open(format, data, 0, data.length);
clip.start();
go.await();
while (clip.isRunning()) {
// This loop should not hang
}
while (clip.isActive()) {
// This loop should not hang
}
clip.close();
}
示例9: doLine2
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private static void doLine2(DataLine line, AudioFormat format) {
try {
System.out.println(" - call to open()");
line.open();
try {
System.out.println(" - line has format: "+line.getFormat());
if (!line.getFormat().matches(format)) {
System.out.println("## Error: expected this format: "+format);
failed++;
} else {
passed++;
}
} finally {
line.close();
System.out.println(" - closed");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例10: doMixerClip
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private static void doMixerClip(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("Clip from mixer "+mixer+":");
System.out.println(" "+mixer.getMixerInfo());
DataLine.Info info = new DataLine.Info(
Clip.class,
format);
if (mixer.isLineSupported(info)) {
Clip clip = (Clip) mixer.getLine(info);
doLine1(clip, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例11: doMixerSDL
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private static void doMixerSDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("SDL from mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
SourceDataLine.class,
format);
if (mixer.isLineSupported(info)) {
SourceDataLine sdl = (SourceDataLine) mixer.getLine(info);
doLine1(sdl, format);
doLine2(sdl, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例12: doMixerTDL
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private static void doMixerTDL(Mixer mixer, AudioFormat format) {
if (mixer==null) return;
try {
System.out.println("TDL from mixer "+mixer+":");
DataLine.Info info = new DataLine.Info(
TargetDataLine.class,
format);
if (mixer.isLineSupported(info)) {
TargetDataLine tdl = (TargetDataLine) mixer.getLine(info);
doLine1(tdl, format);
doLine2(tdl, format);
} else {
System.out.println(" - Line not supported");
}
} catch (Throwable t) {
System.out.println(" - Caught exception. Not failed.");
System.out.println(" - "+t.toString());
}
}
示例13: checkLines
import javax.sound.sampled.DataLine; //导入依赖的package包/类
public static void checkLines(Mixer mixer, Line.Info[] infos) {
for (int i = 0; i<infos.length; i++) {
try {
if (infos[i] instanceof DataLine.Info) {
DataLine.Info info = (DataLine.Info) infos[i];
System.out.println(" Line "+info+" (max. "+mixer.getMaxLines(info)+" simultaneously): ");
AudioFormat[] formats = info.getFormats();
for (int f = 0; f < formats.length; f++) {
try {
AudioFormat otherEndianOrSign = getOtherEndianOrSign(formats[f]);
if (otherEndianOrSign != null) {
checkFormat(formats, otherEndianOrSign);
}
} catch (Exception e1) {
out(" Unexpected exception when getting a format: "+e1);
}
}
}
} catch (Exception e) {
out(" Unexpected exception when getting a line: "+e);
}
}
}
示例14: playRecorded
import javax.sound.sampled.DataLine; //导入依赖的package包/类
void playRecorded(AudioFormat format, byte[] data) throws Exception {
//SourceDataLine line = AudioSystem.getSourceDataLine(format);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
SourceDataLine line = (SourceDataLine)AudioSystem.getLine(info);
line.open();
line.start();
int remaining = data.length;
while (remaining > 0) {
int avail = line.available();
if (avail > 0) {
if (avail > remaining)
avail = remaining;
int written = line.write(data, data.length - remaining, avail);
remaining -= written;
log("Playing: " + written + " bytes written");
} else {
delay(100);
}
}
line.drain();
line.stop();
}
示例15: enableHorn
import javax.sound.sampled.DataLine; //导入依赖的package包/类
private void enableHorn () throws UnsupportedAudioFileException, IOException, LineUnavailableException
{
if ( ( this.clip == null || !this.clip.isRunning () ) && Activator.getDefault ().getPreferenceStore ().getBoolean ( PreferenceConstants.BELL_ACTIVATED_KEY ) )
{
final AudioInputStream sound = AudioSystem.getAudioInputStream ( this.soundFile );
final DataLine.Info info = new DataLine.Info ( Clip.class, sound.getFormat () );
this.clip = (Clip)AudioSystem.getLine ( info );
this.clip.open ( sound );
this.clip.loop ( Clip.LOOP_CONTINUOUSLY );
}
if ( !this.bellIcon.isDisposed () )
{
this.bellIcon.setImage ( getBellIcon () );
}
}