akofman / cordova-plugin-dbmeter

:microphone::mega: Cordova plugin to get decibels from the microphone
Apache License 2.0
34 stars 29 forks source link

iOS: calling DBMeter.start multiple times results in -70db #15

Open nexorianus opened 5 years ago

nexorianus commented 5 years ago

When calling DBMeter.start() multiple times (accidentally or on purpose) the resulting dB value will always be -70.

I would suggest, throwing an error, on multiple starts.

My setup was:

const dummy = {
  dB: 0,
  isListening: false,
  startMeter() {
    const $this = this;
    setInterval(() => {
      if (!this.paused) {
        if (!this.isListening) {
          DBMeter.isListening((isListening) => {
            this.isListening = isListening;
            if (!isListening) {
              DBMeter.start(_.throttle($this.recordMeter, 100), $this.errorLog);
            }
          }, $this.errorLog);
          return;
        }
        // update stuff with this.db
      }
    }, 100);
  },
  recordMeter(dB) {
    this.dB = dB;
  },
  errorLog(e) { 
    // log
  }
};

On iOS the first few intervals DBMeter.isListening() passes false so i told the system to start again. After like 0.3 to 1 second DBMeter.isListening() passes true.