/** * Writes one sample (between -1.0 and +1.0) to standard audio. * If the sample is outside the range, it will be clipped. * * @param sample the sample to play * @throws IllegalArgumentException if the sample is {@code Double.NaN} */ public static void play(double sample) { // clip if outside [-1, +1] if (Double.isNaN(sample)) throw new IllegalArgumentException("sample is NaN"); if (sample < -1.0) sample = -1.0; if (sample > +1.0) sample = +1.0; // convert to bytes short s = (short) (MAX_16_BIT * sample); buffer[bufferSize++] = (byte) s; buffer[bufferSize++] = (byte) (s >> 8); // little Endian // send to sound card if buffer is full if (bufferSize >= buffer.length) { line.write(buffer, 0, buffer.length); bufferSize = 0; } }
int nBytesWritten = sourceLine.write(abData, 0, nBytesRead);
sourceDataLine.write(soundbytes, 0, soundbytes.length); System.out.println(soundbytes.toString()); sourceDataLine.drain();
ms = Math.min(ms, Note.SECONDS * 1000); int length = Note.SAMPLE_RATE * ms / 1000; int count = line.write(note.data(), 0, length);
i < end && i < data.length; i++) { Utils.toBytes(data[i], frame, false); line.write(frame, 0, frame.length);
int count = 0; while ((count = ais.read(samples, 0, BUFFER_SIZE)) != -1) { line.write(samples, 0, count);
double angle = i / (SAMPLE_RATE / hz) * 2.0 * Math.PI; buf[0] = (byte)(Math.sin(angle) * 127.0 * vol); sdl.write(buf,0,1);
@Override public void play(int left, int right) { if (tick++ != 0) { tick %= divider; return; } Preconditions.checkArgument(left >= 0); Preconditions.checkArgument(left < 256); Preconditions.checkArgument(right >= 0); Preconditions.checkArgument(right < 256); buffer[i++] = (byte) (left); buffer[i++] = (byte) (right); if (i > BUFFER_SIZE / 2) { line.write(buffer, 0, i); i = 0; } } }
line.write(abData, 0, nRead);
line.write(abData, 0, nRead);
byte[] buf = new byte[ 1 ];; AudioFormat af = new AudioFormat( (float )44100, 8, 1, true, false ); SourceDataLine sdl = AudioSystem.getSourceDataLine( af ); sdl.open(); sdl.start(); for( int i = 0; i < 1000 * (float )44100 / 1000; i++ ) { double angle = i / ( (float )44100 / 440 ) * 2.0 * Math.PI; buf[ 0 ] = (byte )( Math.sin( angle ) * 100 ); sdl.write( buf, 0, 1 ); } sdl.drain(); sdl.stop();
public void run() { try { sourceDataLine.flush(); int len; while ((len = audioInputStream.read(tempBuffer, 0, tempBuffer.length)) != -1) { if (breaked_out) { break; } if (len > 0) { sourceDataLine.write(tempBuffer, 0, len); } } //breaked or stopped sourceDataLine.flush(); sourceDataLine.close(); breaked = true; } catch (Exception e) { log.error("Thread error: " + e); } } }
line.write(buffer, 0, buffer.length); line.drain(); line.stop();
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) { } }
public void run() { while (m_nRepeatCount >= 0) { m_line.write(m_abClip, 0, m_abClip.length); m_nRepeatCount--; } }
newData = tempData; dataLine.write(newData, 0, newData.length); if (startOrMove) { data = new byte[bufSize/
private void play(final SourceDataLine line, final Integer tone, final int ms) { final int length = fill(tone, ms); int count = 0; while (count < length) { final int r = line.write(buf, count, length - count); if (r <= 0) throw new RuntimeException("Could not write to line"); count += r; } }
public static void play() { if (!PLAYING) { SDL.start(); } for (int i = 0; i < (44100 / 60); i++) { int number = STREAM.getAsInt(); BUF[0] = (byte) number; SDL.write(BUF, 0, 1); } }