Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Specifying basic sounds via JavaScript/HTML?

  • 24-04-2015 8:04pm
    #1
    Registered Users Posts: 2,003 ✭✭✭


    Greetings boardsCoders

    I’ve been teaching myself a little JavaScript, magpie-style, and I’m like a kid with a new toy :p (have made a few simple items).

    However I naively :o assumed that I’d be able to direct the soundcard to produce tones by simply specifying frequencies, amplitudes and durations, in analogy to control of colour on the screen via HTML specification. I now get the impression that I’d have to play separate pre-recorded/coded sound files – e.g. I found a site that allows download of sine/square wave wav files for chosen frequencies, but they’re about a quarter of a MG in size each, and I’d need a ton of them! :eek: Is there a simpler way to play with basic sounds?

    (I know there are already myriads of sophisticated synthesiser/music apps out there, but I don’t want to either use or compete with them – just to play with sound in a bottom-up way for my own amusement and possibly education. I’ve no other languages to speak of (yet), and know little (yet) about sound/music technicalities.)


Comments

  • Registered Users Posts: 5,999 ✭✭✭Talisman


    You have a few options:

    HTML5 has an <audio> element. Wikipedia has a list of the supported audio formats for each of the main browsers. It's easy to hook into the <audio> elements using JavaScript, see HTML5 Audio and JavaScript Control.

    SoundManager 2 is a JavaScript API with Flash fallback for browsers that don't support the HTML5 elements.

    Google created the Web Audio API which is supported by all the major browsers except Internet Explorer, see CanIuse.com for reference. Howler.js is a library that uses the Web Audio API by default and falls back to HTML5 Audio.


  • Registered Users Posts: 2,003 ✭✭✭nomdeboardie


    Talisman wrote: »
    You have a few options:

    HTML5 has an <audio> element. Wikipedia has a list of the supported audio formats for each of the main browsers. It's easy to hook into the <audio> elements using JavaScript, see HTML5 Audio and JavaScript Control.

    SoundManager 2 is a JavaScript API with Flash fallback for browsers that don't support the HTML5 elements.

    Google created the Web Audio API which is supported by all the major browsers except Internet Explorer, see CanIuse.com for reference. Howler.js is a library that uses the Web Audio API by default and falls back to HTML5 Audio.
    Thanks Talisman - I will investigate these :)

    (I was aware of the <audio> element, but got the impression it was just used to control the playing of sound files(?))


  • Registered Users Posts: 5,999 ✭✭✭Talisman


    The <audio> element is used to embed the sound file in the HTML document. Each element represents a single audio channel, you can use JavaScript to clone elements in the DOM and so create additional audio channels. JavaScript can be used to dynamically load sounds into the elements and determine when to play each sound. The more channels you have the more sounds you can play in parallel.


Advertisement