EVR.Sound.Audio.Embed = function(container)
{
   EVR.Sound.Audio.call(this, container, "embed", "mp3");
   this.set_attributes();
}
EVR.Sound.Audio.Embed.prototype = new EVR.Sound.Audio;
EVR.Sound.Audio.Embed.prototype.set_attributes = function()
{
   this.element.setAttribute("loop", true);
   this.element.setAttribute("hidden", true);
   this.element.setAttribute("autostart", true);
}
EVR.Sound.Audio.Embed.prototype.toggle = function()
{
   if (this.attached)
   {
      this.remove();
   }
   else
   {
      this.append();
   }
}
EVR.Sound.Audio.Embed.prototype.set_song = function(name)
{
   EVR.Sound.Audio.prototype.set_song.call(this, name);
   if (this.attached)
   {
      this.remove();
      this.append();
   }
}
EVR.Sound.Audio.Embed.prototype.toString = function()
{
   return "[object EVR.Sound.Audio.Embed]";
}
EVR.include("sound/controls/button/Button.js");
EVR.Sound.Controls = function(container)
{
   EVR.Graphic.call(this, container, null, null, ALIGN_CENTER);
   this.set_proportions(SOUND_CONTROLS_WIDTH, SOUND_CONTROLS_HEIGHT);
   this.append();
   this.add_buttons();
}
EVR.Sound.Controls.prototype = new EVR.Graphic;
EVR.Sound.Controls.prototype.add_buttons = function()
{
   this.buttons = [
      new EVR.Sound.Controls.Button.Indicator(this),
      new EVR.Sound.Controls.Button.Volume.Amplify(this),
      new EVR.Sound.Controls.Button.Volume.Deamplify(this)
   ];
}
EVR.Sound.Controls.prototype.hide = function()
{
   var buttons = this.buttons;
   for (var ii = 0; ii < buttons.length; ii++)
   {
      buttons[ii].set_opacity(0);
   }
}
EVR.Sound.Controls.prototype.show = function()
{
   var buttons = this.buttons;
   for (var ii = 0; ii < buttons.length; ii++)
   {
      buttons[ii].set_opacity(SOUND_CONTROLS_UNFOCUSED_OPACITY);
   }
}
EVR.Sound.Controls.prototype.draw = function()
{
   EVR.Graphic.prototype.draw.call(this);
   if (!!this.buttons)
   {
      var buttons = this.buttons;
      for (var ii = 0; ii < buttons.length; ii++)
      {
	 buttons[ii].draw();
      }
   }
}
EVR.Sound.Controls.prototype.update = function()
{
   var buttons = this.buttons;
   for (var ii = 0; ii < buttons.length; ii++)
   {
      buttons[ii].update();
   }
   var prompt = this.container.prompt;
   if (prompt.attached)
   {
      prompt.remove();
   }
}
EVR.Sound.Controls.prototype.toString = function()
{
   return "[object EVR.Sound.Controls]";
}
EVR.include("sound/controls/button/Indicator.js");
EVR.include("sound/controls/button/volume/Volume.js");
EVR.Sound.Controls.Button = function(container, alignment, ratio)
{
   EVR.Graphic.call(this, container, ratio, null, alignment)
   this.focused = false;
   this.unfocused_opacity = SOUND_CONTROLS_UNFOCUSED_OPACITY;
   this.focused_opacity = SOUND_CONTROLS_FOUCUSED_OPACITY;
   this.add_listeners();
   this.set_opacity();
   container != null && (this.audio = container.container.audio);
}
EVR.Sound.Controls.Button.prototype = new EVR.Graphic;
EVR.Sound.Controls.Button.prototype.add_listeners = function()
{
   var current = this;
   this.element.onclick = function() { current.respond() };
   this.element.onmouseover = function() { current.focus() };
   this.element.onmouseout = function() { current.unfocus() };
}
EVR.Sound.Controls.Button.prototype.set_opacity = function(opacity)
{
   if (opacity != null)
   {
      this.unfocused_opacity = opacity;
   }
   var opacity;
   if (this.focused)
   {
      opacity = this.focused_opacity;
   }
   else
   {
      opacity = this.unfocused_opacity;
   }
   EVR.Graphic.prototype.set_opacity.call(this, opacity);
}
EVR.Sound.Controls.Button.prototype.respond = function()
{
   this.container.update();
}
EVR.Sound.Controls.Button.prototype.focus = function()
{
   this.focused = true;
   this.set_opacity();
}
EVR.Sound.Controls.Button.prototype.unfocus = function()
{
   this.focused = false;
   this.set_opacity();
}
EVR.Sound.Controls.Button.prototype.toString = function()
{
   return "[EVR.Sound.Controls.Button]";
}
EVR.Sound.Controls.Button.Indicator = function(container)
{
   EVR.Sound.Controls.Button.call(this, container, ALIGN_CENTER, RATIO_HEIGHT);
   this.border_width = SOUND_INDICATOR_BORDER_WIDTH;
   this.set_attributes();
   this.append();
}
EVR.Sound.Controls.Button.Indicator.prototype = new EVR.Sound.Controls.Button;
EVR.Sound.Controls.Button.Indicator.prototype.set_attributes = function()
{
   this.set_proportions(1, SOUND_ENABLE_SIZE);
   this.css.border = this.border_width + "px " + SOUND_INDICATOR_BORDER;
   this.set_color();
}
EVR.Sound.Controls.Button.Indicator.prototype.set_color = function()
{
   var color = SOUND_INDICATOR_INACTIVE_COLOR;
   if (!this.audio.muted)
   {
      color = SOUND_INDICATOR_ACTIVE_COLOR;
   }
   EVR.Sound.Controls.Button.prototype.set_color.call(this, color);
}
EVR.Sound.Controls.Button.Indicator.prototype.shape = function()
{
   EVR.Sound.Controls.Button.prototype.shape.call(this);
   if (!!!window.ActiveXObject)
   {
      var dimensions = this.get_dimensions();
      var offset = 4 * this.border_width;
      this.set_dimensions(dimensions[0] - offset, dimensions[1] - offset);
   }
}
EVR.Sound.Controls.Button.Indicator.prototype.respond = function()
{
   this.audio.mute();
   EVR.Sound.Controls.Button.prototype.respond.call(this);
}
EVR.Sound.Controls.Button.Indicator.prototype.update = function()
{
   this.set_color();
}
EVR.Sound.Controls.Button.Indicator.prototype.toString = function()
{
   return "[EVR.Sound.Controls.Button.Indicator]";
}
18.119.161.161
18.119.161.161
18.119.161.161
 
September 13, 2013

from array import array
from time import sleep

import pygame
from pygame.mixer import Sound, get_init, pre_init

class Note(Sound):

    def __init__(self, frequency, volume=.1):
        self.frequency = frequency
        Sound.__init__(self, self.build_samples())
        self.set_volume(volume)

    def build_samples(self):
        period = int(round(get_init()[0] / self.frequency))
        samples = array("h", [0] * period)
        amplitude = 2 ** (abs(get_init()[1]) - 1) - 1
        for time in xrange(period):
            if time < period / 2:
                samples[time] = amplitude
            else:
                samples[time] = -amplitude
        return samples

if __name__ == "__main__":
    pre_init(44100, -16, 1, 1024)
    pygame.init()
    Note(440).play(-1)
    sleep(5)

This program generates and plays a 440 Hz tone for 5 seconds. It can be extended to generate the spectrum of notes with a frequency table or the frequency formula. Because the rewards in Send are idealized ocean waves, they can also be represented as tones. Each level has a tone in its goal and a tone based on where the player's disc lands. Both play at the end of a level, sounding harmonic for a close shot and discordant for a near miss. The game can dynamically create these tones using the program as a basis.

I'm also building an algorithmically generated song: Silk Routes (Scissored). Here is an example of how it sounds so far.