sb2702 / audioRecord.js

Easily record audio in the browser, export as WAV, MP3 or OGG
MIT License
57 stars 14 forks source link

How to record at 24 or 32 Bit? #5

Open hales548 opened 4 years ago

hales548 commented 4 years ago

How do you get the script to record at 24 or 32 bit?

sb2702 commented 4 years ago

It's been a few years since I've worked on this, so I'm not 100% sure this is the right fix, but I think you would need to replace

output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);

on line 199 of webworker.js with

output.setInt32(offset, s < 0 ? s * 0x80000000 : s * 0x7FFFFFFF, true);

in order to get 32bit output for WAV.

For MP3, you would need to replace the float32toInt function

with


  function float32ToInt(f32){

    return new Int32Array(f32);

  }

This should work, as it inputs 32 bit raw audio to the audio encoders (mp3/ogg etc..), but I don't know 100%, because the actual audio encoders all have different settings, and I didn't write the encoders myself, I just ported different audio encoding libraries and put them together, so you'd need to test that the audio encoders actually output 32 bit audio when you do this.

I can see if I can test this and put in a patch in the next month or so.

hales548 commented 4 years ago

Hi Sam

Many thanks for this. If you manage to put in a patch that would help.

All the best.