Loading core/java/android/speech/tts/BlockingAudioTrack.java +1 −12 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ class BlockingAudioTrack { mVolume = volume; mPan = pan; mBytesPerFrame = getBytesPerFrame(mAudioFormat) * mChannelCount; mBytesPerFrame = AudioFormat.getBytesPerSample(mAudioFormat) * mChannelCount; mIsShortUtterance = false; mAudioBufferSize = 0; mBytesWritten = 0; Loading Loading @@ -229,17 +229,6 @@ class BlockingAudioTrack { return audioTrack; } private static int getBytesPerFrame(int audioFormat) { if (audioFormat == AudioFormat.ENCODING_PCM_8BIT) { return 1; } else if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) { return 2; } return -1; } private void blockUntilDone(AudioTrack audioTrack) { if (mBytesWritten <= 0) { return; Loading core/java/android/speech/tts/FileSynthesisCallback.java +1 −2 Original line number Diff line number Diff line Loading @@ -278,8 +278,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { private ByteBuffer makeWavHeader(int sampleRateInHz, int audioFormat, int channelCount, int dataLength) { // TODO: is AudioFormat.ENCODING_DEFAULT always the same as ENCODING_PCM_16BIT? int sampleSizeInBytes = (audioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2); int sampleSizeInBytes = AudioFormat.getBytesPerSample(audioFormat); int byteRate = sampleRateInHz * sampleSizeInBytes * channelCount; short blockAlign = (short) (sampleSizeInBytes * channelCount); short bitsPerSample = (short) (sampleSizeInBytes * 8); Loading media/java/android/media/AudioFormat.java +15 −0 Original line number Diff line number Diff line Loading @@ -139,4 +139,19 @@ public class AudioFormat { public static final int CHANNEL_IN_FRONT_BACK = CHANNEL_IN_FRONT | CHANNEL_IN_BACK; // CHANNEL_IN_ALL is not yet defined; if added then it should match AUDIO_CHANNEL_IN_ALL /** @hide */ public static int getBytesPerSample(int audioFormat) { switch (audioFormat) { case ENCODING_PCM_8BIT: return 1; case ENCODING_PCM_16BIT: case ENCODING_DEFAULT: return 2; case ENCODING_INVALID: default: throw new IllegalArgumentException("Bad audio format " + audioFormat); } } } media/java/android/media/AudioRecord.java +1 −1 Original line number Diff line number Diff line Loading @@ -319,7 +319,7 @@ public class AudioRecord // NB: this section is only valid with PCM data. // To update when supporting compressed formats int frameSizeInBytes = mChannelCount * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2); * (AudioFormat.getBytesPerSample(mAudioFormat)); if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) { throw new IllegalArgumentException("Invalid audio buffer size."); } Loading media/java/android/media/AudioTrack.java +1 −1 Original line number Diff line number Diff line Loading @@ -518,7 +518,7 @@ public class AudioTrack // NB: this section is only valid with PCM data. // To update when supporting compressed formats int frameSizeInBytes = mChannelCount * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2); * (AudioFormat.getBytesPerSample(mAudioFormat)); if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) { throw new IllegalArgumentException("Invalid audio buffer size."); } Loading Loading
core/java/android/speech/tts/BlockingAudioTrack.java +1 −12 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ class BlockingAudioTrack { mVolume = volume; mPan = pan; mBytesPerFrame = getBytesPerFrame(mAudioFormat) * mChannelCount; mBytesPerFrame = AudioFormat.getBytesPerSample(mAudioFormat) * mChannelCount; mIsShortUtterance = false; mAudioBufferSize = 0; mBytesWritten = 0; Loading Loading @@ -229,17 +229,6 @@ class BlockingAudioTrack { return audioTrack; } private static int getBytesPerFrame(int audioFormat) { if (audioFormat == AudioFormat.ENCODING_PCM_8BIT) { return 1; } else if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) { return 2; } return -1; } private void blockUntilDone(AudioTrack audioTrack) { if (mBytesWritten <= 0) { return; Loading
core/java/android/speech/tts/FileSynthesisCallback.java +1 −2 Original line number Diff line number Diff line Loading @@ -278,8 +278,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback { private ByteBuffer makeWavHeader(int sampleRateInHz, int audioFormat, int channelCount, int dataLength) { // TODO: is AudioFormat.ENCODING_DEFAULT always the same as ENCODING_PCM_16BIT? int sampleSizeInBytes = (audioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2); int sampleSizeInBytes = AudioFormat.getBytesPerSample(audioFormat); int byteRate = sampleRateInHz * sampleSizeInBytes * channelCount; short blockAlign = (short) (sampleSizeInBytes * channelCount); short bitsPerSample = (short) (sampleSizeInBytes * 8); Loading
media/java/android/media/AudioFormat.java +15 −0 Original line number Diff line number Diff line Loading @@ -139,4 +139,19 @@ public class AudioFormat { public static final int CHANNEL_IN_FRONT_BACK = CHANNEL_IN_FRONT | CHANNEL_IN_BACK; // CHANNEL_IN_ALL is not yet defined; if added then it should match AUDIO_CHANNEL_IN_ALL /** @hide */ public static int getBytesPerSample(int audioFormat) { switch (audioFormat) { case ENCODING_PCM_8BIT: return 1; case ENCODING_PCM_16BIT: case ENCODING_DEFAULT: return 2; case ENCODING_INVALID: default: throw new IllegalArgumentException("Bad audio format " + audioFormat); } } }
media/java/android/media/AudioRecord.java +1 −1 Original line number Diff line number Diff line Loading @@ -319,7 +319,7 @@ public class AudioRecord // NB: this section is only valid with PCM data. // To update when supporting compressed formats int frameSizeInBytes = mChannelCount * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2); * (AudioFormat.getBytesPerSample(mAudioFormat)); if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) { throw new IllegalArgumentException("Invalid audio buffer size."); } Loading
media/java/android/media/AudioTrack.java +1 −1 Original line number Diff line number Diff line Loading @@ -518,7 +518,7 @@ public class AudioTrack // NB: this section is only valid with PCM data. // To update when supporting compressed formats int frameSizeInBytes = mChannelCount * (mAudioFormat == AudioFormat.ENCODING_PCM_8BIT ? 1 : 2); * (AudioFormat.getBytesPerSample(mAudioFormat)); if ((audioBufferSize % frameSizeInBytes != 0) || (audioBufferSize < 1)) { throw new IllegalArgumentException("Invalid audio buffer size."); } Loading