about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2022-08-14 21:24:54 +0000
committerEric Wong <e@80x24.org>2022-08-14 22:58:43 +0000
commita2386146b7132533f3b8e2041e85eceff4aeab84 (patch)
treee86001843466c7911d9b75ad4ec5f58b20bbe257
parent2cfb6b0a1a92bbfd1811a15893ac9563f027c0c4 (diff)
downloaddtas-a2386146b7132533f3b8e2041e85eceff4aeab84.tar.gz
For users of the CPU-saving bypass mode (e.g. "format rate=bypass"),
this fixes a bug when enqueueing a 44.1kHz immediately after a
48kHz file (or vice-versa).

Note: gapless playback with different rates/channels between
tracks has never been supported with bypass mode enabled.
Bypass only allows opportunistic gapless when sequential tracks
have the same format.
-rw-r--r--lib/dtas/player.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index 06ba788..6ea3aba 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -37,6 +37,7 @@ class DTAS::Player # :nodoc:
     @paused = false
     @format = DTAS::Format.new
     @bypass = [] # %w(rate bits channels) (not worth Hash overhead)
+    @bypass_next = nil # source_spec
 
     @sinks = {} # { user-defined name => sink }
     @targets = [] # order matters
@@ -331,6 +332,7 @@ class DTAS::Player # :nodoc:
 
   # called when the player is leaving idle state
   def spawn_sinks(source_spec)
+    @bypass_next = nil
     return true if @targets[0]
     @sinks.each_value do |sink|
       sink.active or next
@@ -392,6 +394,8 @@ class DTAS::Player # :nodoc:
       if ! @bypass.empty? && pending.respond_to?(:format)
         new_fmt = bypass_match!(@format.dup, pending.format)
         if new_fmt != @format
+          @bypass_next = source_spec
+          return if @sink_buf.inflight > 0
           stop_sinks # we may fail to start below
           format_update!(new_fmt)
         end
@@ -434,6 +438,7 @@ class DTAS::Player # :nodoc:
   end
 
   def stop_sinks
+    @bypass_next = nil
     @targets.each { |t| drop_target(t) }.clear
   end
 
@@ -458,7 +463,9 @@ class DTAS::Player # :nodoc:
     end
 
     # nothing left inflight, stop the sinks until we have a source
+    bn = @bypass_next
     stop_sinks
+    next_source(bn) if bn # are we restarting for bypass?
     :ignore
   end