Notification sound added. Docs updated.
This commit is contained in:
1 parent
4c9a267897
commit
81cc630319
29 files changed
+845
-57
No files matched your search
@@ -38,6 +38,8 @@ import (
|
||||
type Service struct {
|
||||
clips map[presentation.Cue]*clip
|
||||
pending atomic.Pointer[clip]
|
||||
notification atomic.Pointer[clip]
|
||||
draining *notificationPlayback // audio callback owns this boundary
|
||||
tones [101]*clip
|
||||
indentationTones [101]*clip
|
||||
progress atomic.Pointer[clip]
|
||||
@@ -126,6 +128,19 @@ func (s *Service) read_samples(samples []float32) (int, error) {
|
||||
if s.closed.Load() {
|
||||
return len(samples), nil
|
||||
}
|
||||
// Notification cues retain their tail despite ordinary cue updates. Their
|
||||
// boundary drains the device before speech is released by Play_wait.
|
||||
if s.current != nil && s.current.notification != nil {
|
||||
request := s.current.notification
|
||||
if request.ctx.Err() != nil || s.finishing.Load() {
|
||||
s.offset = len(s.current.samples)
|
||||
}
|
||||
if s.offset == len(s.current.samples) {
|
||||
s.draining, s.current = request, nil
|
||||
return 0, errNotificationDrain
|
||||
}
|
||||
return s.copy_samples(samples)
|
||||
}
|
||||
if s.cancelProgress.Swap(false) && s.progressing {
|
||||
s.current, s.progressing = nil, false
|
||||
}
|
||||
@@ -137,7 +152,9 @@ func (s *Service) read_samples(samples []float32) (int, error) {
|
||||
s.current, s.offset, s.starting, s.progressing = next, 0, true, false
|
||||
}
|
||||
if !s.starting {
|
||||
if next := s.pending.Swap(nil); next != nil {
|
||||
if next := s.notification.Swap(nil); next != nil && next.notification.ctx.Err() == nil && !s.finishing.Load() {
|
||||
s.current, s.offset, s.progressing = next, 0, false
|
||||
} else if next := s.pending.Swap(nil); next != nil {
|
||||
s.current, s.offset, s.progressing = next, 0, false
|
||||
}
|
||||
}
|
||||
@@ -151,6 +168,10 @@ func (s *Service) read_samples(samples []float32) (int, error) {
|
||||
s.current = nil
|
||||
return 0, pulse.EndOfData
|
||||
}
|
||||
return s.copy_samples(samples)
|
||||
}
|
||||
|
||||
func (s *Service) copy_samples(samples []float32) (int, error) {
|
||||
if s.current != nil {
|
||||
count := copy(samples, s.current.samples[s.offset:])
|
||||
volume := math.Float32frombits(s.volume.Load())
|
||||
@@ -161,7 +182,7 @@ func (s *Service) read_samples(samples []float32) (int, error) {
|
||||
samples[index] *= volume
|
||||
}
|
||||
s.offset += count
|
||||
if s.offset == len(s.current.samples) && s.current.finished == nil {
|
||||
if s.offset == len(s.current.samples) && s.current.finished == nil && s.current.notification == nil {
|
||||
s.current = nil
|
||||
s.starting, s.progressing = false, false
|
||||
}
|
||||
@@ -206,6 +227,7 @@ func (s *Service) Close() {
|
||||
return
|
||||
}
|
||||
s.pending.Store(nil)
|
||||
s.notification.Store(nil)
|
||||
s.Clear_progress()
|
||||
s.startup.Store(nil)
|
||||
if s.done != nil {
|
||||
|
||||
Reference in new issue
Block a user