Hi,
You get to set the sampleRate in the audio context you use, for audio
worklets samplerate is read only,
```
typedef int EMSCRIPTEN_WEBAUDIO_T;
typedef struct EmscriptenWebAudioCreateAttributes
{
const char *latencyHint; // Specify one of "balanced",
"interactive" or "playback"
uint32_t sampleRate; // E.g. 44100 or 48000
} EmscriptenWebAudioCreateAttributes;
// Creates a new Web Audio AudioContext, and returns a handle to it.
EMSCRIPTEN_WEBAUDIO_T emscripten_create_audio_context(const
EmscriptenWebAudioCreateAttributes *options);
```
from system/include/emscripten/webaudio.h
you can also have it EM_ASM_INT{console.log(sampleRate)} or something
equivalent (check out
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html),
but you need to be careful and run this in the audio worklet scope not the
main one.
Hope it helps,
On Thu, Nov 21, 2024 at 11:19 PM Luis Torres <[email protected]> wrote:
> I'm following this nice tutorial to get an AudioWorklet going in C++:
>
> https://emscripten.org/docs/api_reference/wasm_audio_worklets.html
>
> But how do I figure out what the audio sample rate is? If I want to
> generate a tone in the audio callback, it will need to know the audio
> sample rate.
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/emscripten-discuss/981b4bd4-64c4-4747-8c09-6a63e9c69e3an%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/981b4bd4-64c4-4747-8c09-6a63e9c69e3an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/emscripten-discuss/CANLCay%3DKH6j25C75jKaHMiFs4E%2BtcoHv%2B%3DhzBQz2JWg0H-KDgQ%40mail.gmail.com.