CSE 203 Closed Lab 9 Instructions
Table of Contents
1. Objectives
To practice using sound in a program, and to see how
ClearRectangle() and PrintInRectangle() work together.
2. Set Up
- Two students should work together at one workstation.
- In one student's account, follow the instructions given
below in section 3, Method. Remember, trading roles (driver and
non-driver) for each new session is a very good
idea.
3. Method
- From the File menu in Phrogram, select New Program (or click the
same icon in the toolbar to Create a new program).
- Change the program's name to Sound_Test.
- Put date and author information in comments at the top of the
program.
- Type the following two statements inside the Main method:
Define Test_Sound As Sound
Test_Sound.LoadFile( "eerie.wav" )
Test_Sound.Play()
- From the File menu, select Save (or click the same icon in the
toolbar to Save the active program) and save the program in folder 0)
My Own.
- Get a "splitter" from a proctor, plug it in, and plug your
headphones in. The proctor has extra headphones if you need to
borrow them.
- Run the program.
- You didn't hear a sound. That's because the program stopped
running immediately after it began playing the sound. The program
can't play a sound when it's not running, and computers are so fast
that we couldn't even hear the beginning of the sound before the
program stopped running. Close the window of the stopped program.
- We can cause the program to keep running with a call to
Delay(). Let's delay for eight seconds. After
"Test_Sound.Play()", type the following statement:
Delay( 8000 )
- Now run the program. You can hear the sound play for five
seconds followed by a couple of clicks, which are an (undesirable)
artifact of Phrogram's sound-playing behavior, and about three seconds
of silence. (Close the window of the stopped program.)
- Now change "Test_Sound.Play()" to "Test_Sound.PlayLoop()", and
run the program. You can hear the sound play for five seconds, then
immediately start over, playing just the first three seconds of the
sound a second time. PlayLoop() plays the sound over and over
again until it is stopped or the program stops. (Close the window
of the stopped program.)
- Two or more sounds can be played simultaneously. Add the
following definition and call to LoadFile() to the beginning of the
Main method:
Define Second_Sound As Sound
Second_Sound.LoadFile( "SpatialShift.wav" )
- Now change PlayLoop() back to Play(), change the 8000 millisecond
delay to a 2000 millisecond delay, and add a Play() for Second_Sound
and a 5000 millisecond delay, so that the body of the Main method
becomes:
Define Second_Sound As Sound
Second_Sound.LoadFile( "SpatialShift.wav" )
Define Test_Sound As Sound
Test_Sound.LoadFile( "eerie.wav" )
Test_Sound.Play()
Delay( 2000 )
Second_Sound.Play()
Delay( 5000 )
- Run the program. You can hear SpatialShift play while eerie
is playing. (Close the window of the stopped program.)
- You can make that last delay longer, say 15000 milliseconds, and
change both calls to Play() to calls to PlayLoop() to hear both of
these sounds play over and over together. Try it!
- Of course, we usually don't use such long delays when augmenting
interactions with sound. The file,
LOGO_Style_Sprites_W_Sound_N_Msg.kpl plays a
sound, yet has
only a 15 millisecond delay in its main event loop to keep the program
slow enough. From the Week05 folder in the OSU folder, open and
examine file
LOGO_Style_Sprites_W_Sound_N_Msg.kpl to see
how it starts and stops the sound.
- Notice that this program has defined a Boolean object
Turn_Sound_Stopped. A Boolean object can have either of two
values: True or False. The object Turn_Sound_Stopped remembers
for us whether it is true that the turn sound has been stopped.
- Also notice that, rather strangely, a call to Stop() unloads the
sound from the Sound object! That's bad, but we can overcome this
problem by getting in the habit of always calling LoadFile()
immediately after calling Stop().
- You may also want to notice how this program uses three
rectangles to display the rotation message. Because "Rotation:"
and "degrees" only need to be printed to the screen once at the
beginning of the program, they each have their own separate
rectangle. This approach also keeps "degrees" from sliding
rapidly back and forth as the number of digits of the degree measure
changes. The degree measure is printed in its own rectangle each
time through the main event loop.
- If you have time, think about your course project. Consider
whether you want to have sound and/or printed rectangles in your course
project, and, if so, take the initial steps toward doing so.
4. Proctor Help
If you have a question or get stuck,
raise your hand and one of the proctors will come by to chat.