mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
Fix debounce race and recorder callback write handling
This commit is contained in:
@@ -149,11 +149,15 @@ var lastToggleUnixNano int64
|
||||
func (a *App) ToggleRecording() {
|
||||
// Debounce toggle calls to prevent rapid firing from double-binds or Wayland glitches
|
||||
now := time.Now().UnixNano()
|
||||
for {
|
||||
last := atomic.LoadInt64(&lastToggleUnixNano)
|
||||
if last != 0 && time.Duration(now-last) < 500*time.Millisecond {
|
||||
return
|
||||
}
|
||||
atomic.StoreInt64(&lastToggleUnixNano, now)
|
||||
if atomic.CompareAndSwapInt64(&lastToggleUnixNano, last, now) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if atomic.LoadInt32(&a.recording) == 1 {
|
||||
a.StopRecording()
|
||||
|
||||
@@ -254,8 +254,15 @@ func (r *AudioRecorder) Cleanup() {
|
||||
|
||||
// onAudioData is called by miniaudio when audio data is available.
|
||||
func (r *AudioRecorder) onAudioData(_, inputSamples []byte, _ uint32) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
if r.outputFile != nil && len(inputSamples) > 0 {
|
||||
n, _ := r.outputFile.Write(inputSamples)
|
||||
n, err := r.outputFile.Write(inputSamples)
|
||||
if err != nil {
|
||||
logger.Error("Failed to write audio data: %v", err)
|
||||
return
|
||||
}
|
||||
r.dataSize += uint32(n)
|
||||
|
||||
// Calculate volume if callback is set
|
||||
|
||||
Reference in New Issue
Block a user