qiuxiang / aubiojs

aubio for javascript, the real-time audio processing library
https://qiuxiang.github.io/aubiojs/
MIT License
137 stars 36 forks source link

Trying to use aubiojs to do pitch detection #12

Closed pm100 closed 2 years ago

pm100 commented 2 years ago

(I put this in your tuner project by mistake)

In index.html

<script src="https://unpkg.com/aubiojs"></script>

I have this in ts (ignore the name, this is not a worklet, it starts one , now that scriptnode is deprecated), using your .d.ts file

class PitchDetectWorklet {
    audioContext!: AudioContext;
    running: boolean = false;
    pitchWorklet!: AudioWorkletNode;
    cb: (note: number, freq: number) => void;
    options: PitchDetectOptions;
    stream!: MediaStream;
    aupitch!: Pitch;  <<<<==
    au!: Aubio; <<<< ====

and then

        this.au = await aubio();
        this.aupitch = new this.au.Pitch('default', 128 * (this.options.buffersize || 10), 1, this.audioContext.sampleRate );

this all works fine.

But then when I get a buffer from my worklet I do

            var buff = ev.data.buff;
            var freq = that.aupitch.do(buff);

I always get

  Uncaught RuntimeError: null function or function signature mismatch
at 00068a0a:0x15c89
at 00068a0a:0xe02b
at Pitch$do [as do] (eval at Gb (aubiojs:38:242), <anonymous>:9:10)
at MessagePort.pitchWorklet.port.onmessage (worklet_caller.js:34:51)
I think I have copied everything from your tuner demo. I have run out of ideas

fails edge and chrome

chrome gives better debug stack

    local.get $var1
    i32.load offset=8
    local.get $var1
    i32.load offset=4
    local.get $var1
    i32.load offset=12
    i32.load offset=40
    call_indirect (param i32 i32 i32) <<<<<===== 15c89
    local.get $var1
    i32.load offset=8
    local.get $var1
    i32.load offset=12
    f32.load offset=52
    call $func92
    i32.const 1
    i32.eq
    if
      local.get $var1
      i32.load offset=4
      i32.load offset=4
      f32.const 0.0
pm100 commented 2 years ago

Solved, I was passing a buffer size that was not a power of 2