When playing back the decoded sound, I was able to create many sounds from gurgling to screeching demonic chants. The closest one sounds the same as fast-forward, and playback lasts about 15 seconds. I tried with a large combination of parameters for decoding methods and AudioSystem API, nothing works.
So what causes this sound distortion?
Opusinfo for this file shows the following:
Processing file "test.opus"... New logical stream (#1, serial: 00002c88): type opus Encoded with libopus 1.1 User comments section follows... ENCODER=opusenc from opus-tools 0.1.9 Opus stream 1: Pre-skip: 356 Playback gain: 0 dB Channels: 1 Original sample rate: 44100Hz Packet duration: 20.0ms (max), 20.0ms (avg), 20.0ms (min) Page duration: 1000.0ms (max), 996.8ms (avg), 200.0ms (min) Total data length: 1930655 bytes (overhead: 1.04%) Playback length: 4m:09.173s Average bitrate: 61.99 kb/s, w/o overhead: 61.34 kb/s Logical stream 1 ended
This file plays correctly using VLC.
To decode a file, I am trying to use the following libraries:
SSCCE below
package me.justinb.mediapad.audio; import org.gagravarr.ogg.OggFile; import org.gagravarr.ogg.OggPacket; import org.jitsi.impl.neomedia.codec.audio.opus.Opus; import javax.sound.sampled.*; import java.io.*; import java.nio.ByteBuffer; public class OpusAudioPlayer { private static int BUFFER_SIZE = 1024 * 1024; private static int INPUT_BITRATE = 48000; private static int OUTPUT_BITRATE = 44100; private OggFile oggFile; private long opusState; private ByteBuffer decodeBuffer = ByteBuffer.allocate(BUFFER_SIZE); private AudioFormat audioFormat = new AudioFormat(OUTPUT_BITRATE, 16, 1, true, false); public static void main(String[] args) { try { OpusAudioPlayer opusAudioPlayer = new OpusAudioPlayer(new File("test.opus")); opusAudioPlayer.play(); } catch (IOException e) { e.printStackTrace(); } } public OpusAudioPlayer(File audioFile) throws IOException { oggFile = new OggFile(new FileInputStream(audioFile)); opusState = Opus.decoder_create(INPUT_BITRATE, 1); System.out.println("Audio format: " + audioFormat); } private byte[] decode(byte[] packetData) { int frameSize = Opus.decoder_get_nb_samples(opusState, packetData, 0, packetData.length); int decodedSamples = Opus.decode(opusState, packetData, 0, packetData.length, decodeBuffer.array(), 0, frameSize, 0); if (decodedSamples < 0) { System.out.println("Decode error: " + decodedSamples); decodeBuffer.clear(); return null; } decodeBuffer.position(decodedSamples * 2);
java audio ogg opus jitsi
Justin
source share