This commit is contained in:
loliball 2024-08-31 14:51:16 +08:00
parent b0d87c0d13
commit 7d20b9c841

View File

@ -12,22 +12,12 @@ fun main() = runBlocking {
}
delay(1000)
Client.main(emptyArray())
// val ss = ByteArrayOutputStream()
// val o = ObjectOutputStream(ss)
// o.writeObject(DataPack(0, ByteArray(10) { 5 }))
// val i = ObjectInputStream(ByteArrayInputStream(ss.toByteArray()))
// val aa = i.readObject() as DataPack
// println(aa)
}
//private val buffer = ThreadLocal<ByteArray>()
fun OpusEncoder.encode(
pcm: ByteArray,
opusBuffer: ByteArray = ByteArray(pcm.size)
): DataPack {
// val pcm1 = Program.BytesToShorts(pcm, 0, pcm.size)
val bytesEncoded = encode(pcm, 0, PACKET_SAMPLES, opusBuffer, 0, opusBuffer.size)
return DataPack(System.currentTimeMillis(), opusBuffer.sliceArray(0..<bytesEncoded))
}
@ -36,6 +26,5 @@ fun OpusDecoder.decode(
pack: DataPack,
output: ByteArray,
) {
val opus = pack.opus
decode(opus, 0, opus.size, output, 0, PACKET_SAMPLES, false);
decode(pack.opus, 0, pack.opus.size, output, 0, PACKET_SAMPLES, false)
}