Problem facing in Simon game

Problem facing in Simon game
0

#1

I have to use a error sound in my project. But I am not getting any direct link of audio file. So please tell me about a site from where I can directly use the sound.


#2

You could link to and use the sound clips provided in the problem statement.

var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3')

audio.play();

#3

Why is there no “error” sound included with the simon game challenge. Where does the error sound in the example come from?


#4

If you look at the source code of the example’s Codepen, you will see they are using an external library

https://raw.githubusercontent.com/shinnn/AudioContext-Polyfill/master/audiocontext-polyfill.js

then use the following code to create the error sound:

    var errOsc = audioCtx.createOscillator();
    errOsc.type = 'triangle';
    errOsc.frequency.value = 110;
    errOsc.start(0.0); //delay optional parameter is mandatory on Safari
    var errNode = audioCtx.createGain();
    errOsc.connect(errNode);
    errNode.gain.value = 0;
    errNode.connect(audioCtx.destination);

Ultimately, errNode is used in the following two functions:

    function playErrTone(){
      errNode.gain.linearRampToValueAtTime(vol, audioCtx.currentTime + ramp);
    };

    function stopErrTone(){
      errNode.gain.linearRampToValueAtTime(0, audioCtx.currentTime + ramp);
    };

which are used in the notifyError function which actually plays the error sound.