@@ -176,27 +176,26 @@ class WSPRProcessor
176176 */
177177 private fun generateTimeAlignedWindows (): List <DecodeWindow >
178178 {
179+ // Check if we have enough audio for at least one decode
180+ if (audioBuffer.size < REQUIRED_DECODE_SAMPLES )
181+ {
182+ Timber .w(" Insufficient audio for time-aligned decode: ${audioBuffer.size} samples < ${REQUIRED_DECODE_SAMPLES } required" )
183+ return emptyList()
184+ }
185+
179186 val windows = mutableListOf<DecodeWindow >()
180- val cycleSamples = (WSPR_REQUIRED_SAMPLE_RATE * WSPR_CYCLE_DURATION_SECONDS ).toInt()
181- val availableCycles = audioBuffer.size / cycleSamples
182- val maxCycles = minOf(availableCycles, MAX_DECODE_WINDOWS )
183187
184- for (cycle in 0 until maxCycles)
185- {
186- val startIndex = cycle * cycleSamples
187- val endIndex = minOf(startIndex + REQUIRED_DECODE_SAMPLES , audioBuffer.size)
188+ // Create a single window from the start of the buffer
189+ // This is already time-aligned because collection starts at even_minute + 2s
190+ val endIndex = minOf(REQUIRED_DECODE_SAMPLES , audioBuffer.size)
188191
189- // Ensure we have enough data to decode
190- val windowDurationSeconds = (endIndex - startIndex.toFloat()) / WSPR_REQUIRED_SAMPLE_RATE
191- if (windowDurationSeconds >= WSPR_TRANSMISSION_DURATION_SECONDS )
192- {
193- windows.add(DecodeWindow (
194- startIndex,
195- endIndex,
196- description = " Time-aligned cycle ${cycle + 1 } (${startIndex / WSPR_REQUIRED_SAMPLE_RATE } s-${endIndex / WSPR_REQUIRED_SAMPLE_RATE } s)"
197- ))
198- }
199- }
192+ windows.add(DecodeWindow (
193+ startIndex = 0 ,
194+ endIndex = endIndex,
195+ description = " Time-aligned window (0s-${endIndex / WSPR_REQUIRED_SAMPLE_RATE } s)"
196+ ))
197+
198+ Timber .d(" Generated time-aligned window: 0-${endIndex} samples (${endIndex / WSPR_REQUIRED_SAMPLE_RATE } s)" )
200199
201200 return windows
202201 }
0 commit comments