Based on LAME Project (lame.sourceforge.net)
directly create a Lame object
val lame = Lame()
...
Or binding the service (cross-process)
private val intent = Intent("io.github.hesoft.lame.MP3EncodeSERVICE")
context.bindService(intent, object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, serviceBinder: IBinder) {
val service = ILameService.Stub.asInterface(serviceBinder)
val lame = service.create(Binder())
...
}
override fun onServiceDisconnected(name: ComponentName?) {}
}, Context.BIND_AUTO_CREATE)
// inputSampleRate
// outputSampleRate
// outputBitRate
// outputQuality
// outputMode
lame.initParams(
44100,
44100, 320, 3, MPEGMode.MONO
)
Use the following method to encode, each method is for a different input format
encodeUnsigned8bit(byte[] pcm_l, byte[] pcm_r, int inSize, byte[] outBytes)
encodeSigned16bit(byte[] pcm_l, byte[] pcm_r, int inSize, byte[] outBytes)
encodeSigned32bit(byte[] pcm_l, byte[] pcm_r, int inSize, byte[] outBytes)
encodeSigned32bitFloat(byte[] pcm_l, byte[] pcm_r, int inSize, byte[] outBytes)
encodeSigned64bitDouble(byte[] pcm_l, byte[] pcm_r, int inSize, byte[] outBytes)
encodeUnsigned8bitInterleaved(byte[] pcm, int inSize, byte[] outBytes)
encodeSigned16bitInterleaved(byte[] pcm, int inSize, byte[] outBytes)
encodeSigned32bitInterleaved(byte[] pcm, int inSize, byte[] outBytes)
encodeSigned32bitFloatInterleaved(byte[] pcm, int inSize, byte[] outBytes)
encodeSigned64bitDoubleInterleaved(byte[] pcm, int inSize, byte[] outBytes)
Demo: LameServiceTest.kt
val outSize = lame.flush(outBuff)
output.write(outBuff, 0, outSize)
output.close()
lame.destroy()
add lame_encode_buffer_byte
and lame_encode_buffer_interleaved_byte
method to support 8-bit format encoding
https://github.com/4332weizi/AME/
License inherits from original LAME Project.
GNU LESSER GENERAL PUBLIC LICENSE