public static String lookupFourcc(AudioFormat format) { if (format.getSampleSizeInBits() == 16 && !format.isBigEndian()) return "sowt"; else if (format.getSampleSizeInBits() == 24) return "in24"; else throw new IllegalArgumentException("Audio format " + format + " is not supported."); }
public static String lookupFourcc(AudioFormat format) { if (format.getSampleSizeInBits() == 16 && !format.isBigEndian()) return "sowt"; else if (format.getSampleSizeInBits() == 24) return "in24"; else throw new IllegalArgumentException("Audio format " + format + " is not supported."); }
public static String lookupFourcc(AudioFormat format) { if (format.getSampleSizeInBits() == 16 && !format.isBigEndian()) return "sowt"; else if (format.getSampleSizeInBits() == 24) return "in24"; else throw new NotSupportedException("Audio format " + format + " is not supported."); }
/** * Deinterleaves audio samples from inb into outs using sample size from * format * * @param format * @param inb * @param outs */ public static void deinterleave(AudioFormat format, ByteBuffer inb, ByteBuffer[] outs) { int bytesPerSample = format.getSampleSizeInBits() >> 3; int bytesPerFrame = bytesPerSample * outs.length; while (inb.remaining() >= bytesPerFrame) { for (int j = 0; j < outs.length; j++) { for (int i = 0; i < bytesPerSample; i++) { outs[j].put(inb.get()); } } } } }
/** * Interleaves audio samples in ins into outb using sample size from the * format * * @param format * @param ins * @param outb */ public static void interleave(AudioFormat format, ByteBuffer[] ins, ByteBuffer outb) { int bytesPerSample = format.getSampleSizeInBits() >> 3; int bytesPerFrame = bytesPerSample * ins.length; int max = 0; for (int i = 0; i < ins.length; i++) if (ins[i].remaining() > max) max = ins[i].remaining(); for (int frames = 0; frames < max && outb.remaining() >= bytesPerFrame; frames++) { for (int j = 0; j < ins.length; j++) { if (ins[j].remaining() < bytesPerSample) { for (int i = 0; i < bytesPerSample; i++) outb.put((byte) 0); } else { for (int i = 0; i < bytesPerSample; i++) { outb.put(ins[j].get()); } } } } }
public static int fromInt(int[] data, int len, AudioFormat format, ByteBuffer buf) { if (!format.isSigned()) throw new NotSupportedException("Unsigned PCM is not supported ( yet? )."); if (format.getSampleSizeInBits() != 16 && format.getSampleSizeInBits() != 24) throw new NotSupportedException(format.getSampleSizeInBits() + " bit PCM is not supported ( yet? )."); if (format.isBigEndian()) { if (format.getSampleSizeInBits() == 16) { return fromInt16BE(buf, data, len); } else { return fromInt24BE(buf, data, len); } } else { if (format.getSampleSizeInBits() == 16) { return fromInt16LE(buf, data, len); } else { return fromInt24LE(buf, data, len); } } }
public static int toInt(AudioFormat format, ByteBuffer buf, int[] samples) { if (!format.isSigned()) throw new NotSupportedException("Unsigned PCM is not supported ( yet? )."); if (format.getSampleSizeInBits() != 16 && format.getSampleSizeInBits() != 24) throw new NotSupportedException(format.getSampleSizeInBits() + " bit PCM is not supported ( yet? )."); if (format.isBigEndian()) { if (format.getSampleSizeInBits() == 16) { return toInt16BE(buf, samples); } else { return toInt24BE(buf, samples); } } else { if (format.getSampleSizeInBits() == 16) { return toInt16LE(buf, samples); } else { return toInt24LE(buf, samples); } } }
/** * Converts PCM samples stored in buf and described with format to float * array representation * * @param format * Supported formats - *_*_S16_LE, *_*_S24_LE, *_*_S16_BE, * *_*_S24_LE * @param buf * @param floatBuf * @return Total number of samples read from the buffer */ public static void toFloat(AudioFormat format, ByteBuffer buf, FloatBuffer floatBuf) { if (!format.isSigned()) throw new NotSupportedException("Unsigned PCM is not supported ( yet? )."); if (format.getSampleSizeInBits() != 16 && format.getSampleSizeInBits() != 24) throw new NotSupportedException(format.getSampleSizeInBits() + " bit PCM is not supported ( yet? )."); if (format.isBigEndian()) { if (format.getSampleSizeInBits() == 16) { toFloat16BE(buf, floatBuf); } else { toFloat24BE(buf, floatBuf); } } else { if (format.getSampleSizeInBits() == 16) { toFloat16LE(buf, floatBuf); } else { toFloat24LE(buf, floatBuf); } } }
/** * Creates wav header for the specified audio format * * @param format * @param samples */ public static WavHeader createWavHeader(AudioFormat format, int samples) { WavHeader w = new WavHeader("RIFF", 40, "WAVE", new FmtChunk((short) 1, (short) format.getChannels(), format.getSampleRate(), format.getSampleRate() * format.getChannels() * (format.getSampleSizeInBits() >> 3), (short) (format.getChannels() * (format.getSampleSizeInBits() >> 3)), (short) format.getSampleSizeInBits()), 44, calcDataSize(format.getChannels(), format.getSampleSizeInBits() >> 3, samples)); return w; }
/** * Converts float PCM samples stored in floatBuf to integer representation * according to format and stores them in buf * * @param format * Supported formats - *_*_S16_LE, *_*_S24_LE, *_*_S16_BE, * *_*_S24_LE * @param buf * @param floatBuf * @return Total number of samples written to the buffer */ public static void fromFloat(FloatBuffer floatBuf, AudioFormat format, ByteBuffer buf) { if (!format.isSigned()) throw new NotSupportedException("Unsigned PCM is not supported ( yet? )."); if (format.getSampleSizeInBits() != 16 && format.getSampleSizeInBits() != 24) throw new NotSupportedException(format.getSampleSizeInBits() + " bit PCM is not supported ( yet? )."); if (format.isBigEndian()) { if (format.getSampleSizeInBits() == 16) { fromFloat16BE(buf, floatBuf); } else { fromFloat24BE(buf, floatBuf); } } else { if (format.getSampleSizeInBits() == 16) { fromFloat16LE(buf, floatBuf); } else { fromFloat24LE(buf, floatBuf); } } }
public static AudioCodecMeta createAudioCodecMeta3(String fourcc, ByteBuffer codecPrivate, AudioFormat format, boolean pcm, Label[] labels) { AudioCodecMeta self = new AudioCodecMeta(fourcc, codecPrivate); self.sampleSize = format.getSampleSizeInBits() >> 3; self.channelCount = format.getChannels(); self.sampleRate = format.getSampleRate(); self.endian = format.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; self.pcm = pcm; self.labels = labels; return self; }
public static AudioCodecMeta fromAudioFormat(AudioFormat format) { AudioCodecMeta self = new AudioCodecMeta(null, null); self.sampleSize = format.getSampleSizeInBits() >> 3; self.channelCount = format.getChannels(); self.sampleRate = format.getSampleRate(); self.endian = format.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; self.pcm = false; return self; } }
public PCMMP4MuxerTrack addPCMAudioTrack(AudioFormat format) { return addPCMTrack((int) format.getSampleRate(), 1, (format.getSampleSizeInBits() >> 3) * format.getChannels(), audioSampleEntry(format)); }
public PCMMP4MuxerTrack addPCMAudioTrack(AudioFormat format) { return addPCMTrack((int) format.getSampleRate(), 1, (format.getSampleSizeInBits() >> 3) * format.getChannels(), audioSampleEntry(format)); }
public static AudioSampleEntry audioSampleEntryPCM(AudioFormat format) { return audioSampleEntry(AudioSampleEntry.lookupFourcc(format), 1, format.getSampleSizeInBits() >> 3, format.getChannels(), (int) format.getSampleRate(), format.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); }
public static AudioSampleEntry audioSampleEntry(AudioFormat format) { return MP4Muxer.audioSampleEntry(lookupFourcc(format), 1, format.getSampleSizeInBits() >> 3, format.getChannels(), (int) format.getSampleRate(), format.isBigEndian() ? Endian.BIG_ENDIAN : Endian.LITTLE_ENDIAN); }
public static AudioSampleEntry audioSampleEntry(AudioFormat format) { return MP4Muxer.audioSampleEntry(lookupFourcc(format), 1, format.getSampleSizeInBits() >> 3, format.getChannels(), (int) format.getSampleRate(), format.isBigEndian() ? Endian.BIG_ENDIAN : Endian.LITTLE_ENDIAN); }
public PCMMP4MuxerTrack(int trackId, AudioFormat format) { super(trackId, MP4TrackType.SOUND); this.chunkOffsets = LongArrayList.createLongArrayList(); this.frameDuration = 1; this.frameSize = (format.getSampleSizeInBits() >> 3) * format.getChannels(); addSampleEntry(AudioSampleEntry.audioSampleEntryPCM(format)); this._timescale = format.getSampleRate(); setTgtChunkDuration(new Rational(1, 2), Unit.SEC); }
AudioFormat format = at.getAudioFormat(); System.out.print("|C=" + at.getCodec() + "|SR=" + format.getSampleRate() + "|SS=" + (format.getSampleSizeInBits() >> 3) + "|CH=" + format.getChannels()); } else if (pkt.getType() == Type.SCRIPT) { FLVMetadata metadata = FLVReader.parseMetadata(pkt.getData().duplicate());
public static WavHeader create(AudioFormat af, int size) { WavHeader w = emptyWavHeader(); w.dataSize = size; FmtChunk fmt = newFmtChunk(); int bitsPerSample = af.getSampleSizeInBits(); int bytesPerSample = bitsPerSample / 8; int sampleRate = (int) af.getSampleRate(); w.fmt.bitsPerSample = (short) bitsPerSample; w.fmt.blockAlign = (short) (af.getFrameSize()); w.fmt.byteRate = (int) af.getFrameRate() * af.getFrameSize(); w.fmt.numChannels = (short) af.getChannels(); w.fmt.sampleRate = (int) af.getSampleRate(); return w; }