feat: add neutral avatar video call MVP in Android 0.6.0
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import com.gorios.lanvoice.audio.PcmActivityTimeline
|
||||
import com.gorios.lanvoice.audio.PlaybackHead
|
||||
|
||||
fun publicTone(samples: Int, value: Int = 2000) = ByteArray(samples * 2).also {
|
||||
for (i in 0 until samples) { it[i*2] = value.toByte(); it[i*2+1] = (value shr 8).toByte() }
|
||||
}
|
||||
fun checkActivityTimeline() {
|
||||
val head = PlaybackHead()
|
||||
check(head.read(0xfffffff0.toInt()) == 0xfffffff0L)
|
||||
check(head.read(32) == 0x1_0000_0020L)
|
||||
head.reset(); check(head.read(0) == 0L)
|
||||
val activity = PcmActivityTimeline()
|
||||
activity.append(publicTone(300)); activity.append(publicTone(660)) // a cross-chunk 20ms window
|
||||
check(!activity.sample(0,960,0)) // writing and queueing do not open mouth
|
||||
check(!activity.sample(480,0,5)) // beyond accepted partial write never consumes activity
|
||||
check(activity.sample(480,480,10))
|
||||
check(activity.sample(960,960,20))
|
||||
check(activity.sample(960,960,139))
|
||||
check(!activity.sample(960,960,140)) // actual native underrun, TTS need not be ended
|
||||
activity.append(ByteArray(48_000/5*2))
|
||||
check(!activity.sample(10_560,10_560,240)) // 200ms silence closes
|
||||
activity.append(publicTone(960))
|
||||
check(activity.sample(11_520,11_520,260))
|
||||
activity.reset(); check(!activity.sample(0,0,270))
|
||||
activity.append(publicTone(100)) // final partial analysis window is playable immediately
|
||||
check(activity.sample(100,100,280))
|
||||
activity.reset(); activity.append(publicTone(960,100))
|
||||
check(!activity.sample(960,960,300)) // low noise under RMS and peak thresholds
|
||||
activity.reset()
|
||||
repeat(2000) { activity.append(publicTone(960)); check(activity.sample((it+1)*960L,(it+1)*960L,400+it*20L)) }
|
||||
check(activity.retainedWindows == 0) // continuous long playback prunes consumed metadata
|
||||
val bounded = PcmActivityTimeline(maxWindows=2)
|
||||
bounded.append(publicTone(1920))
|
||||
check(runCatching { bounded.append(publicTone(960)) }.isFailure)
|
||||
println("PASS: production PCM RMS/peak cross-block/partial/tail, no activity until playback head, silence/120ms underrun/resume/reset, u32 wrap and bounded/pruned metadata")
|
||||
}
|
||||
@@ -14,6 +14,7 @@ class AudioTrack {
|
||||
@Volatile var latest: AudioTrack? = null
|
||||
@Volatile var advanceHead = true
|
||||
@Volatile var rejectWrites = false
|
||||
@Volatile var manualHead: Int? = null
|
||||
fun getMinBufferSize(a: Int, b: Int, c: Int) = 320
|
||||
}
|
||||
class Builder {
|
||||
@@ -29,7 +30,7 @@ class AudioTrack {
|
||||
@Volatile var released = false
|
||||
@Volatile var attempts = 0
|
||||
val underrunCount get() = attempts / 4
|
||||
val playbackHeadPosition get() = if (advanceHead && samples >= bufferSizeInFrames) samples else 0
|
||||
val playbackHeadPosition get() = manualHead ?: if (advanceHead && samples >= bufferSizeInFrames) samples else 0
|
||||
fun play() { playState = PLAYSTATE_PLAYING }
|
||||
fun pause() { playState = 0 }
|
||||
fun flush() { samples = 0; flushes++ }
|
||||
|
||||
@@ -9,6 +9,7 @@ fun awaitCheck(test: () -> Boolean) {
|
||||
while (!test()) { check(System.nanoTime() < deadline) { "playback test timed out" }; Thread.sleep(2) }
|
||||
}
|
||||
fun main() {
|
||||
checkActivityTimeline()
|
||||
val drains = CopyOnWriteArrayList<Long>()
|
||||
val failures = CopyOnWriteArrayList<Exception>()
|
||||
val progress = CopyOnWriteArrayList<String>()
|
||||
@@ -52,4 +53,40 @@ fun main() {
|
||||
check(5L !in drains)
|
||||
println("PASS: real AudioPlayback partial/zero writes, explicit end + native head drain, short tail, interruption fence, write failure, stalled head watchdog; device doubles, no real speaker")
|
||||
} finally { player.release() }
|
||||
checkActualActivityPlayback()
|
||||
}
|
||||
|
||||
fun checkActualActivityPlayback() {
|
||||
SystemClock.extra = 0
|
||||
AudioTrack.rejectWrites = false; AudioTrack.manualHead = 0
|
||||
val activities = CopyOnWriteArrayList<com.gorios.lanvoice.audio.PlaybackActivity>()
|
||||
val drains = CopyOnWriteArrayList<Long>()
|
||||
val errors = CopyOnWriteArrayList<Exception>()
|
||||
val player = AudioPlayback({ turn, _ -> drains.add(turn) }, { _, error -> errors.add(error) }, onActivity = activities::add)
|
||||
try {
|
||||
player.beginTurn(70); player.enqueue(DownlinkFrame(70,1,publicTone(960)))
|
||||
awaitCheck { AudioTrack.latest?.samples == 960 }
|
||||
check(activities.isEmpty())
|
||||
AudioTrack.manualHead = 960
|
||||
awaitCheck { activities.lastOrNull()?.audible == true }
|
||||
awaitCheck { activities.lastOrNull()?.audible == false } // software queue empty but TTS remains open
|
||||
check(drains.isEmpty())
|
||||
player.enqueue(DownlinkFrame(70,2,ByteArray(1920)))
|
||||
awaitCheck { AudioTrack.latest?.samples == 1920 }
|
||||
AudioTrack.manualHead = 1920
|
||||
Thread.sleep(30); check(!activities.last().audible)
|
||||
player.enqueue(DownlinkFrame(70,3,publicTone(960)))
|
||||
awaitCheck { AudioTrack.latest?.samples == 2880 }
|
||||
player.endTurn(70) // downlink stop still leaves native buffered speech
|
||||
check(drains.isEmpty())
|
||||
AudioTrack.manualHead = 2400
|
||||
awaitCheck { activities.lastOrNull()?.audible == true }
|
||||
AudioTrack.manualHead = 2880
|
||||
awaitCheck { drains == listOf(70L) }
|
||||
check(!activities.last().audible && errors.isEmpty())
|
||||
val count = activities.size
|
||||
player.interrupt(); Thread.sleep(30)
|
||||
check(activities.size == count)
|
||||
println("PASS: actual AudioPlayback head sampling continues during empty queue; queued PCM held silent, underrun idle, resumed speech talk, downlink end preserves buffered activity, drained/interrupt fences")
|
||||
} finally { player.release(); AudioTrack.manualHead = null }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user