This task is part of project01 which is due at 23:00 EST on 2025-01-28.
You have the option to work with a partner on this task if you wish. Working with a partner requires more work to coordinate schedules, but if you work together and make sure that you are both understanding the code you write, you will make progress faster and learn more.
You can download the starter code for this task using this link.
You can submit this task using this link.
Put all of your work for this task into the file
tune.py
(you will create this file from scratch)
This task will help you practice writing basic code and will help you get
familiar with the wavesynth
library for creating music with Python.
The requirements are very simple, and in fact, there are no restrictions on what notes you create: the only rules are that you must make use of certain functions.
To start, you need to create a new file, named tune.py
. This file must
be in a folder where wavesynth.py
is also present. To create that file,
you should:
wavesynth.py
.Now you're ready to write code. Your tune.py
file must satisfy the
following criteria:
Your file must start with a triple-quoted string at the top, identifying the names of each author, which classmates and/or tutors and/or instructors you consulted for help, the last date you modified the file, and a brief description of the purpose of the file. We will do this for all files that you submit in this class. Here is an example:
py
"""
Authors: Anon & Ymous
Consulted: T. A.
Date: 2022-1-21
Purpose: Wavesynth tune task
"""
Your file must import
the wavesynth
module so that you can use
functions from it.
climbUp
, climbDown
,
halfStepUp
, or halfStepDown
to
change the current pitch between notes. For full credit, you must
both use at least one of climbUp
or
climbDown
and use at least
one of halfStepUp
or
halfStepDown
, and you must also
use setPitch
.setVolume
, quieter
, and/or
louder
functions to manipulate
the volume of one or more notes or beats.setTime
, rewind
, and/or
fastforward
functions to alter the
time at which some notes or beats are created.saveTack
function so that your program saves the music to a file. You may name
your saved file whatever you wish. As an extra goal, you may
also use the printTrack
function
to print out a record of the notes you created. Calling playTrack
is
not required, but if simpleaudio
can be installed on your system,
it's a faster way to hear the audio than opening up the saved file
each time.setDrum
and/or
setInstrument
functions to specify
the instrument or drum used to create notes. You can see the list of
available beat and note instruments in our quick
reference.You are welcome to use other wavesynth
features in addition to the ones
listed above, but only the above features are required.
If you want to challenge yourself and read ahead a little bit, consider defining a custom function and using it as part of your tune (but you will not receive any extra credit for this, so don't do it if you're short on time).
Reminder: If you want to hear sounds using playTrack
, you must install
the simpleaudio
module using the Package manager in the Thonny Tools
menu (search for simpleaudio
, select the result with that name, and
then click "install"). This may not work on some machines. If
simpleaudio
and thus playTrack
doesn't work for you, just use
saveTrack
to save as a .wav
file and then open that file after you
run your program.
Using wavesynth
Here's a brief reminder of how to use the wavesynth
functions. This
code creates a tune with three notes going up in pitch.
In []:Audiofrom wavesynth import * addNote(0.2) climbUp(1) addNote(0.2) climbUp(1) addNote(0.2) saveTrack('threeUp.wav') # playTrack() # Use this only if simpleaudio is working on your system
Layering sounds
Here's an example of how to use rewind
to layer sounds on top of each
other. This tune has two 1/2-second notes and two 1/4-second beats play
during each note. Remember that a quick reference
guide
is available that covers all of the wavesynth
functions we will use in
this class.
In []:Audiofrom wavesynth import * addNote(0.5) climbUp(2) addNote(0.5) rewind(1) addBeat(0.25) addBeat(0.25) addBeat(0.25) addBeat(0.25) saveTrack('layered.wav') # playTrack() # Use this only if simpleaudio is working on your system
addNote
addNote
in at least one place.addBeat
addBeat
in at least one place.climbUp
climbUp
, climbDown
, halfStepUp
, or halfStepDown
in at least one place.setVolume
setVolume
, quieter
, or louder
in at least one place.setTime
setTime
, rewind
, or fastforward
in at least one place.saveTrack
saveTrack
in at least one place.addRest
addRest
in at least one place.setPitch
setPitch
in at least one place.climbUp
climbUp
or climbDown
in at least one place.halfStepUp
halfStepUp
or halfStepDown
in at least one place.setDrum
setDrum
or setInstrument
in at least one place.printTrack
printTrack
in at least one place.