/** * Get the audio format being used. * @return */ public AudioFormat getFormat() { return mLine.getFormat(); }
/** * @see io.github.amyassist.amy.core.audio.environment.AbstractAudioEnvironment#getOutputFormat() */ @Override public AudioFormat getOutputFormat() { return this.sdl.getFormat(); }
/** Converts a duration in milliseconds to a frame count. */ private int convertMillisecondsToFrames (long milliseconds) { return (int)(milliseconds / dataLine.getFormat().getSampleRate()); }
/** Converts a duration in milliseconds to a frame count. */ private int convertMillisecondsToFrames (long milliseconds) { return (int)(milliseconds / dataLine.getFormat().getSampleRate()); }
/** Converts a frame count to a duration in milliseconds. */ private long convertFramesToMilliseconds (int frames) { return (frames / (long)dataLine.getFormat().getSampleRate()) * 1000; }
/** Converts a duration in milliseconds to a frame count. */ private int convertMillisecondsToFrames (long milliseconds) { return (int)(milliseconds / dataLine.getFormat().getSampleRate()); }
/** Converts a frame count to a duration in milliseconds. */ private long convertFramesToMilliseconds (int frames) { return (frames / (long)dataLine.getFormat().getSampleRate()) * 1000; }
/** Converts a duration in milliseconds to a frame count. */ private int convertMillisecondsToFrames (long milliseconds) { return (int)(milliseconds / dataLine.getFormat().getSampleRate()); }
/** Converts a frame count to a duration in milliseconds. */ private long convertFramesToMilliseconds (int frames) { return (frames / (long)dataLine.getFormat().getSampleRate()) * 1000; }
public void addStreamer(MediaStreamer streamer) { synchronized(streamers) { streamers.add(streamer); if (audio != null) streamer.setAudioFormat(audio.getFormat()); } } public void removeStreamer(MediaStreamer streamer) {
/** Converts a frame count to a duration in milliseconds. */ private long convertFramesToMilliseconds (int frames) { return (frames / (long)dataLine.getFormat().getSampleRate()) * 1000; }
@Override public int getFramePosition () { long timeSinceLastPositionSet = System.currentTimeMillis() - timelastPositionSet; int size = dataLine.getBufferSize() * (format.getChannels() / 2) / bufferUpdateFactor; // Step down to the next whole frame. size /= dataLine.getFormat().getFrameSize(); size *= dataLine.getFormat().getFrameSize(); int framesSinceLast = (int)((timeSinceLastPositionSet / 1000f) * dataLine.getFormat().getFrameRate()); int framesRemainingTillTime = size - framesSinceLast; return framePosition - framesRemainingTillTime; }
@Override public int getFramePosition () { long timeSinceLastPositionSet = System.currentTimeMillis() - timelastPositionSet; int size = dataLine.getBufferSize() * (format.getChannels() / 2) / bufferUpdateFactor; // Step down to the next whole frame. size /= dataLine.getFormat().getFrameSize(); size *= dataLine.getFormat().getFrameSize(); int framesSinceLast = (int)((timeSinceLastPositionSet / 1000f) * dataLine.getFormat().getFrameRate()); int framesRemainingTillTime = size - framesSinceLast; return framePosition - framesRemainingTillTime; }
@Override public int getFramePosition () { long timeSinceLastPositionSet = System.currentTimeMillis() - timelastPositionSet; int size = dataLine.getBufferSize() * (format.getChannels() / 2) / bufferUpdateFactor; // Step down to the next whole frame. size /= dataLine.getFormat().getFrameSize(); size *= dataLine.getFormat().getFrameSize(); int framesSinceLast = (int)((timeSinceLastPositionSet / 1000f) * dataLine.getFormat().getFrameRate()); int framesRemainingTillTime = size - framesSinceLast; return framePosition - framesRemainingTillTime; }
@Override public int getFramePosition () { long timeSinceLastPositionSet = System.currentTimeMillis() - timelastPositionSet; int size = dataLine.getBufferSize() * (format.getChannels() / 2) / bufferUpdateFactor; // Step down to the next whole frame. size /= dataLine.getFormat().getFrameSize(); size *= dataLine.getFormat().getFrameSize(); int framesSinceLast = (int)((timeSinceLastPositionSet / 1000f) * dataLine.getFormat().getFrameRate()); int framesRemainingTillTime = size - framesSinceLast; return framePosition - framesRemainingTillTime; }
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; }
/** * @see io.github.amyassist.amy.core.audio.environment.AbstractAudioEnvironment#start() */ @Override public void start() { try { this.sdl.open(this.sdl.getFormat()); this.tdl.open(this.tdl.getFormat()); } catch (LineUnavailableException e) { throw new IllegalStateException(e); } this.sdl.start(); this.tdl.start(); super.start(); }
@Override public synchronized void flush() { if(format==null||source==null) return; final SampleSubmitter putter = getPutter(); if(putter==null) return; ByteBuffer scratch = getBuffer(); final int bufferSizeFrames = getBufferSizeFrames(); final int numChannels = format.getChannels(); final int numIterations = bufferSizeFrames * numChannels; try{for (int i = numIterations; i > 0; i--) putter.submit(scratch,source.get()); }catch(BufferUnderflowException e){System.out.println("UNDERFLOW: javaSoundSystem bufferSizeFrames="+bufferSizeFrames+" numChannels="+numChannels); throw e;} scratch.clear(); try{ final SourceDataLine sourceDataLine = getSourceDataLine(); final AudioFormat fmt = sourceDataLine.getFormat(); sourceDataLine.write(scratch.array(), 0, scratch.remaining());} catch(LineUnavailableException e){e.printStackTrace();}//TODO: Manage this better. }//end flush()
JSAudioOutput(SourceDataLine sdl, int bufferSize) { super(); this.bufferSize = bufferSize; format = sdl.getFormat(); buffer = new FloatSampleBuffer(format.getChannels(), bufferSize, format.getSampleRate()); mcBuffer = new MultiChannelBuffer(bufferSize, format.getChannels()); outBytes = new byte[buffer.getByteArrayBufferSize(format)]; finished = false; line = sdl; }
private void readSignal() { if (line.getFormat().getChannels() == Minim.MONO) { //long start = System.nanoTime(); signal.generate(buffer.getChannel(0)); //long end = System.nanoTime(); //long elap = (end - start) / 1000; //System.out.println("Generated a buffer in " + elap + " microseconds."); } else { signal.generate(buffer.getChannel(0), buffer.getChannel(1)); } }