end (type: int): The ending index for the range of samples. This is non-inclusive. Returns: (type: int) The maximum left channel value in samples between the start and end indices. """ # initialize max value to left channel value in the first sample in the range first = my_sound[start] max_val = abs(first.left) # loop through all other samples in the range and keep track of the # largest left channel sample value. for i in range(start + 1, end): sample = my_sound[i] left_val = abs(sample.left) if (left_val > max_val): max_val = left_val return max_val # To Do: Define your set_extremes function below this line. jolly = sound.load_sound("jolly.wav") jolly.play() sound.wait_until_played() # waits until jolly is done playing jolly.display() # To Do: Add new test code after this line.
Exercises from lab 06, dealing with string accumualators. """ import sound def create_sound(sound_string): """ Function that uses sound_string to create a sound object. Each character is either a letter signifying a note (a, b, c, d, e, f, g, each could be upper or lower case), or a single digit number (1, 2, 3, 4, 5, 6, 7, 8, 9), or s to indicate a silent sound. The function should create and return a sound object consisting of the notes specified in the string (in the same order as they appear in the string.) Each note should be inserted into the sound object for one half second, and it should be at the default octave. If, however, the character before a note is a digit, then the note should appear for longer. For example, if the digit is 4, then the next note should be inserted with a length of 4 times one half second, or 2 seconds. """ return None # replace this when you're done. # Do not modify anything after this point. if __name__ == "__main__": snd = create_sound("3Eabcde2Sc2e2Sc2egacadca") snd.play() sound.wait_until_played()
""" Module: comp110_lab03 Practice code for working with sounds in Python. """ import sound love_sound = sound.load_sound("love.wav") love_sound.play() sound.wait_until_played() # waits until love_sound is done playing # change the volume of the love sound for i in range(len(love_sound)): sample = love_sound.get_sample(i) new_left_val = sample.get_left() * 2 new_right_val = sample.get_right() * 2 sample.set_left(new_left_val) sample.set_right(new_right_val) love_sound.play() sound.wait_until_played() # waits until love_sound is done playing