Modern Apps git

← Modern-Apps.git

tuner: remove the "unprocessed microphone feed" warning

Commit
835f3a6a26c148808e81bf7191dfefc20fc43f85
Author
Vayun Mathur <[email protected]>
When
2026-11-01 18:27 UTC (1 month ago)
Parents
8da1669
The Note tab showed a red banner whenever the platform substituted a processed
mic source for UNPROCESSED. It was alarming and unclear to users, and nothing
in it was actionable. The substitution is still logged by AudioCapture.

Diff

tuner/src/main/java/com/vayunmathur/tuner/platform/AudioCapture.kt
diff --git a/tuner/src/main/java/com/vayunmathur/tuner/platform/AudioCapture.kt b/tuner/src/main/java/com/vayunmathur/tuner/platform/AudioCapture.ktindex 4be2a86ab2..72b59b353c 100644--- a/tuner/src/main/java/com/vayunmathur/tuner/platform/AudioCapture.kt+++ b/tuner/src/main/java/com/vayunmathur/tuner/platform/AudioCapture.kt@@ -20,14 +20,6 @@ import kotlin.concurrent.thread /** Why capture stopped, so the screen can say something specific. */ enum class CaptureFailure { NO_PERMISSION, UNAVAILABLE } -/**- * The source the platform actually opened, read back off the stream rather than assumed.- *- * Anything other than [UNPROCESSED] means the low strings cannot be trusted, and the UI says so- * out loud: a tuner that is quietly wrong below 100 Hz is worse than one that admits it.- */-enum class CaptureSource { UNPROCESSED, VOICE_RECOGNITION, OTHER }- /**  * Microphone capture into a lock-free-enough ring buffer, with the settings a tuner needs.  *@@ -49,11 +41,6 @@ class AudioCapture(private val context: Context) {     /** Samples captured since this instance started. */     val capturedSamples: Long get() = synchronized(lock) { total } -    /** What [open] actually got, or null before the first successful open. */-    @Volatile-    var activeSource: CaptureSource? = null-        private set-     /**      * Copies the most recent `into.size` samples. Returns false while the buffer is still      * filling, so the caller shows "listening" rather than analysing zeros.@@ -151,17 +138,13 @@ class AudioCapture(private val context: Context) {                 null             }             if (record != null && record.state == AudioRecord.STATE_INITIALIZED) {-                // Read the source back off the stream instead of trusting what we asked for.-                // This still cannot prove the HAL applied no processing - nothing can from here --                // but it does catch the platform substituting a source behind our back.-                val honoured = classify(record.audioSource)-                activeSource = honoured-                if (honoured != CaptureSource.UNPROCESSED) {+                // Read the source back off the stream instead of trusting what we asked for, so a+                // platform substituting a processed source at least shows up in the log.+                if (record.audioSource != MediaRecorder.AudioSource.UNPROCESSED) {                     Log.status(                         TAG,-                        "UNPROCESSED unavailable, capturing with $honoured instead - the voice " +-                            "high-pass will attenuate everything below ~100 Hz, so readings on " +-                            "low strings are not trustworthy",+                        "UNPROCESSED unavailable, capturing with source ${record.audioSource} - " ++                            "a voice high-pass may attenuate everything below ~100 Hz",                     )                 }                 return record@@ -181,12 +164,6 @@ class AudioCapture(private val context: Context) {         }     } -    private fun classify(source: Int): CaptureSource = when (source) {-        MediaRecorder.AudioSource.UNPROCESSED -> CaptureSource.UNPROCESSED-        MediaRecorder.AudioSource.VOICE_RECOGNITION -> CaptureSource.VOICE_RECOGNITION-        else -> CaptureSource.OTHER-    }-     /** Some platforms attach these to the session regardless of the source; turn them off. */     private fun disableVoiceProcessing(sessionId: Int) {         runCatching {
tuner/src/main/java/com/vayunmathur/tuner/platform/TunerUiContract.kt
diff --git a/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerUiContract.kt b/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerUiContract.ktindex 88936de109..9d93696cc6 100644--- a/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerUiContract.kt+++ b/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerUiContract.kt@@ -51,8 +51,6 @@ data class TunerUiState(     val instruments: List<Instrument>,     val listening: Boolean = false,     val failure: CaptureFailure? = null,-    /** Null until the microphone has been opened once. */-    val captureSource: CaptureSource? = null,     val note: NoteUiState = NoteUiState(),     val chord: ChordUiState = ChordUiState(), )
tuner/src/main/java/com/vayunmathur/tuner/platform/TunerViewModel.kt
diff --git a/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerViewModel.kt b/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerViewModel.ktindex de345883ab..8812b6119a 100644--- a/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerViewModel.kt+++ b/tuner/src/main/java/com/vayunmathur/tuner/platform/TunerViewModel.kt@@ -141,7 +141,7 @@ class TunerViewModel(application: Application) : AndroidViewModel(application) {         // Flipped before the first frame arrives so a capture that never produces audio still         // looks different from one that was never asked for. The failure branch below puts it         // back.-        state = state.copy(listening = true, failure = null, captureSource = null)+        state = state.copy(listening = true, failure = null)         captureJob = viewModelScope.launch {             capture.frames(NOTE_HOP).conflate().collect { result ->                 val failure = result.exceptionOrNull()@@ -152,9 +152,6 @@ class TunerViewModel(application: Application) : AndroidViewModel(application) {                     state = state.copy(listening = false, failure = failure.failure)                     return@collect                 }-                if (state.captureSource == null) {-                    state = state.copy(captureSource = capture.activeSource)-                }                 withContext(Dispatchers.Default) {                     analyseNote()                     if (++hopsSinceChord >= CHORD_EVERY) {
tuner/src/main/java/com/vayunmathur/tuner/ui/NoteScreen.kt
diff --git a/tuner/src/main/java/com/vayunmathur/tuner/ui/NoteScreen.kt b/tuner/src/main/java/com/vayunmathur/tuner/ui/NoteScreen.ktindex 0a4eb008ec..184d72ef8c 100644--- a/tuner/src/main/java/com/vayunmathur/tuner/ui/NoteScreen.kt+++ b/tuner/src/main/java/com/vayunmathur/tuner/ui/NoteScreen.kt@@ -19,7 +19,6 @@ import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.tuner.R import com.vayunmathur.tuner.domain.TuningBand-import com.vayunmathur.tuner.platform.CaptureSource import com.vayunmathur.tuner.platform.TunerUiState  /**@@ -50,19 +49,6 @@ fun NoteScreen(state: TunerUiState) {             horizontalAlignment = Alignment.CenterHorizontally,         ) {             val readout = state.note.readout-            if (state.listening &&-                state.captureSource != null &&-                state.captureSource != CaptureSource.UNPROCESSED-            ) {-                // Loud on purpose. A processed feed silently removes the bottom of the range, and-                // a tuner that looks confident while doing that is worse than no tuner.-                Text(-                    text = stringResource(R.string.unprocessed_unavailable),-                    style = MaterialTheme.typography.bodyMedium,-                    color = MaterialTheme.colorScheme.error,-                    textAlign = TextAlign.Center,-                )-            }             Text(                 text = readout?.let { "${it.letter}${it.octave}" } ?: EMPTY_NOTE,                 style = MaterialTheme.typography.displayLarge,
tuner/src/main/res/values/strings.xml
diff --git a/tuner/src/main/res/values/strings.xml b/tuner/src/main/res/values/strings.xmlindex 17a74c25d5..4b96afd3c2 100644--- a/tuner/src/main/res/values/strings.xml+++ b/tuner/src/main/res/values/strings.xml@@ -48,8 +48,6 @@     <string name="shape_recommended">Recommended</string>     <!-- Spells out that a chord diagram is a suggestion rather than a record of what was played. -->     <string name="shapes_caveat">The app cannot hear which part of the neck you used, so this is one valid shape, not the one you played.</string>-    <!-- Warns that the device would not give the app a clean, unprocessed microphone feed. -->-    <string name="unprocessed_unavailable">This device will not provide an unprocessed microphone feed, so it filters out low frequencies. Readings on low strings may be wrong or missing.</string>     <!-- Prompt on the chord tab before anything has been played. -->     <string name="chord_prompt">Play a chord</string>     <!-- Heading over the list of notes the app actually heard. This is a measurement. -->