Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mingzhi22
Copy link
Contributor

@mingzhi22 mingzhi22 commented Sep 17, 2018

Checklist
  • npm test passes (tip: npm run autofix can correct most style issues)
  • tests are included
  • readme and/or JSDoc is updated

@CLAassistant
Copy link

CLAassistant commented Sep 17, 2018

CLA assistant check
All committers have signed the CLA.

@mingzhi22 mingzhi22 closed this Sep 17, 2018
@mingzhi22 mingzhi22 reopened this Sep 17, 2018
@mingzhi22 mingzhi22 changed the title fix bug fix: 降采样后的文件有噪声 Sep 17, 2018
@germanattanasio
Copy link
Contributor

@mingzhi22 why?

@mingzhi22
Copy link
Contributor Author

@mingzhi22 why?

   var indexSampleAfterLastUsed = Math.round(samplingRateRatio * i); // 'i' is out of range
   var remaining = buffer.length - indexSampleAfterLastUsed;
   if (remaining > 0) { // 'remaining' is always less than 0

@germanattanasio
Copy link
Contributor

I'll let @dpopp07 decide

@dpopp07
Copy link
Contributor

dpopp07 commented Sep 18, 2018

Hi @mingzhi22
I admit, I don't fully understand the DSP behind this code. By looking at it mathematically, I can see that you are correct that

  1. i will be out of range by the end of the loop and
  2. remaining will always be less than 0

However, I am not fully convinced that your fix is what we want (probably because of my lack of understanding), although it certainly solves the "out of range" problem.

Could you please post your use-case, an example, or just an explanation of why you are changing the loop to end at outputBuffer.length? I just don't want to commit code I don't understand. Thanks

@mingzhi22
Copy link
Contributor Author

mingzhi22 commented Sep 19, 2018

// remaining will equal 1 when 1st call downsample, equal 2 when 2nd call downsample.
for (i = 0; i < outputBuffer.length; i++) {

img_0660

@mingzhi22
Copy link
Contributor Author

// i will be out of range, remaining will always be less than 0
for (i = 0; i + filter.length - 1 < buffer.length; i++) {

img_4071

@daniel-bolanos
Copy link

I'm not sure this change is correct. The first loop needs to iterate over the elements in the output buffer, since it is producing the output samples from the input samples. Also, are you sure i will be out of range?

@mingzhi22
Copy link
Contributor Author

image

I'm not sure this change is correct. The first loop needs to iterate over the elements in the output buffer, since it is producing the output samples from the input samples. Also, are you sure i will be out of range?

Hi @daniel-bolanos.

The capacity of outputBuffer is 1479, but i is 4076.

@mingzhi22
Copy link
Contributor Author

hi @dpopp07 @daniel-bolanos, here is my user-case. Download and run npm install && npm run build && npm start to start.

downsample.zip

@germanattanasio
Copy link
Contributor

@mingzhi22 sorry for the delay I didn't see your comment before.

@dpopp07 can you check if running the audio from @mingzhi22 you run in the out of bound exception?

@tomoyamachi
Copy link

@mingzhi22
I used webaudio-l16-stream to creating a WAVE file, but the file has some noises.
It becomes very clear sound when applied your PR patch.

Thanks!

Copy link
Contributor

@germanattanasio germanattanasio left a comment

Choose a reason for hiding this comment

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

After some digging, I think this looks good.

Sorry for the delay!

@dpopp07 dpopp07 merged commit 3d6c69d into watson-developer-cloud:master Mar 19, 2019
@watson-github-bot
Copy link

🎉 This PR is included in version 0.35.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Development

Successfully merging this pull request may close these issues.

7 participants