本文整理汇总了Java中javax.sound.sampled.LineUnavailableException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java LineUnavailableException.printStackTrace方法的具体用法?Java LineUnavailableException.printStackTrace怎么用?Java LineUnavailableException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sound.sampled.LineUnavailableException
的用法示例。
在下文中一共展示了LineUnavailableException.printStackTrace方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playGradient
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
public static void playGradient(double fstart,double fend,double duration,double volume,byte fadeend,byte wave) {
byte[] freqdata = new byte[(int)(duration * SAMPLE_RATE)];
// Generate the sound
for(int i = 0; i < freqdata.length; i++) {
freqdata[i] = (byte)generateValue(i, duration, fstart + (fend-fstart) * (i/(double)freqdata.length), volume, fadeend, wave);
}
// Play it
try {
final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
SourceDataLine line = AudioSystem.getSourceDataLine(af);
line.open(af, SAMPLE_RATE);
line.start();
line.write(freqdata, 0, freqdata.length);
line.drain();
line.close();
}catch(LineUnavailableException e) {
e.printStackTrace();
}
}
示例2: playSound
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
/**
* Play a sound at a given frequency freq during duration (in seconds) with volume as strenght
* <br/><br/>
* <code>SoundGenerator.playSound(440.0,1.0,0.5,SoundGenerator.FADE_LINEAR,SoundGenerator.WAVE_SIN);</code><br/>
* Available fades : FADE_NONE, FADE_LINEAR, FADE_QUADRATIC<br/>
* Available waves : WAVE_SIN, WAVE_SQUARE, WAVE_TRIANGLE, WAVE_SAWTOOTH<br/>
*/
public static void playSound(double freq,double duration,double volume,byte fade,byte wave){
double[] soundData = generateSoundData(freq,duration,volume,fade,wave);
byte[] freqdata = new byte[soundData.length];
for(int i = 0;i < soundData.length;i++) {
freqdata[i] = (byte)soundData[i];
}
// Play it
try {
final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
SourceDataLine line = AudioSystem.getSourceDataLine(af);
line.open(af, SAMPLE_RATE);
line.start();
line.write(freqdata, 0, freqdata.length);
line.drain();
line.close();
}catch(LineUnavailableException e) {
e.printStackTrace();
}
}
示例3: restartSDL
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
public void restartSDL(){
AudioFormat form = new AudioFormat(sys.getSampleRate(),16,2,true,false);
bufptr=0;
audioints = new int[(int)((sys.getSampleRate()/1000.0)*sys.getBufferSize())*2];
if(scope!=null)
scope.setAudio(audioints);
audiobuffer = new byte[audioints.length*2];
try {
if(sdl!=null)
sdl.close();
sdl = AudioSystem.getSourceDataLine(form);
sdl.open(form,audiobuffer.length*3);
sdl.start();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
示例4: run
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
public void run () {
//create a separate thread for recording
Thread recordThread = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("Start recording...");
recorder.start();
} catch (LineUnavailableException ex) {
ex.printStackTrace();
System.exit(-1);
}
}
});
recordThread.start();
// try {
// Thread.sleep(RECORD_TIME);
// } catch (InterruptedException ex) {
// ex.printStackTrace();
// }
}
示例5: run
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
@Override
public void run(String... args) {
String inputResource = AudioResourceUtils.sanitizeResource(args[0]);
AudioDispatcher d;
try {
d = AudioDispatcherFactory.fromPipe(inputResource, TARGET_SAMPLE_RATE, 2028, 0);
d.addAudioProcessor(new AudioPlayer(JVMAudioInputStream.toAudioFormat(d.getFormat())));
d.run();
} catch (LineUnavailableException e) {
e.printStackTrace();
System.err.print(e.getLocalizedMessage());
}
}
示例6: monitor
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
@Override
public void monitor(String query, int maxNumberOfReqults, Set<Integer> avoid, QueryResultHandler handler) {
int samplerate = Config.getInt(Key.RAFS_SAMPLE_RATE);
int size = Config.getInt(Key.MONITOR_STEP_SIZE) * samplerate;
int overlap = Config.getInt(Key.MONITOR_OVERLAP) * samplerate;
AudioDispatcher d ;
if (query.equals(Panako.DEFAULT_MICROPHONE)){
try {
d = AudioDispatcherFactory.fromDefaultMicrophone(samplerate,size, overlap);
} catch (LineUnavailableException e) {
LOG.warning("Could not connect to default microphone!" + e.getMessage());
e.printStackTrace();
d = null;
}
}else{
d = AudioDispatcherFactory.fromPipe(query, samplerate, size, overlap);
}
d.setZeroPadFirstBuffer(true);
d.addAudioProcessor(new AudioProcessor() {
@Override
public boolean process(AudioEvent audioEvent) {
double timeStamp = audioEvent.getTimeStamp() - Config.getInt(Key.MONITOR_OVERLAP);
processMonitorQuery(audioEvent.getFloatBuffer().clone(), handler,timeStamp,avoid);
return true;
}
@Override
public void processingFinished() {
}
});
d.run();
}
示例7: monitor
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
public void monitor(String query,final SerializedFingerprintsHandler handler){
int samplerate = Config.getInt(Key.NFFT_SAMPLE_RATE);
int size = Config.getInt(Key.MONITOR_STEP_SIZE) * samplerate;
int overlap = Config.getInt(Key.MONITOR_OVERLAP) * samplerate;
AudioDispatcher d ;
if (query.equals(Panako.DEFAULT_MICROPHONE)){
try {
d = AudioDispatcherFactory.fromDefaultMicrophone(samplerate,size, overlap);
} catch (LineUnavailableException e) {
LOG.warning("Could not connect to default microphone!" + e.getMessage());
e.printStackTrace();
d = null;
}
}else{
d = AudioDispatcherFactory.fromPipe(query, samplerate, size, overlap);
}
d.addAudioProcessor(new AudioProcessor() {
@Override
public boolean process(AudioEvent audioEvent) {
double timeStamp = audioEvent.getTimeStamp() - Config.getInt(Key.MONITOR_OVERLAP);
processMonitorQueryToSerializeFingerprints(audioEvent.getFloatBuffer().clone(), handler,timeStamp);
return true;
}
@Override
public void processingFinished() {
}
});
d.run();
}
示例8: playSounds
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
/**
* Same as playSound but plays several frequences at the same time<br/>
* <code>
* double[] freqs = {440.0,440*1.5}; <br/>
* SoundGenerator.playSound(freqs,1.0,0.5,SoundGenerator.FADE_LINEAR,SoundGenerator.WAVE_SIN);
* </code>
*
*/
public static void playSounds(double[] freqs,double duration,double volume,byte fade,byte wave) {
if(freqs.length == 0) {
System.err.println("No frequences to play !");
return;
}
volume = volume / freqs.length; // ease volume to avoid overflow
double[][] soundData = new double[freqs.length][];
for(int i = 0;i < soundData.length;i++) {
soundData[i] = generateSoundData(freqs[i],duration,volume,fade,wave);
}
byte[] freqdata = new byte[soundData[0].length];
for(int i = 0;i < soundData[0].length;i++) {
for(int j = 0;j < soundData.length;j++) {
freqdata[i] += (byte)(soundData[j][i]);
}
}
// Play it
try {
final AudioFormat af = new AudioFormat(SAMPLE_RATE, 8, 1, true, true);
SourceDataLine line = AudioSystem.getSourceDataLine(af);
line.open(af, SAMPLE_RATE);
line.start();
line.write(freqdata, 0, freqdata.length);
line.drain();
line.close();
}catch(LineUnavailableException e) {
e.printStackTrace();
}
}
示例9: main
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
/** test class by just printing . when it gets beats */
public static void main (String[] args){
try{
VirtualDrummerMicrophoneInput reporter = new VirtualDrummerMicrophoneInput();
reporter.addBeatListener(new DrumBeatSoundPrinter());
reporter.startReporting();
} catch ( LineUnavailableException e ){
e.printStackTrace();
System.exit(1);
}
}
示例10: getAudioInfo
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
void getAudioInfo (){
Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
log.info(mixerInfos.length + " mixers");
for ( int i = 0 ; i < mixerInfos.length ; i++ ){
Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
System.out.println("Mixer " + mixer);
// target data lines
Line.Info[] lineInfos = mixer.getTargetLineInfo();
System.out.println("\t" + lineInfos.length + " lineInfos");
for ( int j = 0 ; j < lineInfos.length ; j++ ){
if ( lineInfos[j] instanceof DataLine.Info ){
AudioFormat[] formats = ( (DataLine.Info)lineInfos[j] ).getFormats();
System.out.println("\t\t\t" + formats.length + " formats");
for ( int k = 0 ; k < formats.length ; k++ ){
System.out.println("\t\tFormat " + formats[k]);
}
}
Line line = null;
try{
line = mixer.getLine(lineInfos[j]);
System.out.println("\tLine " + line);
} catch ( LineUnavailableException e ){
e.printStackTrace();
}
}
}
}
示例11: openMixer
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
public void openMixer() {
InputStream byteArrayInputStream = new ByteArrayInputStream(playbuffer);
audioInputStream = new AudioInputStream(byteArrayInputStream, audioFormat, playbuffer.length / audioFormat.getFrameSize());
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
try {
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
} catch (LineUnavailableException e) {
e.printStackTrace();
}
}
示例12: main
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
public static void main(String argv[]) throws Exception {
boolean success = true;
Mixer.Info [] infos = AudioSystem.getMixerInfo();
for (int i=0; i<infos.length; i++) {
Mixer mixer = AudioSystem.getMixer(infos[i]);
System.out.println("Mixer is: " + mixer);
Line.Info [] target_line_infos = mixer.getTargetLineInfo();
for (int j = 0; j < target_line_infos.length; j++) {
try {
System.out.println("Trying to get:" + target_line_infos[j]);
mixer.getLine(target_line_infos[j]);
} catch (IllegalArgumentException iae) {
System.out.println("Unexpected IllegalArgumentException raised:");
iae.printStackTrace();
success = false;
} catch (LineUnavailableException lue) {
System.out.println("Unexpected LineUnavailableException raised:");
lue.printStackTrace();
success = false;
}
}
}
if (success) {
System.out.println("Test passed");
} else {
throw new Exception("Test FAILED");
}
}
示例13: jButton16ActionPerformed
import javax.sound.sampled.LineUnavailableException; //导入方法依赖的package包/类
private void jButton16ActionPerformed(
java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
System.out.print("\7"); //Вот это вот издает звук
Clip clip = null;
try {
clip = AudioSystem.getClip();
} catch (LineUnavailableException ex) {
ex.printStackTrace();
}
byte[] buf = new byte[1024];
for (int j = 0; j < buf.length; j++) {
buf[j] = (byte) j;
}
AudioFormat af = new AudioFormat(
11025f,
8, // sample size in bits
2, // channels
true, // signed
false // bigendian
);
try {
byte[] b = buf;
AudioInputStream ais = new AudioInputStream(new ByteArrayInputStream(b), af, 512);
clip.open(ais);
} catch (Exception e) {
e.printStackTrace();
}
}