SonicAudioProcessor implements AudioProcessor { @Override public AudioFormat configure(AudioFormat inputAudioFormat) throws UnhandledAudioFormatException { if (inputAudioFormat.encoding != C.ENCODING_PCM_16BIT) { throw new UnhandledAudioFormatException(inputAudioFormat); } int outputSampleRateHz = pendingOutputSampleRate == SAMPLE_RATE_NO_CHANGE ? inputAudioFormat.sampleRate : pendingOutputSampleRate; pendingInputAudioFormat = inputAudioFormat; pendingOutputAudioFormat = new AudioFormat(outputSampleRateHz, inputAudioFormat.channelCount, C.ENCODING_PCM_16BIT); pendingSonicRecreation = true; return pendingOutputAudioFormat; } SonicAudioProcessor(); float setSpeed(float speed); float setPitch(float pitch); void setOutputSampleRateHz(int sampleRateHz); long scaleDurationForSpeedup(long duration); @Override AudioFormat configure(AudioFormat inputAudioFormat); @Override boolean isActive(); @Override void queueInput(ByteBuffer inputBuffer); @Override void queueEndOfStream(); @Override ByteBuffer getOutput(); @Override boolean isEnded(); @Override void flush(); @Override void reset(); static final float MAXIMUM_SPEED; static final float MINIMUM_SPEED; static final float MAXIMUM_PITCH; static final float MINIMUM_PITCH; static final int SAMPLE_RATE_NO_CHANGE; }
@Test public void testDoesNotSupportNon16BitInput() throws Exception { try { sonicAudioProcessor.configure( new AudioFormat( 44100, 2, C.ENCODING_PCM_8BIT)); fail(); } catch (UnhandledAudioFormatException e) { } try { sonicAudioProcessor.configure( new AudioFormat( 44100, 2, C.ENCODING_PCM_24BIT)); fail(); } catch (UnhandledAudioFormatException e) { } try { sonicAudioProcessor.configure( new AudioFormat( 44100, 2, C.ENCODING_PCM_32BIT)); fail(); } catch (UnhandledAudioFormatException e) { } }