本文整理汇总了Java中javax.sound.sampled.SourceDataLine类的典型用法代码示例。如果您正苦于以下问题:Java SourceDataLine类的具体用法?Java SourceDataLine怎么用?Java SourceDataLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceDataLine类属于javax.sound.sampled包,在下文中一共展示了SourceDataLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultProvider
import javax.sound.sampled.SourceDataLine; //导入依赖的package包/类
/** 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;
}
示例2: init
import javax.sound.sampled.SourceDataLine; //导入依赖的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: JSAudioRecording
import javax.sound.sampled.SourceDataLine; //导入依赖的package包/类
JSAudioRecording(JSMinim sys, byte[] samps, SourceDataLine sdl,
AudioMetaData mdata)
{
system = sys;
samples = samps;
meta = mdata;
format = sdl.getFormat();
finished = false;
line = sdl;
loop = false;
play = false;
numLoops = 0;
loopBegin = 0;
loopEnd = (int)AudioUtils.millis2BytesFrameAligned( meta.length(),
format );
rawBytes = new byte[sdl.getBufferSize() / 8];
iothread = null;
totalBytesRead = 0;
bytesWritten = 0;
shouldRead = true;
}
示例4: save
import javax.sound.sampled.SourceDataLine; //导入依赖的package包/类
/**
* Finishes the recording process by closing the file.
*/
public AudioRecordingStream save()
{
try
{
aos.close();
}
catch (IOException e)
{
Minim.error("AudioRecorder.save: An error occurred when trying to save the file:\n"
+ e.getMessage());
}
String filePath = filePath();
AudioInputStream ais = system.getAudioInputStream(filePath);
SourceDataLine sdl = system.getSourceDataLine(ais.getFormat(), 1024);
// this is fine because the recording will always be
// in a raw format (WAV, AU, etc).
long length = AudioUtils.frames2Millis(ais.getFrameLength(), format);
BasicMetaData meta = new BasicMetaData(filePath, length, ais.getFrameLength());
JSPCMAudioRecordingStream recording = new JSPCMAudioRecordingStream(system, meta, ais, sdl, 1024);
return recording;
}
示例5: playGradient
import javax.sound.sampled.SourceDataLine; //导入依赖的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();
}
}
示例6: playSound
import javax.sound.sampled.SourceDataLine; //导入依赖的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();
}
}
示例7: playSound
import javax.sound.sampled.SourceDataLine; //导入依赖的package包/类
/**
* Play a sound.
*
* @param in The {@code AudioInputStream} to play.
* @return True if the stream was played without incident.
* @exception IOException if unable to read or write the sound data.
*/
private boolean playSound(AudioInputStream in) throws IOException {
boolean ret = false;
SourceDataLine line = openLine(in.getFormat());
if (line == null) return false;
try {
startPlaying();
int rd;
while (keepPlaying() && (rd = in.read(data)) > 0) {
line.write(data, 0, rd);
}
ret = true;
} finally {
stopPlaying();
line.drain();
line.stop();
line.close();
}
return ret;
}
示例8: createSourceDataLine
import javax.sound.sampled.SourceDataLine; //导入依赖的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;
}
示例9: run
import javax.sound.sampled.SourceDataLine; //导入依赖的package包/类
public void run() {
byte[] buffer = SoftAudioPusher.this.buffer;
AudioInputStream ais = SoftAudioPusher.this.ais;
SourceDataLine sourceDataLine = SoftAudioPusher.this.sourceDataLine;
try {
while (active) {
// Read from audio source
int count = ais.read(buffer);
if(count < 0) break;
// Write byte buffer to source output
sourceDataLine.write(buffer, 0, count);
}
} catch (IOException e) {
active = false;
//e.printStackTrace();
}
}
示例10: run
import javax.sound.sampled.SourceDataLine; //导入依赖的package包/类
@Override
public void run() {
byte[] buffer = SoftAudioPusher.this.buffer;
AudioInputStream ais = SoftAudioPusher.this.ais;
SourceDataLine sourceDataLine = SoftAudioPusher.this.sourceDataLine;
try {
while (active) {
// Read from audio source
int count = ais.read(buffer);
if(count < 0) break;
// Write byte buffer to source output
sourceDataLine.write(buffer, 0, count);
}
} catch (IOException e) {
active = false;
//e.printStackTrace();
}
}
示例11: getDefaultProvider
import javax.sound.sampled.SourceDataLine; //导入依赖的package包/类
/** 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;
}
示例12: doMixerSDL
import javax.sound.sampled.SourceDataLine; //导入依赖的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());
}
}
示例13: playRecorded
import javax.sound.sampled.SourceDataLine; //导入依赖的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();
}
示例14: startPlayback
import javax.sound.sampled.SourceDataLine; //导入依赖的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();
}
示例15: main
import javax.sound.sampled.SourceDataLine; //导入依赖的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);
}
}
}
}