List of usage examples for java.nio FloatBuffer get
public FloatBuffer get(float[] dest, int off, int len)
From source file:Main.java
public static void main(String[] args) { FloatBuffer floatBuffer = FloatBuffer.allocate(10); floatBuffer.put(0, 1.23F);/* w w w .j a va 2 s . c o m*/ floatBuffer.rewind(); float[] floatArray = new float[10]; floatBuffer.get(floatArray, 0, 3); System.out.println(Arrays.toString(floatArray)); }
From source file:Main.java
static void toArray(FloatBuffer src, float[] dst, int offset) { src.position(0);/* w w w . j a va 2 s . com*/ src.get(dst, offset, dst.length - offset); }
From source file:uk.co.modularaudio.service.jnajackaudioprovider.JNAJackAppRenderingSession.java
private void masterInBuffersResetOrCopy(final int numFrames, final long periodStartFrameTime) { final int numProducersUsed = (masterInBuffers.numAudioBuffers < numProducerAudioPorts ? masterInBuffers.numAudioBuffers : numProducerAudioPorts);// w w w .j a v a2s . c om int pac = 0; for (; pac < numProducersUsed; ++pac) { final JackPort pp = producerAudioPorts[pac]; final FloatBuffer fb = pp.getFloatBuffer(); final MadChannelBuffer aucb = masterInBuffers.audioBuffers[pac]; final float[] mifb = aucb.floatBuffer; // if( fb.hasArray() ) // { // aucb.floatBuffer = fb.array(); // } // else // { // Slow copy fb.get(mifb, 0, numFrames); // } } // Point the other channels at silence for (int r = pac; r < masterInBuffers.numAudioBuffers; ++r) { masterInBuffers.audioBuffers[r].floatBuffer = emptyFloatBuffer.floatBuffer; } // Should do midi in here for (int pmc = 0; pmc < numProducerMidiPorts; ++pmc) { try { final JackPort mp = producerMidiPorts[pmc]; final int numMidiEvents = JackMidi.getEventCount(mp); if (numMidiEvents > 0) { // log.debug("Processing " + numMidiEvents + " midi events"); } for (int i = 0; i < numMidiEvents; ++i) { JackMidi.eventGet(jme, mp, i); final int bufferSize = jme.size(); final byte[] jjmmb = jnaJackMidiMessage.getBuffer(); if (bufferSize > jjmmb.length) { log.error("Failed midi event byte size during get :-("); } else { jme.read(jjmmb); final long jackMidiEventTime = jme.time(); // log.debug("Within process() call at time " + periodStartFrameTime + " midi event with time " + jackMidiEventTime ); final long timestamp = periodStartFrameTime + jackMidiEventTime; midiToEventRingDecoder.decodeMessage(jnaJackMidiMessage.getCommand(), jnaJackMidiMessage.getChannel(), jnaJackMidiMessage.getData1(), jnaJackMidiMessage.getData2(), timestamp); } } // Now push from the ring into the master in buffer // Should do some magic to massage them into the right channels.... for (int c = 0; c < masterInBuffers.numMidiBuffers; ++c) { masterInBuffers.noteBuffers[c].numElementsInBuffer = 0; } // MadChannelNoteEvent[] noteBuf = masterInBuffers.noteBuffers[0].noteBuffer; // noteEventRing.readUpToMaxNum(target, pos, maxNum) final long startCandidateFrameTime = periodStartFrameTime; final long endCandidateFrameTime = startCandidateFrameTime + numFrames; final int numRead = noteEventRing.readUpToMaxNumAndFrameTime(tmpNoteEventArray, 0, tmpNoteEventArrayLength, endCandidateFrameTime); for (int n = 0; n < numRead; ++n) { final HardwareMidiNoteEvent midiEvent = tmpNoteEventArray[n]; final int eventMidiChannel = midiEvent.channel; final long eventFrameTime = midiEvent.eventFrameTime; if (eventMidiChannel <= masterInBuffers.numMidiBuffers) { final MadChannelBuffer midiChannelBuffer = masterInBuffers.noteBuffers[eventMidiChannel]; final MadChannelNoteEvent noteEvent = midiChannelBuffer.noteBuffer[midiChannelBuffer.numElementsInBuffer++]; final int sampleIndex = frameTimeToIndex(startCandidateFrameTime, endCandidateFrameTime, eventFrameTime); noteEvent.set(midiEvent.channel, sampleIndex, midiEvent.eventType, midiEvent.paramOne, midiEvent.paramTwo, midiEvent.paramThree); } } } catch (final JackException je) { if (log.isErrorEnabled()) { log.error("JackException caught in midi process ports: " + je.toString(), je); } } } }