@extends('template') @section('title') Wavesynth Sounds @stop @section('head') @stop @section('content') # Lab 1: Sounds with Wavesynth ## Exploring `wavesynth` **For this part of the lab, work through as many steps as you have time for. We don't expect you to get all the way to the end!**
To explore more of the possibilities of the `wavesynth` library we can make a simple melody. Below is one possibility. You and your partner have creative freedom in this task. The goal is to learn how to arrange notes and beats; their precise pitches/volumes/durations are up to you.
## Reference When working with `wavesynth`, [our quick-reference page](/reference/quickref#wavesynth) provides a description of the key concepts and an overview of the functions available. You don't need to read through it all now, but you can refer back to it when you have questions about how something works. ## Step 0: Start a new file and imports For this task, **create a new file** named `tune.py` (make sure to save it in your `lab01` folder where `wavesynth.py` is, or else importing `wavesynth` will not work). As we did in the previous part, we'll need to import `wavesynth` to use music commands. At the top of your new file, start with a comment indicating your names and the purpose of the file, and then add code to import those libraries, like this: ```py # Authors: Peter and Sohie # Purpose: CS 111 lab 1 musical tune from wavesynth import * ``` ## Step 1: Add some notes Use the [`addNote`](/reference/quickref#addNote) function a few times to add a few notes to your song. Use [`climbUp`](/reference/quickref#climbUp) and/or [`climbDown`](/reference/quickref#climbDown) in between to control the pitch of each note. You can use [`setPitch`](/reference/quickref#setPitch) beforehand to pick a starting pitch.For example, here's a melody with four 1/4 second notes, which go up one step, up one more step, and then back down to the starting pitch (C4):
To get your song to play (and save it), you'll also need to add these lines of code to the end of your file: ```py saveTrack("melody.wav") playTrack() ``` ## Step 2: Add some beats To make our melody sound nicer, we can add some drum beats in time with the notes. First, use [`rewind`](/reference/quickref#rewind) to back up to the beginning of the song, and then use [`addBeat`](/reference/quickref#addBeat) and/or [`addRest`](/reference/quickref#addRest) to add some beats that happen at the same time as some of the notes. You may want to use [`quieter`](/reference/quickref#quieter) to make the beats a bit quieter than the notes.Here's the same tune with beats on the first and third notes:
## Step 3: Add a chord For a finishing touch, we can add a chord to compliment the melody. A chord is when multiple notes are played at once, and these often last longer than individual notes of a melody. You can try different things, but we've added a chord of three 1-second notes that play together, at the same time as the four melody notes play in sequence. To do this, we rewound to the beginning, then added one note of the chord, then rewound again, added the second note, and finally rewound a third time and added the last note. To create a nice-sounding chord, you can start by picking a pitch that's one octave below your first note. In this case, we used C4 for the first note of the melody, we use `setPitch(C3)` to set the base pitch of the chord one octave below that. For a "major" chord (which sounds "bright" or "cheerful") we can set the pitches using half-steps: four half steps between the first two notes, and three between the second and third notes. The [`halfStepUp`](/reference/quickref#halfStepUp) function lets us change pitch in half-step increments.Here's what the result sounds like (feel free to ask for help figuring out how to get this working with code).
## Step 4: Continue If you've gotten this far and there's still time left, you've figured out all of the basics of `wavesynth`, but feel free to experiment further, and if you want, make your tune longer. Just remember to keep track of how far to `rewind` if you start adding notes to the melody. You may want to use [`setTime`](/reference/quickref#setTime) instead in some cases, which jumps to a particular point in time. @include('/labs/lab01/_toc') @stop