chrisguttandin / extendable-media-recorder

An extendable drop-in replacement for the native MediaRecorder.
MIT License
258 stars 13 forks source link

recording sometimes introduces slight, temporary pitch shift? #682

Closed gregsadetsky closed 8 months ago

gregsadetsky commented 9 months ago

I am using extendable-media-recorder with extendable-media-recorder-wav-encoder -- thanks for these amazing libraries!

in one occurrence (see example .wav below), someone reported that a recording they made on my site (where I use these libraries) had a slight pitch shift during the record. it doesn't last very long (about a second) but is pretty audible.

pitch-shift-example.wav.zip

is this a known problem? I didn't find anything in the closed issues. is it possible that the media recording API will sometimes skip/miss some samples, and thus will "compress" the time and thus pitch shift the signal..?

I'm using Howler as the frontend media playing library.

thank you!

chrisguttandin commented 9 months ago

Hi @gregsadetsky, thanks a lot for reporting this. I've never seen or heard this bug before.

Is the sound that is being recorded coming from the microphone or from Howler? Which browser was used to make the recording? And how long did it take before the pitch shift appeared?

gregsadetsky commented 9 months ago

thank you for looking into this!

the sound being recorded was coming from Howler -- I did:

  let streamDest = Howler.ctx.createMediaStreamDestination();
  Howler.masterGain.connect(streamDest); // connect masterGain to destination

  // set up media recorder to record output
  let chunks = [];
  mediaRecorder = new MediaRecorder(streamDest.stream, {
    mimeType: "audio/wav",
  });

in the recording that was shared with me, the pitch shift started after 57 seconds. I don't have information re: which browser -- I'll ask and report back. I'm afraid that this issue might not be easy to reproduce, right..? thanks again!


EDIT: just heard from the person who encountered this that it happened in desktop Safari on a Mac

chrisguttandin commented 8 months ago

Ah, that's interesting. I'm currently working on an improved mechanism to record in Safari. Up to now an AudioWorklet is used internally. That means extendable-media-recorder manages an AudioContext internally, too. My gut feeling is that the AudioContext from Howler and the one from extendable-media-recorder may drift slightly over time and the browser tries to compensate for that by resampling the audio.

The problem I'm trying to solve with the improved mechanism is that Safari sometimes inserts silence. I ran countless tests while working on that. But I never experienced the pitch shift bug myself. Is that something that always appears for that user or was it a one time problem?

gregsadetsky commented 8 months ago

thanks again for looking into it / thinking about this issue! it was a one time problem so ... obviously difficult to diagnose / reproduce. I haven't heard from other people regarding this issue.

chrisguttandin commented 8 months ago

Okay, I will close it for now. Please feel free to open it again if you come across a way to reproduce it.