Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store sample rate of block #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Gusted
Copy link

@Gusted Gusted commented Jun 10, 2024

FLAC can have a different sample rate for every frame, therefore it should be stored in Block and have a function that exposes the value of it.

Ref: https://github.com/ietf-wg-cellar/flac-test-files/blob/main/uncommon/01%20-%20changing%20samplerate.flac

FLAC can have a different sample rate for every frame, therefore it
should be stored in `Block` and have a function that exposes the value
of it.

Ref: https://github.com/ietf-wg-cellar/flac-test-files/blob/main/uncommon/01%20-%20changing%20samplerate.flac
Copy link
Owner

@ruuda ruuda left a comment

Choose a reason for hiding this comment

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

Thank you for taking the time to open a pull request. This makes sense to add, but let’s make sure that the sample rate is always set to the correct value then.

@@ -504,6 +508,12 @@ impl Block {
return self.buffer;
}

/// Returns the sample rate of this block.
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
/// Returns the sample rate of this block.
/// Returns the sample rate of this block in Hz.

@@ -773,7 +783,7 @@ impl<R: ReadBytes> FrameReader<R> {
BlockTime::SampleNumber(snr) => snr,
};

let block = Block::new(time, header.block_size as u32, buffer);
let block = Block::new(time, header.block_size as u32, header.sample_rate.unwrap_or_default(), buffer);
Copy link
Owner

Choose a reason for hiding this comment

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

unwrap_or_default would default to 0 when the header does not specify a sample rate. Instead, we need to get the value from the streaminfo:

0b0000 => sample_rate = None, // 0000 means 'get from streaminfo block'.

Copy link
Author

Choose a reason for hiding this comment

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

It doesn't seem like streaminfo is available from this function's scope?

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.

2 participants