Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Questions on HW3-Spring2006

Questions about making the turtles dance? Or playing sound and music? Or generating synchrony?

Ask 'em here!


How exactly would you like this movie played? Are we talking drawing on a world? A Canvas? A Frame Sequence?
I don't know what you need to make a movie out of our file...

Also, "Your name and GT-email address" – Probably a very silly question, but we only have to put this once in the class file, right? And not in every comment?

Yes, the comment just goes in once at the top. Draw on a World. I can make a movie out of it – see Gallery HW3: Turtle Dance-Sp06. Mark Guzdial


Okay - I have a strange problem ... well a couple of them - the first one I had that I gave up on, was when I mixed 2 sounds that played fine on their own - I couldn't hear anything until I changed the ration value to like 100 -and then it was all chipmunk sounding. The second problem, that I'd really like to fix - is that I have a sound playing and I have a for loop for the turtles moving - and to get them to pause instead of just going crazy, I have a sound going sound.blockingPlay() inside the for loop. It works fine - until the original sound is done playing... then the blocking play song just keeps going and going and my turtles just keep going and going...

Edit - OO!!!! So I solved the second problem. :):), but I would still like help with the first problem, pleeeease!!!


Okay... So I am working on adding a bit of jMusic into my code... and I am wondering - how do we make it just play it?? All of my notes that I can find have us "view.notate"-ing it, and then you have to play it from inside of that... but is there a way that we can just play it?? I know there must be, but I can't find it.. Saaaaddd...

What class does .blockingPlay() come from? and World? I keep getting the 'cannot resolve symbol' error. Also, how do you import classes like Turtle.java? The last homework I just assumed the TA would compile the other nessecary classes in DrJava.

The "ration value"? Okay, let's take this from the top:
  • If the blockingPlay sound just keeps going, then change your loop around it.
  • To just play it – go see the Homework page and see the hints there. (Remember: That's extra credit. It's going to take some digging on your part.
  • blockingPlay comes from SimpleSound. World is a class. If you have your Preferences set right, Turtle.java should be immediately accessible without an import.
Mark Guzdial

DrJava dosn't want to recognize blockingPlay. Play.midi(sound, null) works fine, and I assume that blockingPlay.midi(sound, null) would work in the same way. Is there somthing I'm not understanding?

Oh! I meant the ratio value.. You know you put in the sound that you want to mix and then the ratio for it to play at?? well.. that's what I meant.. it's bizzare...

Have you compiled SimpleSound yet? Mark Guzdial

For those who didn't make it to class today, Jennifer's question above (about ratio's) is because she had a CD-quality sound (sampled at 44Khz), mixed with our sounds which are sampled at 22Khz.
For those brave souls trying to use JMusic for HW3, be sure to read at http://jmusic.ci.qut.edu.au/jmDocumentation/jm/util/Play.html – that explains the Play class. You'll particularly want to pay attention to (a) the false second parameter to the midi method that keeps the program from crashing and (b) the waitCycle method. Think about it this way: When you play MIDI, it plays in parallel (technically, "in a separate thread") to your turtle drawing. It's just like using someSound.play(). How do you synchronize with MIDI? Well, after drawing (which takes almost zero time), you need to get your drawing thread to wait for the music. How do you do that? With sounds, we'd say someSound.blockingPlay(). In JMusic, you use waitCycle(someScore) which will make your drawing thread sleep (wait) for awhile – long enough to play the score. If the score is about as long as the piece you're playing, the turtles will wait until the current piece is done. Then you play the next piece and do the next drawing, and wait until the piece is done. And so on. Make sense? Mark Guzdial

Some of you may be thinking, "Hey, it's not fair that I can't use JMusic for the extra credit, just because I don't read music or know how to compose music!" First response: Nobody said that the music had to sound GOOD. Just play SOME notes, and you get the extra credit. Second response: Here's the cheater's way to compose music: Just use C, E, and G in different octaves. Those three notes make up what's called a C major chord. It won't sound exciting to just use those three notes (see First Response), but it'll never sound bad. (It's the computational equivalent of three-chord rock-n-roll. :-) Mark Guzdial


BTW, you don't have to use waitCycle to get your drawing to pause while using JMusic. sound.blockingPlay() should work just as well to get some pauses in your drawing, so that you can synchronize with the music. Mark Guzdial

I know this is a stupid question, but how have people gotten the turtles to changes colors/move. I tried Turtle.java and I can't even get a turtle "icon" picture to show up.
Look in SimpleTurtle. Mark Guzdial

So, to make the turtles dance and have the sound play at the same time, which class/method needs to go first? I have both of them written up, but for some reason only one or the other will actually happen when the program is run.
You need to interleave. Typically you'll start a sound.play(), then move the turtles with sound.blockingPlay() interleaved (e.g., in the loop). Mark Guzdial

Okay... so I tried scaling the sounds different.. and I can't hear anything. They seem to only play in their original form no matter what I do - unless I have them at chipmunk speed when they're mixed... I think I might just decide to cut that out of my plan... ~Jennifer
If you send the sounds to me, I can scaled them down to the right sampling rate and mail them back to you. Mark Guzdial



Link to this Page