Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for configurable codecs
This commit adds the initial framework for allowing the configuration of output codecs. There are three codec choices available: * FLAC: (default) lossless, compression level 0-8 * OGG/Opus: lossy, bitrate 6-510kbps, Android 10+ only * M4A/AAC: lossy, HE-AAC bitrate 24-32kbps, AAC-LC bitrate 32-128kbps While all three codecs are implemented, RecorderThread is currently hardcoded to use the default. The next step is to save and load the codec configuration from SharedPreferences and the finally add the user interface. Issue: #21 Signed-off-by: Andrew Gunnerson <chillermillerlong@hotmail.com>
- Loading branch information
1 parent
7320c41
commit 3d3eb82
Showing
9 changed files
with
484 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.chiller3.bcr.codec | ||
|
||
import android.media.AudioFormat | ||
import android.media.MediaCodecInfo | ||
import android.media.MediaFormat | ||
import android.media.MediaMuxer | ||
import java.io.FileDescriptor | ||
|
||
class AacCodec : Codec() { | ||
override val codecParamType: CodecParamType = CodecParamType.Bitrate | ||
// The codec has no hard limits, so the lower bound is ffmpeg's recommended minimum bitrate for | ||
// HE-AAC: 24kbps/channel. The upper bound is twice the bitrate for audible transparency with | ||
// AAC-LC: 2 * 64kbps/channel. | ||
// https://trac.ffmpeg.org/wiki/Encode/AAC | ||
override val codecParamRange: UIntRange = 24_000u..128_000u | ||
override val codecParamDefault: UInt = 64_000u | ||
// https://datatracker.ietf.org/doc/html/rfc6381#section-3.1 | ||
override val mimeTypeContainer: String = "audio/mp4" | ||
override val mimeTypeAudio: String = MediaFormat.MIMETYPE_AUDIO_AAC | ||
override val supported: Boolean = true | ||
|
||
override fun getMediaFormat(audioFormat: AudioFormat, sampleRate: Int): MediaFormat = | ||
super.getMediaFormat(audioFormat, sampleRate).apply { | ||
val profile = if (codecParamValue >= 32_000u) { | ||
MediaCodecInfo.CodecProfileLevel.AACObjectLC | ||
} else { | ||
MediaCodecInfo.CodecProfileLevel.AACObjectHE | ||
} | ||
|
||
setInteger(MediaFormat.KEY_AAC_PROFILE, profile) | ||
setInteger(MediaFormat.KEY_BIT_RATE, codecParamValue.toInt() * audioFormat.channelCount) | ||
} | ||
|
||
override fun getContainer(fd: FileDescriptor): Container = | ||
MediaMuxerContainer(fd, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4) | ||
} |
Oops, something went wrong.