From 0eae250b66dd817b07e1295bc510fe84420338b4 Mon Sep 17 00:00:00 2001 From: Patrick Burns Date: Mon, 1 Jun 2026 18:52:10 -0500 Subject: [PATCH] FT8TransmitSignal: instrument TX output path with fileLog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The car-dash TX-abort symptom (PTT keys → 250-300ms → PTT releases, no audio sent) is still happening despite #84 shipping the libusb nativeWrite. But the full TX output path is logged only to logcat, so from debug.log there's no way to tell: 1. Which output branch ran (USB direct vs. AudioTrack). 2. If USB direct ran, which step failed before reaching writeAudio (device lookup, USB permission, open, hasOutput, activateOutput). Same instrumentation pattern as the input side that surfaced the real bugs in #82 / #83. Changes: - playFT8Signal: log the branch decision with audioOutputDeviceId and the saved USB output VID:PID. Log which branch was taken. - playViaUsbAudio: fileLog at each failure point and at the success pivots (device opened + output activated, before writeAudio, writeAudio return value). Every failure path has a distinct message so the failure point is obvious from one log line. After the next car-dash repro we'll know whether the abort is: - audioOutputDeviceId not being -1 at TX time (picker reset?), - device lookup failing (UsbManager state), - permission lost on re-attach, - activateOutput failing on the car-dash kernel, - or actually reaching writeAudio and libusb dying inside. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../ft8cn/ft8transmit/FT8TransmitSignal.java | 58 +++++++++++++++---- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/ft8cn/app/src/main/java/com/bg7yoz/ft8cn/ft8transmit/FT8TransmitSignal.java b/ft8cn/app/src/main/java/com/bg7yoz/ft8cn/ft8transmit/FT8TransmitSignal.java index e66fdd68..9a6c2461 100644 --- a/ft8cn/app/src/main/java/com/bg7yoz/ft8cn/ft8transmit/FT8TransmitSignal.java +++ b/ft8cn/app/src/main/java/com/bg7yoz/ft8cn/ft8transmit/FT8TransmitSignal.java @@ -419,12 +419,25 @@ private void playFT8Signal(Ft8Message msg) { return; } - // USB audio output path + // USB audio output path. Logged so a dev-screen reader can see + // which branch was taken — the difference between TX going out + // the USB radio (this branch) vs. Android's default sink (the + // AudioTrack branch below) was the whole reason for #84, and we + // currently have no way to tell from debug.log which one fired. + GeneralVariables.fileLog(String.format( + "playFT8Signal: TX path branch: audioOutputDeviceId=%d " + + "usbAudioOutputVidPid=%04X:%04X", + GeneralVariables.audioOutputDeviceId, + GeneralVariables.usbAudioOutputVendorId, + GeneralVariables.usbAudioOutputProductId)); if (GeneralVariables.audioOutputDeviceId == -1 && GeneralVariables.usbAudioOutputVendorId != 0) { + GeneralVariables.fileLog("playFT8Signal: using USB audio (direct) output"); playViaUsbAudio(buffer); return; } + GeneralVariables.fileLog( + "playFT8Signal: using AudioTrack output (Android default sink)"); Log.d(TAG, String.format("playFT8Signal: Preparing sound card playback... bit depth: %s, sample rate: %d" , GeneralVariables.audioOutput32Bit ? "Float32" : "Int16" @@ -506,14 +519,15 @@ public void onPeriodicNotification(AudioTrack audioTrack) { * Play FT8 signal through USB audio device. */ private void playViaUsbAudio(float[] buffer) { - Log.d(TAG, String.format("playFT8Signal: USB audio output, VID=%04X PID=%04X, samples=%d, rate=%d", + GeneralVariables.fileLog(String.format( + "playViaUsbAudio: start, VID=%04X PID=%04X samples=%d rate=%d", GeneralVariables.usbAudioOutputVendorId, GeneralVariables.usbAudioOutputProductId, buffer.length, GeneralVariables.audioSampleRate)); Context context = GeneralVariables.getMainContext(); if (context == null) { - Log.e(TAG, "No context for USB audio"); + GeneralVariables.fileLog("playViaUsbAudio: ABORT no main context"); afterPlayAudio(); return; } @@ -522,38 +536,56 @@ private void playViaUsbAudio(float[] buffer) { GeneralVariables.usbAudioOutputVendorId, GeneralVariables.usbAudioOutputProductId); if (device == null) { - Log.e(TAG, "USB audio output device not found"); + GeneralVariables.fileLog(String.format( + "playViaUsbAudio: ABORT USB audio output device not found " + + "by VID:PID %04X:%04X", + GeneralVariables.usbAudioOutputVendorId, + GeneralVariables.usbAudioOutputProductId)); afterPlayAudio(); return; } UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); - if (usbManager == null || !usbManager.hasPermission(device)) { - Log.e(TAG, "No USB permission for audio output device"); + if (usbManager == null) { + GeneralVariables.fileLog("playViaUsbAudio: ABORT UsbManager is null"); + afterPlayAudio(); + return; + } + if (!usbManager.hasPermission(device)) { + GeneralVariables.fileLog( + "playViaUsbAudio: ABORT no USB permission for output device " + + "(re-pick (USB direct) in Settings to re-grant)"); afterPlayAudio(); return; } UsbAudioDevice usbDev = new UsbAudioDevice(); if (!usbDev.open(context, device)) { - Log.e(TAG, "Failed to open USB audio output device"); + GeneralVariables.fileLog( + "playViaUsbAudio: ABORT UsbAudioDevice.open() failed " + + "(descriptor parse or claimInterface failed)"); afterPlayAudio(); return; } if (!usbDev.hasOutput()) { - Log.e(TAG, "USB audio device has no output endpoint"); + GeneralVariables.fileLog( + "playViaUsbAudio: ABORT device has no output endpoint"); usbDev.close(); afterPlayAudio(); return; } if (!usbDev.activateOutput(48000)) { - Log.e(TAG, "Failed to activate USB audio output"); + GeneralVariables.fileLog( + "playViaUsbAudio: ABORT activateOutput(48000) failed " + + "(alt-setting select or rate setup failed)"); usbDev.close(); afterPlayAudio(); return; } + GeneralVariables.fileLog( + "playViaUsbAudio: device opened, output activated at 48000 Hz"); // Skip leading samples if we started transmitting late, so audio still ends on the cycle boundary. int skipSamples = (lateStartSkipMs * GeneralVariables.audioSampleRate) / 1000; @@ -567,10 +599,12 @@ private void playViaUsbAudio(float[] buffer) { volumeAdjusted[i] = buffer[skipSamples + i] * GeneralVariables.volumePercent; } + GeneralVariables.fileLog(String.format( + "playViaUsbAudio: calling writeAudio playLength=%d rate=%d", + playLength, GeneralVariables.audioSampleRate)); boolean success = usbDev.writeAudio(volumeAdjusted, GeneralVariables.audioSampleRate); - if (!success) { - Log.e(TAG, "USB audio write failed"); - } + GeneralVariables.fileLog( + "playViaUsbAudio: writeAudio returned " + (success ? "OK" : "FAILED")); usbDev.close(); afterPlayAudio();