Sounds Framework

This framework is designed to make the usage of the speaker on the VBOX touch easier. It can be used to play set sounds for a length of time without disrupting the rest of your program. All the functions in this class are in the Speaker Singleton class.

To import the Speaker class simply use the code snippet below:

from sounds import Speaker
vbox_speaker = Speaker(128) # volume to start on. Defaults to 128 if no data entered.

Note

Speaker is a Singleton. There can only be one object of this class.

Set volume

Sets the current volume for sounds playing from the speaker. This can range from 0 to 255.

vbox_speaker.set_volume(volume)

There is also a function to mute a sound by setting the volume to be 0.

vbox_speaker.mute()

Playing a sound

To play a sounds you need to pass it the index of the sound you want it to play. This is done by using one of the attributes of the Speaker object.

For example if you want to play a click sound you do the following.

vbox_speaker.play_sound(vbox_speaker.snd_click)

The attributes that work with this are, the number they equal is their index in the vbox_speaker.sounds list:

  • snd_click = 0

  • snd_error = 1

  • snd_1s_beep = 2

  • snd_2s_beep = 3

  • snd_generic_beep = 4

Add a sound

Allows the user to add a sound from the preset sounds that already exist in the VBOX Touch which you can find here

vbox_speaker.add_sound(sound_name, sound)

Input Parameters:

  • sound_name[str] = the name you want to assign to your class attribute that stores the index of your sound in the sounds list

  • sound[list] = list containing your sound tuples

    • sound_tuple[tuple] = tuple containing the following:

      • time[int] = Time for sound to play for

      • sound[hex int] = Preset sound. This is based on the instruments/waves that can be found here

      • [OPTIONAL] note[int] = MIDI note that can be found to the right of the instruments.

      • [FURTHER OPTION] volume[int] = Volume for the sound to be played at.

Example:

piano_list = []
for x in range(108, 21, -1):
    piano_list.append((250, 0x46, x, 220))
vbox_speaker.add_sound("WELCOME", piano_list)
vbox_speaker.play_sound(vbox_speaker.WELCOME)

Other functions

There are other functions within the sounds class however these are designed for the play_sound function to use. So do not use:

  • vbox_speaker.sound_start(sl)

  • vbox_speaker.sound_cb()