final AudioFormat af = new AudioFormat(Note.SAMPLE_RATE, 8, 1, true, true); SourceDataLine line = AudioSystem.getSourceDataLine(af); line.open(af, Note.SAMPLE_RATE); line.start();
true, // signed false); // bigEndian SourceDataLine sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start();
@Override public void start() { if (line != null) { LOG.debug("Sound already started"); return; } LOG.debug("Start sound"); try { line = AudioSystem.getSourceDataLine(FORMAT); line.open(FORMAT, BUFFER_SIZE); } catch (LineUnavailableException e) { throw new RuntimeException(e); } line.start(); buffer = new byte[line.getBufferSize()]; divider = (int) (Gameboy.TICKS_PER_SEC / FORMAT.getSampleRate()); }
public static void tone(int hz, int msecs, double vol) { try { byte[] buf = new byte[1]; AudioFormat af = new AudioFormat( SAMPLE_RATE, // sampleRate 8, // sampleSizeInBits 1, // channels true, // signed false); // bigEndian SourceDataLine sdl; sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i=0; i < msecs*8; i++) { double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI; buf[0] = (byte)(Math.sin(angle) * 127.0 * vol); sdl.write(buf,0,1); } sdl.drain(); sdl.stop(); sdl.close(); } catch (Exception e) { } }
public static void tone(int hz, int msecs, double vol) { try { byte[] buf = new byte[1]; AudioFormat af = new AudioFormat( SAMPLE_RATE, // sampleRate 8, // sampleSizeInBits 1, // channels true, // signed false); // bigEndian SourceDataLine sdl; sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i=0; i < msecs*8; i++) { double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI; buf[0] = (byte)(Math.sin(angle) * 127.0 * vol); sdl.write(buf,0,1); } sdl.drain(); sdl.stop(); sdl.close(); } catch (Exception e) { } }
public static void tone(int hz, int msecs, double vol) { try { byte[] buf = new byte[1]; AudioFormat af = new AudioFormat( SAMPLE_RATE, // sampleRate 8, // sampleSizeInBits 1, // channels true, // signed false); // bigEndian SourceDataLine sdl; sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i=0; i < msecs*8; i++) { double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI; buf[0] = (byte)(Math.sin(angle) * 127.0 * vol); sdl.write(buf,0,1); } sdl.drain(); sdl.stop(); sdl.close(); } catch (Exception e) { } }
dataLine = AudioSystem.getSourceDataLine( clip.getFormat() ); dataLine = AudioSystem.getSourceDataLine(afTemp); dataLine.open(); inputStream = new ByteArrayInputStream( audioData );
import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.SourceDataLine; [...] // Constructs a Mono, 48kHz, 2-bytes per sample, one sample per frame format */ AudioFormat af = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, 48000.0f, 16, 1, 2, 48000.0f, true ); SourceDataLine output = AudioSystem.getSourceDataLine( af ); output.open(); output.start(); // `output` should be ready for writing
/** * There are a number of AudioSystem methods that will return a configured Clip. This * convenience constructor allows us to obtain a SourceDataLine for the BigClip that uses the * same AudioFormat as the original Clip. * @param clip Clip The Clip used to configure the BigClip. */ public BigClip (Clip clip) throws LineUnavailableException { dataLine = AudioSystem.getSourceDataLine(clip.getFormat()); }
/** * There are a number of AudioSystem methods that will return a configured Clip. This * convenience constructor allows us to obtain a SourceDataLine for the BigClip that uses the * same AudioFormat as the original Clip. * @param clip Clip The Clip used to configure the BigClip. */ public BigClip (Clip clip) throws LineUnavailableException { dataLine = AudioSystem.getSourceDataLine(clip.getFormat()); }
/** * There are a number of AudioSystem methods that will return a configured Clip. This * convenience constructor allows us to obtain a SourceDataLine for the BigClip that uses the * same AudioFormat as the original Clip. * @param clip Clip The Clip used to configure the BigClip. */ public BigClip (Clip clip) throws LineUnavailableException { dataLine = AudioSystem.getSourceDataLine(clip.getFormat()); }
/** * There are a number of AudioSystem methods that will return a configured Clip. This * convenience constructor allows us to obtain a SourceDataLine for the BigClip that uses the * same AudioFormat as the original Clip. * @param clip Clip The Clip used to configure the BigClip. */ public BigClip (Clip clip) throws LineUnavailableException { dataLine = AudioSystem.getSourceDataLine(clip.getFormat()); }
/** * Creates a new local audio environment with the given audio formats. * * @param inputFormat * The format of the microphone input line. * @param outputFormat * The format of the speaker output line. * @throws LineUnavailableException * When either the input or output line can't be opened with the given format. */ public LocalAudioEnvironment(AudioFormat inputFormat, AudioFormat outputFormat) throws LineUnavailableException { this.sdl = AudioSystem.getSourceDataLine(outputFormat); this.tdl = AudioSystem.getTargetDataLine(inputFormat); }
public SourceDataLine openLine() throws LineUnavailableException { final AudioFormat af = new AudioFormat(sampleRate, 8, 1, true, true); final SourceDataLine line = AudioSystem.getSourceDataLine(af); line.open(af, sampleRate); line.start(); return line; }
public SourceDataLine openLine() throws LineUnavailableException { final AudioFormat af = new AudioFormat(sampleRate, 8, 1, true, true); final SourceDataLine line = AudioSystem.getSourceDataLine(af); line.open(af, sampleRate); line.start(); return line; }
@Override public void onActive() { if (audioLine != null) audioLine.close(); try { if (player.getMixer() != null) { log.debug("Custom mixer " + player.getMixer().getName()); audioLine = AudioSystem.getSourceDataLine(PCM, player.getMixer()); } else { audioLine = AudioSystem.getSourceDataLine(PCM); } audioLine.open(PCM, 1048576); log.debug("player.volume : " + player.getVolume()); onVolumeChanged(player.getVolume()); if (isMuted && audioLine.isControlSupported(BooleanControl.Type.MUTE)) ((BooleanControl) audioLine.getControl(BooleanControl.Type.MUTE)).setValue(true); } catch (LineUnavailableException e) { log.error("onActive error", e); } }
public static void tone(int hz, int msecs, double vol) { try { byte[] buf = new byte[1]; AudioFormat af = new AudioFormat( SAMPLE_RATE, // sampleRate 8, // sampleSizeInBits 1, // channels true, // signed false); // bigEndian SourceDataLine sdl; sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i=0; i < msecs*8; i++) { double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI; buf[0] = (byte)(Math.sin(angle) * 127.0 * vol); sdl.write(buf,0,1); } sdl.drain(); sdl.stop(); sdl.close(); } catch (Exception e) { } }
public static void tone(int hz, int msecs, double vol) { try { byte[] buf = new byte[1]; AudioFormat af = new AudioFormat( SAMPLE_RATE, // sampleRate 8, // sampleSizeInBits 1, // channels true, // signed false); // bigEndian SourceDataLine sdl; sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i=0; i < msecs*8; i++) { double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI; buf[0] = (byte)(Math.sin(angle) * 127.0 * vol); sdl.write(buf,0,1); } sdl.drain(); sdl.stop(); sdl.close(); } catch (Exception e) { } }
public static void tone(int hz, int msecs, double vol) { try { byte[] buf = new byte[1]; AudioFormat af = new AudioFormat( SAMPLE_RATE, // sampleRate 8, // sampleSizeInBits 1, // channels true, // signed false); // bigEndian SourceDataLine sdl; sdl = AudioSystem.getSourceDataLine(af); sdl.open(af); sdl.start(); for (int i=0; i < msecs*8; i++) { double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI; buf[0] = (byte)(Math.sin(angle) * 127.0 * vol); sdl.write(buf,0,1); } sdl.drain(); sdl.stop(); sdl.close(); } catch (Exception e) { } }
private static void decodeAAC(String in) throws Exception { SourceDataLine line = null; byte[] b; try { final ADTSDemultiplexer adts = new ADTSDemultiplexer(new FileInputStream(in)); final Decoder dec = new Decoder(adts.getDecoderSpecificInfo()); final SampleBuffer buf = new SampleBuffer(); while(true) { b = adts.readNextFrame(); dec.decodeFrame(b, buf); if(line==null) { final AudioFormat aufmt = new AudioFormat(buf.getSampleRate(), buf.getBitsPerSample(), buf.getChannels(), true, true); line = AudioSystem.getSourceDataLine(aufmt); line.open(); line.start(); } b = buf.getData(); line.write(b, 0, b.length); } } finally { if(line!=null) { line.stop(); line.close(); } } } }