scot.butzbach.net

Projects

If you want to view the old layout of the website, press the first button below.

Projects

JavaScript Audio

License: MIT
Plays sounds using the Web Audio API.

Note: Code markup displayed here is formatted with Prism.


How to Use

In your HTML file, import the script with the following tag:

<script src="https://scot.butzbach.net/projects/javascript_audio/audio.js"></script>

With this file imported, you can use the two provided functions:

playSound(freq, gain, duration);

Plays a sine wave.

  • freq: The frequency of the sine wave.
  • gain: The amplitude of the sine wave.
  • duration: The duration (in seconds) of the sine wave.

playNote(note, octave, gain, duration);

Plays a sine wave at a specific note.

  • note: The note to play (see below).
  • octave: The level of the note (1-8).
  • gain: The volume of the note.
  • duration: The duration (in seconds) of the note.

The notes to choose from are:

  • C
  • C# (Cs)
  • D
  • D# (Ds)
  • E
  • F
  • F# (Fs)
  • G
  • G# (Gs)
  • A
  • A# (As)
  • B

Note: Use the notes in parenthesis (if given) for the function. Otherwise, it will not work.


License

MIT License

Copyright (c) 2021 Scot Butzbach

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.