aolsenjazz / libsamplerate-js

Resample audio in node or browser using a web assembly port of libsamplerate.
Other
32 stars 10 forks source link

Sync changing of sample rate #8

Closed jscheid closed 3 years ago

jscheid commented 3 years ago

Could the call to new SRC somehow be moved out of the promise, so that different sample rates can be chosen without needlessly having to resolve a promise?

aolsenjazz commented 3 years ago

It sounds like you want to be able to do something like this?

// ... create SRC object with sample rate 44.1k
src.simple(data); // or full 

src.outputSampleRate = 48000;

src.simple(data); // or full 

Is this correct?

jscheid commented 3 years ago

Yes, something like that would be ideal.

aolsenjazz commented 3 years ago

Cool. Seems like the easiest way to do this would be to add a setter to the js src object which just calls destroy() + init() on the WASM module.

If you're comfortable doing this, please open a pr! otherwise, I can look into it in the next week or two.

jscheid commented 3 years ago

I've worked around it like so: https://gist.github.com/jscheid/0fe0ca86dbecc7a4efb65a604284d1c1

It's a hack but it does work, feel free to close this.

aolsenjazz commented 3 years ago

Seems like a feature worth having. Will add within the next week or two.

jscheid commented 3 years ago

The other useful improvement would be a way to process multiple streams in parallel (with the full API). This doesn't currently work (efficiently) because there's only a single SRC_STATE per wasm instance.

aolsenjazz commented 3 years ago

Interesting. Curious to see how you would want this used. For organization, would you open a new issue with a bit more detail?

aolsenjazz commented 3 years ago

Added support for updating input and output sample rates in 1c90c7e918e1c4a9908f99e94a0cc80de0329bf0

jscheid commented 3 years ago

Thanks!

aolsenjazz commented 3 years ago

Happy to!