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

getSampleRate disagrees with getFramesRead for input streams when sample rate conversion is enabled #1256

Closed
chrismanchester opened this issue May 3, 2021 · 2 comments · Fixed by #1276
Assignees
Labels

Comments

@chrismanchester
Copy link

The calculation here: 

mRateScaler = ((double) sourceStream->getSampleRate()) / sinkStream->getSampleRate();
makes a ratio that will convert from output to input sample rate. However, getSampleRate will always report the requested (converted) sample rate, which is the input sample rate for an output stream, but the output sample rate for an input stream. This means calculations working with getSampleRate along with getFramesRead on input streams will yield incorrect values. Changing the value of mRateScaler to ((double) getSampleRate()) / mChildStream->getSampleRate(); appears to resolve this issue, by setting up a ratio that will consistently convert from the child (native) sample rate to the software (converted) sample rate.

To demonstrate the problem, if we make a function that calculates latency for a stream based on AudioStreamAAudio's calculateLatencyMillis, it will produce implausibly small or negative values for latency when calculating for an input stream that's converting from 48k to 44.1k.

@philburk
Copy link
Collaborator

philburk commented May 4, 2021

Thank you for reporting this problem with mRateScaler. You are correct. We will fix that.

The best way to REPRODUCE the problem is:

  • Launch OboeTester
  • Tap TEST INPUT
  • Select SRate: 8000
  • Select Convert: SRC: Medium
  • Tap OPEN, START
  • Wait 10 seconds
  • Tap STOP
  • Look at Frames read and frames written

EXPECT: about 10*8000 = 80,000 frames

ACTUAL: about 3,200,000 frames

We should fix this and also add a unit test to detect it.

@philburk philburk added the bug label May 4, 2021
@philburk philburk added this to the v1.5.2 milestone May 4, 2021
flamme added a commit that referenced this issue May 17, 2021
@philburk
Copy link
Collaborator

Reopening for unit tests.

@philburk philburk reopened this May 17, 2021
@philburk philburk removed this from the v1.5.2 milestone May 17, 2021
flamme added a commit that referenced this issue May 17, 2021
Add unit tests that open input/output stream and process data for a
while and then verify the returned value from getFramesWritten is
correct.

Fixes #1256.
flamme added a commit that referenced this issue May 18, 2021
Add unit tests to that open input/output stream and process data for a
while and then verify the returned values from getFramesWritten and
getFramesRead are correct.

Fixes #1256.
flamme added a commit that referenced this issue May 19, 2021
* Add unit tests for testing frames processed.

Add unit tests to that open input/output stream and process data for a
while and then verify the returned values from getFramesWritten and
getFramesRead are correct.

Fixes #1256.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants