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

Trying to understand number of processed buffers per second #61

Open
polyclick opened this issue Feb 14, 2021 · 0 comments
Open

Trying to understand number of processed buffers per second #61

polyclick opened this issue Feb 14, 2021 · 0 comments

Comments

@polyclick
Copy link

polyclick commented Feb 14, 2021

Hi

I'm really trying to understand why the following happens.
Any insight would be super useful. 🤪

I have set the following settings from an audio-in readable stream:

sampleRate: 44100
sampleFormat: 16   // 2 bytes per sample per channel
channelCount: 12   // sound card with 12 inputs (6x Left/Right)
highwaterMark = 12 * 2 * 512 // (12 open channels) * (2 bytes per frame) * (512 frames per buffer) = 12288 bytes

I'd think that the buffer-callback gets called +- 86 times per second:
44100 samples per second / 512 samples = 86.1328125

Yet, when I manually count the amount of buffer-callbacks, I get 172, which is exactly the double.
Here's the code how I count the buffer-callback:

let prevTimestamp = 0
let processedBuffersInSecond = 0
this.stream.on(`data`, (buffer) => {
  processedBuffersInSecond++

  if(buffer.timestamp - prevTimestamp > 1) {
    console.log(`Buffers processed in 1 sec: ${processedBuffersInSecond}, ${this.sampleRate} / ${this.framesPerBuffer} = ${this.sampleRate / this.framesPerBuffer}`)
    processedBuffersInSecond = 0
    prevTimestamp = buffer.timestamp
  }
})
# Output
Buffers processed in 1 sec: 172, 44100 / 512 = 86.1328125
Buffers processed in 1 sec: 172, 44100 / 512 = 86.1328125
Buffers processed in 1 sec: 172, 44100 / 512 = 86.1328125
Buffers processed in 1 sec: 173, 44100 / 512 = 86.1328125
Buffers processed in 1 sec: 172, 44100 / 512 = 86.1328125
Buffers processed in 1 sec: 172, 44100 / 512 = 86.1328125
Buffers processed in 1 sec: 172, 44100 / 512 = 86.1328125

Why is this? Am I missing something?

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

No branches or pull requests

1 participant