shukriadams / micVolume

Phonegap plugin for reading ambient noise level through microphone.
5 stars 10 forks source link

Uncaught ReferenceError: audioPoll is not defined #3

Open r0boto opened 9 years ago

r0boto commented 9 years ago

Hi, i tried to use plugin by this way:

 if(audioPoll != null) {

          function audioSuccessCallback() {
              audioPoll.read(function(reading){
                  alert(reading.volume);
              }, function(error){
                  alert("Microhpne error");
                  alert(error);
              });
          };

          function audioErrorCallback() {
              alert("Microhpne error");
          };

          setInterval(function(){
            audioPoll.start(audioSuccessCallback, audioErrorCallback);
          }, 100);

      } else {
          alert("Audio plugin is not defined");
      }

But it throwing this error: Uncaught ReferenceError: audioPoll is not defined

I checked that plugin is in list of installed plugins and i found it there:

com.shukriadams.micVolume 0.1.0 "MicVolume"

What can be wrong please?

aadon94 commented 8 years ago

r0boto did you get anywhere with this? I'm having the same issue.

aadon94 commented 8 years ago

change "audioPoll" to "micVolume"

shukriadams commented 8 years ago

sorry folks,I would love to be more active in this project but I am absolutely jampacked with work on other projects. If anyone wants to write a patch and pull request it, I'd be happy to comply. Best I can came up with right now : /

aadon94 commented 8 years ago

No problem man, I understand! I've got it working but may I ask if you can remember if the values it gave when you used it fluctuated quite a bit? It's definitely able to tell what's loud and what's quiet but the values can change by a value of up to roughly 10, without the ambient noise really changing.

shukriadams commented 8 years ago

This is the same problem that I've always had with it - it returns values, but the values are mostly random noise. You can make out general peaks or troughs that correspond with your room noise, but it's still all over the place.

My take on this was that either I was not initializing the AndroidRecord object properly, ie

new AudioRecord(src,freq,chan,enc,buflen);

was getting some incorrect src, encoding, freq etc, but trawling through the Android SDK documentation and examples I couldn't find any other way of doing this.

Or, I was polling incorrectly :

int bufferReadResult = audioRecord.read(buffer, 0, buffer.length);

I even put some kind of average-over-time on that to flatten out the noise, but it was still all over the place. I tried different buffer sizes (it's currently at 1024), but that didn't help either. Have you tried using a much larger (orders of mag) buffer size? Pretty much every example I've seen pegs buffer size at about 1024 though.