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

✨ Supports -s and -l to specify starting point and length in seconds to be rendered. (for making a preview, etc.) #5

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

Conversation

5argon
Copy link

@5argon 5argon commented Oct 28, 2017

A feature to prepare for newer BMS players that supports pre-rendered preview e.g. beatoraja

Problems : libsndfile produces a .wav with bad header. The file plays correctly in audio player but beatoraja 0.5.1 plays the preview with high frequency artifacts. sox output.wav output2.wav fixes the problem and sox will says sox WARN wav: wave header missing extended part of fmt chunk.

@5argon
Copy link
Author

5argon commented Dec 23, 2017

Now it seems beatoraja can play the preview file with sox WARN wav: wave header missing extended part of fmt chunk properly, but to fix the header anyways it is because libsndfile outputs a wav file that does not have an extended part.

According to this website non-PCM must have an extended part. We are using an IEEE floating format 03 but libsndfile outputs a file with fmt chunk size as 16, meaning that it won't have a room for extension size field cbSize which can be 00 00 but must be present. We can change the chunk size to 18, add the cbSize field as 00 00, and finally add +2 to the overall chunk size with codes like this.

  let outWav = fs.readFileSync(outfilepath) // Read back the output from libsndfile

  const chunkSize = outWav.readInt32LE(4)
  outWav.writeInt32LE(chunkSize + 2, 4) // Increase overall size by 2 bytes for the extension field
  outWav.writeInt32LE(18, 16) // To add extension field chunk size should be 18. It is on position 16

  let modifiedWav = Buffer.alloc(outWav.length + 2) // Initialize as all 0
  outWav.copy(modifiedWav,0,0,36) // Stops at before extension size (cbSize)
  outWav.copy(modifiedWav,38,36) // Left the extension field as 00 00 and copy the rest
  fs.writeFileSync(outfilepath,modifiedWav);

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.

None yet

1 participant