Skip to content

Make flac do sample rate accurrate seek - #679

Closed
Wang-Yue wants to merge 3 commits into
cmus:masterfrom
Wang-Yue:patch-1
Closed

Wang-Yue wants to merge 3 commits into
cmus:masterfrom
Wang-Yue:patch-1

Conversation

@Wang-Yue

Copy link
Copy Markdown
Contributor

fix #678

@Wang-Yue Wang-Yue mentioned this pull request Apr 22, 2017
3 of 9 tasks
Comment thread ip/flac.c

if (ip_data->sf == 0) {
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ip_data->sf should be non zero after _open. if it's zero things are terribly wrong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/ip/flac.c b/ip/flac.c
index 90a97b6..1bc585e 100644
--- a/ip/flac.c
+++ b/ip/flac.c
@@ -66,6 +66,8 @@ static T(ReadStatus) read_cb(const Dec *dec, unsigned char *buf, size_t *size, v
 	struct flac_private *priv = ip_data->private;
 	int rc;
 
+	fprintf(stderr, "ip_data->sf = %d\n", ip_data->sf);
+
 	if (priv->pos == priv->len) {
 		*size = 0;
 		return E(READ_STATUS_END_OF_STREAM);

Tells me that it's zero sometimes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, my bad. This was the wrong callback.

Comment thread ip/flac.c
}
priv->ignore_next_write = 1;
priv->buf_rpos = 0;
priv->buf_wpos = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the FLAC__stream_decoder_seek_absolute will internally call seek_to_absolute_sample_, which process a frame. See https://github.com/xiph/flac/blob/4f47b63e9c971e6391590caf00a0f2a5ed612e67/src/libFLAC/stream_decoder.c#L3140 .

so the wirte_cb will be called during flac_seek.
If buf position is reset to 0, the first block is entirely missing.

Thus, flushing and buf resetting should only be done when something is wrong.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you need to set these before calling seek.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. These should never be reset when things are performing without error. otherwise you might get partial samples if flac_read is not finished through the end, and the stream will be broken.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say that we're seeking from 5s to 10s. At the point of the seek we've already buffered the samples up to 5.5s. If we don't reset these values, then, after the seek, we'll continue to play the samples from 5s to 5.5s and only then start to play the samples at 10s.

Is this the intended behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original author is mislead by flac doc, which mentioned the stream may contain a partial block when seeking. So he tried to reset that block. But what flac doc really means is you won't get the entire block as you normally do when using process_single, becauce the sample may live in the middle of a flac block (which contains various samples). But flac ensures you that you won't get partial samples. You'll always get right data stream when doing seek_absolute. There's no need to reset at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you've answered my question. I'm talking about our buffer flac_private::buf. Should we not clear this buffer before seeking?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Done.

@Wang-Yue Wang-Yue left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread ip/flac.c
}
priv->ignore_next_write = 1;
priv->buf_rpos = 0;
priv->buf_wpos = 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Done.

@mahkoh

mahkoh commented Apr 22, 2017

Copy link
Copy Markdown
Member

Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLAC plugin's seek is not sample-accurrate

2 participants