30 lines
805 B
Kotlin
30 lines
805 B
Kotlin
import io.github.jaredmdobson.concentus.OpusDecoder
|
|
import io.github.jaredmdobson.concentus.OpusEncoder
|
|
import kotlinx.coroutines.*
|
|
|
|
/**
|
|
* Created by LoliBall on 2024/8/31 5:26.
|
|
* https://github.com/WhichWho
|
|
*/
|
|
fun main() = runBlocking {
|
|
CoroutineScope(Dispatchers.IO).launch {
|
|
Server.main(emptyArray())
|
|
}
|
|
delay(1000)
|
|
Client.main(emptyArray())
|
|
}
|
|
|
|
fun OpusEncoder.encode(
|
|
pcm: ByteArray,
|
|
opusBuffer: ByteArray = ByteArray(pcm.size)
|
|
): DataPack {
|
|
val bytesEncoded = encode(pcm, 0, PACKET_SAMPLES, opusBuffer, 0, opusBuffer.size)
|
|
return DataPack(System.currentTimeMillis(), opusBuffer.sliceArray(0..<bytesEncoded))
|
|
}
|
|
|
|
fun OpusDecoder.decode(
|
|
pack: DataPack,
|
|
output: ByteArray,
|
|
) {
|
|
decode(pack.opus, 0, pack.opus.size, output, 0, PACKET_SAMPLES, false)
|
|
} |