Commit b780a94047 for ffmpeg

commit b780a940477ac68cd80e88e42da4b6da2894f003
Author: Guillain d'Erceville <guillain@poulpe.us>
Date:   Sun Nov 1 04:56:46 2026 -0500

    avformat/dss: take DSS SP framing from the block headers

    Every 512 byte audio block starts with a six byte header, and three of
    those bytes describe the framing: how many bytes at the start of the
    payload still belong to the frame that began in the previous block,
    the byte-swap parity of the first whole frame in this block, and
    how many frames the block holds. The demuxer skipped all three and
    derived the framing instead by running on from the previous frame,
    from the first block to the last.

    The two agree for as long as nothing disturbs the recording, which
    is why most files decode correctly today. But a recording that was
    paused, resumed or edited restates the framing at the block where it
    resumes, and a running walk does not notice. From that point every
    frame is read a byte out of phase: the decoder is handed reflection
    coefficients and pulse positions that were never written, and the rest
    of the file is noise. Ignoring the frame count has a second effect,
    milder but always present, of reading on past the last recorded frame
    in a block and manufacturing audio that was never in the file.

    Start each block where its header says its first frame starts, with
    the parity its header gives, and emit exactly as many frames as it
    declares. Frames still straddle block boundaries, so the payload read
    steps over any header it meets. G.723.1 blocks carry no parity and
    their frames do not straddle, so that path is left alone.

    Measured against a reference decoder on seven recordings from Olympus
    and Philips machines, mean sample correlation goes from 0.5849 to
    0.9995. Three were misframed and went from 0.03, 0.03 and 0.04 to
    0.9998, 0.9990 and 0.9997, with their share of clipped samples falling
    from around 0.6% to 0.001%.

    The other four already decoded well, and the change barely touches
    them. Three come out with not one sample different; two of those three
    also lose a short tail, 2112 and 1320 samples, of padding the old
    walk read past the last declared frame. The fourth turned out to hold
    a misframed stretch of its own that the sampled windows had missed:
    2% of its samples change, and its clipped share drops from 0.016%
    to 0.001%.

    On a wider set of 187 recordings, nothing that decoded before
    stops decoding, and four files that produced no audio at all now
    decode. Where honouring the frame count makes the output shorter
    than before, the new length agrees to a tenth of a second with an
    independent decoder validated against the same reference, so the
    samples dropped are ones upstream was inventing.

    fate-dss-sp and fate-dss-lp are unchanged and pass: on an undisturbed
    recording the block headers say exactly what the running walk assumed,
    so the output is bit-identical.

    A missing or short block header ends the file with EOF, not with
    AVERROR_INVALIDDATA. Read from a pipe, the last frame of a block can run
    on into the next block, and the walk then seeks back to the header of
    that block. On an input that cannot seek, the walk calls
    ffio_ensure_seekback() for two blocks from each block it moves to, so
    the AVIOContext still holds that header. When a step fails, the walk
    restores the block position and sets the frame count of the block to 0,
    so the next call walks on from the last block it read.
    olympus-sp-empty56.dss is the first 7 audio blocks of a 3 s SP encode
    made with DssEncoder.dll from ODMS R8, with 56 empty SP blocks after its
    file header. fate-dss-sp-empty56 decodes it from the file, and
    fate-dss-sp-empty56-pipe reads it through pipe:0, 7 bytes at a time with
    -blocksize 7, and shares the reference. A walk that does not keep the
    bytes gave the first 75 of the 86 packets from that pipe and then ended.

    A block header states how many frames start in the block: byte 2 when it
    is not 0, otherwise byte 5 unless that is 0xff. A recorder writes the
    second form where it pauses or stops. The two Olympus decoders disagree
    on these frames. DssDecoder.dll 1.1.1.0 from ODMS R8 plays them, and
    dss32.dll, the 2007 Olympus decoder that NCH Switch ships, skips them.
    The source audio decides. olympus-sp-pause-block.dss is the 6th and 7th
    audio blocks of an R8 SP encode of src3, the 3 s clip in the FATE
    samples, the 6th rewritten to the pause form, 0 in byte 2 and the
    block's 13 frames in byte 5. NCH Switch decodes the whole encode so
    edited to 112 frames. The 50 frames after the pause block then correlate
    0.000 with the source at their place and 0.858 with the source 13 frames
    later, so the skipped frames hold 13 frames of the source. The walk
    keeps those frames, and fate-dss-sp-pause-block decodes the file to 24
    frames, sample-identical to the same blocks unedited. fate-dss-sp-paused
    decodes sp-paused.dss, the pause block of the paused SP vector from the
    ffmpeg-devel thread and the 2 blocks after it, to 27 frames, the 3
    frames of its pause block included. The whole vector decodes to 657
    frames, like R8. A packet takes its position where its frame starts,
    past the block header when the frame starts right at a block boundary.

    The figures for the seven recordings above were measured before this
    rule was added, so they leave out the frames of any pause blocks those
    recordings hold.

    A swapped SP frame takes one byte from the frame before it, two bytes
    before its own start. Carried over from the frame read last, that byte
    is wrong after a seek, at the start of a file cut out of a longer
    recording, and where a block restarts the framing. Whenever a block
    starts with a swapped frame, the demuxer reads the byte from the file,
    after the block header or at the end of the previous block, and it marks
    the byte unknown on open and on a seek. If the file does not hold it,
    the frame is dropped with FFERROR_REDO, so that av_read_frame() moves on
    to the next frame. On an input that cannot seek, the walk also keeps the
    2 bytes in front of each block it moves to. olympus-sp-swap-start.dss is
    the 7th and 8th audio blocks of a 3 s SP encode made with DssEncoder.dll
    from ODMS R8, so its first block starts with a swapped frame. In the
    decode of dss32.dll, the 2007-11-23 build that NCH Switch ships, the
    first two frames correlate 0.532 and 0.767 with the source at their
    place. FFmpeg's correlate 0.566 and 0.812. fate-dss-sp-swap-start
    decodes the file.

    The tests need these new files in the samples suite:

        dss/olympus-sp-empty56.dss
        dss/olympus-sp-pause-block.dss
        dss/olympus-sp-swap-start.dss
        dss/sp-paused.dss

    Signed-off-by: Patrick Domack <patrickdk@patrickdk.com>

diff --git a/libavformat/dss.c b/libavformat/dss.c
index da8f9a0bde..29cf7df38c 100644
--- a/libavformat/dss.c
+++ b/libavformat/dss.c
@@ -44,6 +44,7 @@

 #define DSS_BLOCK_SIZE                512
 #define DSS_AUDIO_BLOCK_HEADER_SIZE   6
+#define DSS_BLOCK_KEEP_BEFORE         2
 #define DSS_FRAME_SIZE                42

 static const uint8_t frame_size[4] = { 24, 20, 4, 1 };
@@ -52,12 +53,24 @@ typedef struct DSSDemuxContext {
     unsigned int audio_codec;
     int counter;
     int swap;
+    int64_t block_pos;      /* offset of the current audio block header */
+    int frames_left;        /* frames still to come from that block */
     int dss_sp_swap_byte;

     int packet_size;
     int dss_header_size;
 } DSSDemuxContext;

+/* Frames that start in an audio block: byte 2 when it is not 0, otherwise
+ * byte 5 unless that is 0xff. A recorder writes the second form where it
+ * pauses or stops, and those frames are audio like any other. */
+static int dss_block_frames(const uint8_t *header)
+{
+    if (header[2] || header[5] == 0xff)
+        return header[2];
+    return header[5];
+}
+
 static int dss_probe(const AVProbeData *p)
 {
     if (   AV_RL32(p->buf) != MKTAG(0x2, 'd', 's', 's')
@@ -173,11 +186,17 @@ static int dss_read_header(AVFormatContext *s)
         return (int)ret64;

     ctx->counter = 0;
-    ctx->swap    = 0;
+    ctx->swap        = 0;
+    ctx->frames_left = 0;
+    ctx->dss_sp_swap_byte = -1;
+    /* dss_sp_next_block steps forward first, so start one block short. */
+    ctx->block_pos   = ctx->dss_header_size - DSS_BLOCK_SIZE;

     return 0;
 }

+/* G.723.1 blocks carry no byte-swap parity and their frames do not straddle,
+ * so this path keeps the running walk it has always used. */
 static void dss_skip_audio_header(AVFormatContext *s, AVPacket *pkt)
 {
     DSSDemuxContext *ctx = s->priv_data;
@@ -187,6 +206,132 @@ static void dss_skip_audio_header(AVFormatContext *s, AVPacket *pkt)
     ctx->counter += DSS_BLOCK_SIZE - DSS_AUDIO_BLOCK_HEADER_SIZE;
 }

+static int dss_seek_block(AVFormatContext *s, int64_t pos)
+{
+    DSSDemuxContext *ctx = s->priv_data;
+    AVIOContext *pb = s->pb;
+    int64_t keep = FFMAX(pos - DSS_BLOCK_KEEP_BEFORE, ctx->dss_header_size);
+    int ret;
+
+    if (!(pb->seekable & AVIO_SEEKABLE_NORMAL)) {
+        if (avio_seek(pb, keep, SEEK_SET) < 0)
+            return AVERROR_EOF;
+        ret = ffio_ensure_seekback(pb, pos - keep + 2 * DSS_BLOCK_SIZE);
+        if (ret < 0)
+            return ret;
+    }
+    return avio_seek(pb, pos, SEEK_SET) < 0 ? AVERROR_EOF : 0;
+}
+
+/* Read `size` bytes of frame payload, stepping over any block header met on
+ * the way. Block payloads are contiguous as far as the frames are concerned,
+ * and a frame is short enough to straddle at most one boundary. */
+static int dss_sp_read_payload(AVFormatContext *s, uint8_t *buf, int size)
+{
+    DSSDemuxContext *ctx = s->priv_data;
+    AVIOContext *pb = s->pb;
+    int ret;
+
+    while (size > 0) {
+        int64_t off = (avio_tell(pb) - ctx->dss_header_size) % DSS_BLOCK_SIZE;
+        int chunk;
+
+        if (off < DSS_AUDIO_BLOCK_HEADER_SIZE) {
+            if (avio_skip(pb, DSS_AUDIO_BLOCK_HEADER_SIZE - off) < 0)
+                return AVERROR_EOF;
+            continue;
+        }
+        chunk = FFMIN(size, (int)(DSS_BLOCK_SIZE - off));
+        ret = ffio_read_size(pb, buf, chunk);
+        if (ret < 0)
+            return ret;
+        buf  += chunk;
+        size -= chunk;
+    }
+    return 0;
+}
+
+/* Move to the next audio block and take its framing from its header.
+ *
+ * Each block states the length of the frame fragment carried over from the
+ * previous block, the byte-swap parity of its first whole frame, and how many
+ * frames it holds. Deriving the framing by running on from the previous frame
+ * instead gives the same answer for as long as nothing disturbs the recording,
+ * which is why most files decode; but a paused or edited recording restates
+ * them, and a running walk then reads every remaining frame a byte out of
+ * phase. Believing the block keeps the walk in step, and costs nothing when
+ * the two agree. */
+static int dss_sp_next_block(AVFormatContext *s)
+{
+    DSSDemuxContext *ctx = s->priv_data;
+    AVIOContext *pb = s->pb;
+    uint8_t header[DSS_AUDIO_BLOCK_HEADER_SIZE];
+    int64_t block_pos = ctx->block_pos;
+    int cont, ret;
+
+    for (;;) {
+        ctx->block_pos += DSS_BLOCK_SIZE;
+        if ((ret = dss_seek_block(s, ctx->block_pos)) < 0)
+            goto fail;
+        ret = avio_read(pb, header, DSS_AUDIO_BLOCK_HEADER_SIZE);
+        if (ret < 0 && ret != AVERROR_EOF)
+            goto fail;
+        if (ret != DSS_AUDIO_BLOCK_HEADER_SIZE) {
+            ret = AVERROR_EOF;
+            goto fail;
+        }
+
+        ctx->swap = !!(header[0] & 0x80);
+        cont      = 2 * header[1] + 2 * ctx->swap - DSS_AUDIO_BLOCK_HEADER_SIZE;
+        if (cont < 0 || cont > DSS_BLOCK_SIZE - DSS_AUDIO_BLOCK_HEADER_SIZE)
+            cont = 0;
+
+        ctx->frames_left = dss_block_frames(header);
+        if (!ctx->frames_left)
+            continue;
+
+        /* A swapped frame takes one byte from the frame before it, two bytes
+         * before its own start, in this block or at the end of the previous
+         * one. Read it from there rather than carry it over: after a seek, at
+         * the start of a cut file, or where a block restarts the framing, the
+         * frame before has not been read. */
+        if (ctx->swap) {
+            int64_t at = ctx->block_pos + cont - 2;
+
+            if (cont >= 2)
+                at += DSS_AUDIO_BLOCK_HEADER_SIZE;
+            if (at >= ctx->dss_header_size + DSS_AUDIO_BLOCK_HEADER_SIZE &&
+                avio_seek(pb, at, SEEK_SET) >= 0)
+                ctx->dss_sp_swap_byte = avio_r8(pb);
+        }
+
+        if (avio_seek(pb, ctx->block_pos + DSS_AUDIO_BLOCK_HEADER_SIZE + cont,
+                      SEEK_SET) < 0) {
+            ret = AVERROR_EOF;
+            goto fail;
+        }
+        return 0;
+    }
+
+fail:
+    ctx->block_pos   = block_pos;
+    ctx->frames_left = 0;
+    return ret;
+}
+
+/* Offset of the next frame. A frame can start where a block does, after the
+ * block header that dss_sp_read_payload() steps over. */
+static int64_t dss_frame_pos(AVFormatContext *s)
+{
+    DSSDemuxContext *ctx = s->priv_data;
+    int64_t pos = avio_tell(s->pb);
+    int64_t off = (pos - ctx->dss_header_size) % DSS_BLOCK_SIZE;
+
+    if (off < DSS_AUDIO_BLOCK_HEADER_SIZE)
+        pos += DSS_AUDIO_BLOCK_HEADER_SIZE - off;
+    return pos;
+}
+
 static void dss_sp_byte_swap(DSSDemuxContext *ctx, uint8_t *data)
 {
     int i;
@@ -210,11 +355,15 @@ static void dss_sp_byte_swap(DSSDemuxContext *ctx, uint8_t *data)
 static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     DSSDemuxContext *ctx = s->priv_data;
-    int read_size, ret, offset = 0, buff_offset = 0;
-    int64_t pos = avio_tell(s->pb);
+    int read_size, ret, buff_offset = 0;
+    int64_t pos;

-    if (ctx->counter == 0)
-        dss_skip_audio_header(s, pkt);
+    if (ctx->frames_left <= 0) {
+        ret = dss_sp_next_block(s);
+        if (ret < 0)
+            return ret;
+    }
+    pos = dss_frame_pos(s);

     if (ctx->swap) {
         read_size   = DSS_FRAME_SIZE - 2;
@@ -230,22 +379,12 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt)
     pkt->pos = pos;
     pkt->stream_index = 0;

-    if (ctx->counter < read_size) {
-        ret = avio_read(s->pb, pkt->data + buff_offset,
-                        ctx->counter);
-        if (ret < ctx->counter)
-            goto error_eof;
-
-        offset = ctx->counter;
-        dss_skip_audio_header(s, pkt);
-    }
-    ctx->counter -= read_size;
-
     /* This will write one byte into pkt's padding if buff_offset == 3 */
-    ret = avio_read(s->pb, pkt->data + offset + buff_offset,
-                    read_size - offset);
-    if (ret < read_size - offset)
-        goto error_eof;
+    ret = dss_sp_read_payload(s, pkt->data + buff_offset, read_size);
+    if (ret < 0)
+        return ret == AVERROR_EOF ? ret : AVERROR_EOF;
+
+    ctx->frames_left--;

     dss_sp_byte_swap(ctx, pkt->data);

@@ -254,9 +393,6 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt)
     }

     return 0;
-
-error_eof:
-    return ret < 0 ? ret : AVERROR_EOF;
 }

 static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
@@ -346,7 +482,14 @@ static int dss_read_seek(AVFormatContext *s, int stream_index,
     ret = ffio_read_size(s->pb, header, DSS_AUDIO_BLOCK_HEADER_SIZE);
     if (ret < 0)
         return ret;
-    ctx->swap = !!(header[0] & 0x80);
+    ctx->swap        = !!(header[0] & 0x80);
+    ctx->frames_left = 0;
+    ctx->block_pos   = seekto - DSS_BLOCK_SIZE;
+    if (ctx->audio_codec == DSS_ACODEC_DSS_SP) {
+        ctx->dss_sp_swap_byte = -1;
+        return 0;
+    }
+
     offset = 2*header[1] + 2*ctx->swap;
     if (offset < DSS_AUDIO_BLOCK_HEADER_SIZE)
         return AVERROR_INVALIDDATA;
diff --git a/tests/fate/audio.mak b/tests/fate/audio.mak
index ec028909d5..6238554b13 100644
--- a/tests/fate/audio.mak
+++ b/tests/fate/audio.mak
@@ -37,6 +37,22 @@ fate-dss-lp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/lp.dss -frames 30 -af aresa
 FATE_SAMPLES_AUDIO-$(call FRAMECRC, DSS, DSS_SP) += fate-dss-sp
 fate-dss-sp: CMD = framecrc -i $(TARGET_SAMPLES)/dss/sp.dss -frames 30

+FATE_SAMPLES_AUDIO-$(call FRAMECRC, DSS, DSS_SP) += fate-dss-sp-empty56
+fate-dss-sp-empty56: CMD = framecrc -i $(TARGET_SAMPLES)/dss/olympus-sp-empty56.dss
+
+FATE_SAMPLES_AUDIO-$(call FRAMECRC, DSS, DSS_SP, PIPE_PROTOCOL) += fate-dss-sp-empty56-pipe
+fate-dss-sp-empty56-pipe: CMD = cat $(SAMPLES)/dss/olympus-sp-empty56.dss | framecrc -blocksize 7 -i pipe:0
+fate-dss-sp-empty56-pipe: REF = $(SRC_PATH)/tests/ref/fate/dss-sp-empty56
+
+FATE_SAMPLES_AUDIO-$(call FRAMECRC, DSS, DSS_SP) += fate-dss-sp-pause-block
+fate-dss-sp-pause-block: CMD = framecrc -i $(TARGET_SAMPLES)/dss/olympus-sp-pause-block.dss
+
+FATE_SAMPLES_AUDIO-$(call FRAMECRC, DSS, DSS_SP) += fate-dss-sp-paused
+fate-dss-sp-paused: CMD = framecrc -i $(TARGET_SAMPLES)/dss/sp-paused.dss
+
+FATE_SAMPLES_AUDIO-$(call FRAMECRC, DSS, DSS_SP) += fate-dss-sp-swap-start
+fate-dss-sp-swap-start: CMD = framecrc -i $(TARGET_SAMPLES)/dss/olympus-sp-swap-start.dss
+
 FATE_SAMPLES_AUDIO-$(call PCM, DSF, DST, ARESAMPLE_FILTER SWRESAMPLE) += fate-dsf-dst
 fate-dsf-dst: CMD = pcm -i $(TARGET_SAMPLES)/dst/dst-64fs44-2ch.dff
 fate-dsf-dst: CMP = oneoff
diff --git a/tests/ref/fate/dss-sp-empty56 b/tests/ref/fate/dss-sp-empty56
new file mode 100644
index 0000000000..9fabc0af24
--- /dev/null
+++ b/tests/ref/fate/dss-sp-empty56
@@ -0,0 +1,91 @@
+#tb 0: 1/11000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 11000
+#channel_layout_name 0: mono
+0,          0,          0,      264,      528, 0x00000000
+0,        264,        264,      264,      528, 0x61a5d195
+0,        528,        528,      264,      528, 0x38b93f99
+0,        792,        792,      264,      528, 0xebb80008
+0,       1056,       1056,      264,      528, 0xef5b1627
+0,       1320,       1320,      264,      528, 0xc7aeb52d
+0,       1584,       1584,      264,      528, 0x718f4796
+0,       1848,       1848,      264,      528, 0xab4e2643
+0,       2112,       2112,      264,      528, 0xf1e710e6
+0,       2376,       2376,      264,      528, 0x99a3fc2d
+0,       2640,       2640,      264,      528, 0x7c961bda
+0,       2904,       2904,      264,      528, 0x98667340
+0,       3168,       3168,      264,      528, 0xe1a12ec9
+0,       3432,       3432,      264,      528, 0x04f919fb
+0,       3696,       3696,      264,      528, 0x68d14534
+0,       3960,       3960,      264,      528, 0x9fb6f119
+0,       4224,       4224,      264,      528, 0xfdc6f208
+0,       4488,       4488,      264,      528, 0xb66414f0
+0,       4752,       4752,      264,      528, 0x71b12634
+0,       5016,       5016,      264,      528, 0x8bb40d89
+0,       5280,       5280,      264,      528, 0xa37d20c9
+0,       5544,       5544,      264,      528, 0x99392ead
+0,       5808,       5808,      264,      528, 0xb1314665
+0,       6072,       6072,      264,      528, 0xc44324ae
+0,       6336,       6336,      264,      528, 0x085a018d
+0,       6600,       6600,      264,      528, 0x46fb00fd
+0,       6864,       6864,      264,      528, 0xf7b6f29a
+0,       7128,       7128,      264,      528, 0x350d3df2
+0,       7392,       7392,      264,      528, 0xb67c33a6
+0,       7656,       7656,      264,      528, 0x4364f879
+0,       7920,       7920,      264,      528, 0x26dd0fc5
+0,       8184,       8184,      264,      528, 0x6a8115bf
+0,       8448,       8448,      264,      528, 0x35fb0317
+0,       8712,       8712,      264,      528, 0x56a7f9c5
+0,       8976,       8976,      264,      528, 0xb87bf9f6
+0,       9240,       9240,      264,      528, 0xb863027c
+0,       9504,       9504,      264,      528, 0x7bdb050a
+0,       9768,       9768,      264,      528, 0x3a1a1425
+0,      10032,      10032,      264,      528, 0x8028fc11
+0,      10296,      10296,      264,      528, 0x4448fe30
+0,      10560,      10560,      264,      528, 0x103cef0a
+0,      10824,      10824,      264,      528, 0x0c830cde
+0,      11088,      11088,      264,      528, 0x6124ec04
+0,      11352,      11352,      264,      528, 0x0cbffe92
+0,      11616,      11616,      264,      528, 0xfbef0d75
+0,      11880,      11880,      264,      528, 0x5326eeda
+0,      12144,      12144,      264,      528, 0x223d1758
+0,      12408,      12408,      264,      528, 0x9b35326c
+0,      12672,      12672,      264,      528, 0x09621cbf
+0,      12936,      12936,      264,      528, 0xd6f9d122
+0,      13200,      13200,      264,      528, 0x45152980
+0,      13464,      13464,      264,      528, 0x173907f6
+0,      13728,      13728,      264,      528, 0x81b70202
+0,      13992,      13992,      264,      528, 0x5f230c4b
+0,      14256,      14256,      264,      528, 0xcd780827
+0,      14520,      14520,      264,      528, 0xf2eafc03
+0,      14784,      14784,      264,      528, 0x02a2fef9
+0,      15048,      15048,      264,      528, 0xa28b1a00
+0,      15312,      15312,      264,      528, 0xb0ff32d8
+0,      15576,      15576,      264,      528, 0xd6f6fbc4
+0,      15840,      15840,      264,      528, 0xe7eb0344
+0,      16104,      16104,      264,      528, 0xb5a2fbdd
+0,      16368,      16368,      264,      528, 0xd5e90c99
+0,      16632,      16632,      264,      528, 0xd8b61602
+0,      16896,      16896,      264,      528, 0xb0a70077
+0,      17160,      17160,      264,      528, 0x2b7904bc
+0,      17424,      17424,      264,      528, 0xe14d1c41
+0,      17688,      17688,      264,      528, 0x3c3af2ab
+0,      17952,      17952,      264,      528, 0xfc2006a8
+0,      18216,      18216,      264,      528, 0x90d10577
+0,      18480,      18480,      264,      528, 0x98ed017b
+0,      18744,      18744,      264,      528, 0x86c70d6e
+0,      19008,      19008,      264,      528, 0x588405cc
+0,      19272,      19272,      264,      528, 0xdf4a2407
+0,      19536,      19536,      264,      528, 0xe28af5cc
+0,      19800,      19800,      264,      528, 0xf68bf594
+0,      20064,      20064,      264,      528, 0xfd69017f
+0,      20328,      20328,      264,      528, 0x12e4047d
+0,      20592,      20592,      264,      528, 0x2ed603c5
+0,      20856,      20856,      264,      528, 0x5e940429
+0,      21120,      21120,      264,      528, 0x5cb9f888
+0,      21384,      21384,      264,      528, 0x4e2e02fa
+0,      21648,      21648,      264,      528, 0x995e1824
+0,      21912,      21912,      264,      528, 0xc1ecf957
+0,      22176,      22176,      264,      528, 0xf9a5fbb1
+0,      22440,      22440,      264,      528, 0xc9f2fcd6
diff --git a/tests/ref/fate/dss-sp-pause-block b/tests/ref/fate/dss-sp-pause-block
new file mode 100644
index 0000000000..8080b3978b
--- /dev/null
+++ b/tests/ref/fate/dss-sp-pause-block
@@ -0,0 +1,29 @@
+#tb 0: 1/11000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 11000
+#channel_layout_name 0: mono
+0,          0,          0,      264,      528, 0xfb83f744
+0,        264,        264,      264,      528, 0xbf9f0c7b
+0,        528,        528,      264,      528, 0x757be607
+0,        792,        792,      264,      528, 0xe4f3f9a2
+0,       1056,       1056,      264,      528, 0xc23afa8d
+0,       1320,       1320,      264,      528, 0x8b5cfad7
+0,       1584,       1584,      264,      528, 0xeaf30619
+0,       1848,       1848,      264,      528, 0x63890311
+0,       2112,       2112,      264,      528, 0x37c3007b
+0,       2376,       2376,      264,      528, 0x82530d6f
+0,       2640,       2640,      264,      528, 0x788e05f1
+0,       2904,       2904,      264,      528, 0x0bdb241d
+0,       3168,       3168,      264,      528, 0x0229f3e3
+0,       3432,       3432,      264,      528, 0xbc7ef435
+0,       3696,       3696,      264,      528, 0x28bc0446
+0,       3960,       3960,      264,      528, 0x44d007b5
+0,       4224,       4224,      264,      528, 0x35080344
+0,       4488,       4488,      264,      528, 0x83de0316
+0,       4752,       4752,      264,      528, 0xb146f6c7
+0,       5016,       5016,      264,      528, 0x79570454
+0,       5280,       5280,      264,      528, 0x618b16fc
+0,       5544,       5544,      264,      528, 0xc3b5fadc
+0,       5808,       5808,      264,      528, 0xf742fba6
+0,       6072,       6072,      264,      528, 0xf2b4fe6a
diff --git a/tests/ref/fate/dss-sp-paused b/tests/ref/fate/dss-sp-paused
new file mode 100644
index 0000000000..1fb0463393
--- /dev/null
+++ b/tests/ref/fate/dss-sp-paused
@@ -0,0 +1,32 @@
+#tb 0: 1/11000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 11000
+#channel_layout_name 0: mono
+0,          0,          0,      264,      528, 0x97c91239
+0,        264,        264,      264,      528, 0xa6c9115d
+0,        528,        528,      264,      528, 0xf46a0a42
+0,        792,        792,      264,      528, 0x0816f5cc
+0,       1056,       1056,      264,      528, 0xaea922bc
+0,       1320,       1320,      264,      528, 0x08c70536
+0,       1584,       1584,      264,      528, 0x792f075e
+0,       1848,       1848,      264,      528, 0x273a0bc2
+0,       2112,       2112,      264,      528, 0xf88e1729
+0,       2376,       2376,      264,      528, 0x4d020cdb
+0,       2640,       2640,      264,      528, 0xc8e51479
+0,       2904,       2904,      264,      528, 0x314ade72
+0,       3168,       3168,      264,      528, 0xd241fa24
+0,       3432,       3432,      264,      528, 0xd08b0937
+0,       3696,       3696,      264,      528, 0xe559ffb5
+0,       3960,       3960,      264,      528, 0xf554dda2
+0,       4224,       4224,      264,      528, 0x2f34f6da
+0,       4488,       4488,      264,      528, 0x14230ab0
+0,       4752,       4752,      264,      528, 0x750203a1
+0,       5016,       5016,      264,      528, 0x863e14df
+0,       5280,       5280,      264,      528, 0xa1b2fac3
+0,       5544,       5544,      264,      528, 0xd0af0c9c
+0,       5808,       5808,      264,      528, 0x5e1b0e47
+0,       6072,       6072,      264,      528, 0xdbaf046a
+0,       6336,       6336,      264,      528, 0x266b0217
+0,       6600,       6600,      264,      528, 0xe32a0cd6
+0,       6864,       6864,      264,      528, 0x18d7e17a
diff --git a/tests/ref/fate/dss-sp-swap-start b/tests/ref/fate/dss-sp-swap-start
new file mode 100644
index 0000000000..f195b57d41
--- /dev/null
+++ b/tests/ref/fate/dss-sp-swap-start
@@ -0,0 +1,28 @@
+#tb 0: 1/11000
+#media_type 0: audio
+#codec_id 0: pcm_s16le
+#sample_rate 0: 11000
+#channel_layout_name 0: mono
+0,          0,          0,      264,      528, 0x67a50ed0
+0,        264,        264,      264,      528, 0x1673fdbe
+0,        528,        528,      264,      528, 0xe0140870
+0,        792,        792,      264,      528, 0x023b056f
+0,       1056,       1056,      264,      528, 0x63dd0912
+0,       1320,       1320,      264,      528, 0xaf2af6fe
+0,       1584,       1584,      264,      528, 0x76b90cda
+0,       1848,       1848,      264,      528, 0xd3ac1b24
+0,       2112,       2112,      264,      528, 0xc100fdd8
+0,       2376,       2376,      264,      528, 0xc4a6f654
+0,       2640,       2640,      264,      528, 0x01a0f8ec
+0,       2904,       2904,      264,      528, 0xdd52f4c8
+0,       3168,       3168,      264,      528, 0xa4bafcff
+0,       3432,       3432,      264,      528, 0xfe6e1bf9
+0,       3696,       3696,      264,      528, 0x3f7f0823
+0,       3960,       3960,      264,      528, 0x07440797
+0,       4224,       4224,      264,      528, 0x69224af3
+0,       4488,       4488,      264,      528, 0xda00f17e
+0,       4752,       4752,      264,      528, 0xc4cce87c
+0,       5016,       5016,      264,      528, 0x4e454196
+0,       5280,       5280,      264,      528, 0xb022248a
+0,       5544,       5544,      264,      528, 0xe551043f
+0,       5808,       5808,      264,      528, 0xae5e317e