Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

"AudioContext was not allowed to start..." #2

Open
F0h opened this issue Jan 13, 2020 · 12 comments
Open

"AudioContext was not allowed to start..." #2

F0h opened this issue Jan 13, 2020 · 12 comments

Comments

@F0h
Copy link

F0h commented Jan 13, 2020

Hi Hlöðver.
Thank you for your project, I use Csound quite well but I'm new to web technology and would like to ask you if there is any way to resolve the warning "AudioContext was not allowed to start..."
The synthesizer that I'm implementing works very well in Brave, but not in Opera 66 or Chrome 79.
When I use it from a server it works.
I'm using Visual Studio Code and LiveServer
Regards!

@hlolli
Copy link
Owner

hlolli commented Jan 13, 2020

Hi @F0h, can you send me the console logs, I think this must be because you attempt to start making sounds without any user interaction. There's no way around it, you have to add a button or something. If it is what I think it is.

@F0h
Copy link
Author

F0h commented Jan 13, 2020

Hi hlolli, Thanks for your answer.
I use csound quite well but I am new to web technology.
Console return this warnings:
"The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu"
Yes I know user must trigger an event...
I would like to know what a button should trigger?
csound.startRealtime ()?
Is it necessary to write a promise?
Regards.

@hlolli
Copy link
Owner

hlolli commented Jan 13, 2020 via email

@hlolli
Copy link
Owner

hlolli commented Jan 14, 2020 via email

@F0h
Copy link
Author

F0h commented Jan 14, 2020

Oh ... I deleted my post because I was trying to find out how to add a Promise to startRealtime () ...
My code works perfectly in Brave, but in Opera, Chrome only works when I'm inside the Visual Studio Code with a server.
When I am with VSC and with server, MIDI and audio events work in perfect harmony and in real time.
But when I run the index.html from local ... warming appears and nothing works.

@F0h
Copy link
Author

F0h commented Jan 14, 2020

//This is my HelloCsound...
////////// CSD FILE ////////
const helloCsound =
`
;;;;;;; csd ;;;;;;;;;;;;;;


-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5


massign 0, 1 ;all MIDI channell for instrument 1
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1
kAEG madsr .01, .001, .8, .01 ;just a deClicked
a1 oscili p5 * kAEG , p4
outs a1 , a1
endin

;causes Csound to run for about 7000 years... ;Rory said f0 z

;;;;;;;;;;;;;;;;;;;;;;;;;
`

/////////// hlolli library ////////////////
csound.enableMidi();
csound.startRealtime();
csound.playCSD(helloCsound); // Use this or csound.realTime(CSD)
csound.inputMessage("i 1 0 .25 880 .1");

const updateCsound = () => {

// Ejemplo de uso de las funciones.
//El primer argumento es el canal que Csound leerá
//El segundo argumento es el valor del Elemento HTML
// csound.setControlChannel("wf1", SeleccionValueById("wf1") );
// csound.setControlChannel("swOsc1", checkboxIsChecked("swOsc1") );
// csound.setControlChannel("portTime1", portTime1 );

}
csound.on("perform", updateCsound);

@hlolli
Copy link
Owner

hlolli commented Jan 14, 2020

When you run index.html from local, are you refering to http://localhost:port or file:///home/index.html... ?

@F0h
Copy link
Author

F0h commented Jan 15, 2020

Yes. When I open file:///home/index.html..

@hlolli
Copy link
Owner

hlolli commented Jan 15, 2020

You may want to use something like https://www.npmjs.com/package/http-server when you are working on javascript locally. I think this is because of strict security around AudioWorklets that makes file:// protocol unavailable.

@hlolli
Copy link
Owner

hlolli commented Jan 15, 2020

But I'll keep you postet, I'll be making an overhaul on this project in next weeks. Maybe I can find a way or hack to make it work with file:// too.

@F0h
Copy link
Author

F0h commented Jan 15, 2020

thanks anyway.
Your project is very easy to use for newbies like me.
My purpose is to create small fragments of synthesizers so that my students can explore each of the voice modules of a typical synthesizer. (Oscillator, Oscillator + Filter, Oscillator + AEG, Oscillator + PitchEG, etc)
Create ear-training quiz for musicians related to synthesizers, etc.
Web technology avoids having to install programs and is supported by any operating system via navigators.
But I need to make sure it can work without the need for internet. That they can play it locally from any browser or any device.
I'm still on vacation and I know that if I do my part I can understand the version of dr. Lazarinni and Steven Yi ...
Your version is much more friendly for musicians, I must admit.
Regards!

@F0h
Copy link
Author

F0h commented Jan 21, 2020

Hello hlolli.
Here I commnit some examples. It works with Brave Brower but I cannot find what is the bug on Chrome and Opera:
https://f0h.github.io/csound-wasm-examples/01_minimal_w_MIDI/index.html: Simple HelloWorld with MIDI input in realtime
https://f0h.github.io/csound-wasm-examples/02_minimal_w_MIDi_Qwery/index.html MIDI and Qwerty
https://f0h.github.io/csound-wasm-examples/03_OW-SYNTH 1_2a_Brave/index.html this is simple oscillator.
Any advice will be well received and grateful.
Regards.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants