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 there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Specifying basic sounds via JavaScript/HTML?

  • 24-04-2015 7:04pm
    #1
    Registered Users, Registered Users 2 Posts: 2,061 ✭✭✭


    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, Registered Users 2 Posts: 6,289 ✭✭✭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, Registered Users 2 Posts: 2,061 ✭✭✭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, Registered Users 2 Posts: 6,289 ✭✭✭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