PreQuiz for 4March2005 Quiz
Consider the below addition to the class SoundTreeTest:
public class SoundTreeExample {
ScaleBranch scaledBranch; // Needed between methods
SoundBranch root;
public SoundBranch root(){return root;}
//Ignore setUp()
public void setUp2() {
FileChooser.setMediaPath("D:/cs1316/MediaSources/");
Sound clap = new Sound(FileChooser.getMediaPath("clap-q.wav"));
Sound chirp = new Sound(FileChooser.getMediaPath("chirp-2.wav"));
Sound rest = new Sound(FileChooser.getMediaPath("rest-1.wav"));
Sound snap = new Sound(FileChooser.getMediaPath("snap-tenth.wav"));
Sound clink = new Sound(FileChooser.getMediaPath("clink-tenth.wav"));
Sound clave = new Sound(FileChooser.getMediaPath("clave-twentieth.wav"));
Sound gong = new Sound(FileChooser.getMediaPath("gongb-2.wav"));
Sound guzdial = new Sound(FileChooser.getMediaPath("guzdial.wav"));
Sound is = new Sound(FileChooser.getMediaPath("is.wav"));
root = new SoundBranch();
SoundNode sn;
SoundBranch branch1 = new SoundBranch();
sn = new SoundNode(guzdial.append(is).append(snap));
branch1.addREMOVEDld(sn);
sn = new SoundNode(clink.append(snap).append(clave));
branch1.addREMOVEDld(sn);
sn = new SoundNode(guzdial.append(is).append(is));
branch1.addREMOVEDld(sn);
root.addREMOVEDld(branch1);
scaledBranch = new ScaleBranch(2.0);
sn = new SoundNode(clink.append(clave).append(gong));
scaledBranch.addREMOVEDld(sn);
sn = new SoundNode(rest.append(chirp).append(clap));
scaledBranch.addREMOVEDld(sn);
root.addREMOVEDld(scaledBranch);
scaledBranch = new ScaleBranch(0.5);
sn = new SoundNode(guzdial.append(is).append(gong));
scaledBranch.addREMOVEDld(sn);
root.addREMOVEDld(scaledBranch);
SoundBranch branch2 = new SoundBranch();
sn = new SoundNode(clap.append(clap).append(clave));
branch2.addREMOVEDld(sn);
sn = new SoundNode(snap.append(snap).append(clave));
branch2.addREMOVEDld(sn);
sn = new SoundNode(snap.append(snap).append(clave));
branch2.addREMOVEDld(sn);
root.addREMOVEDld(branch2);
root.playFromMeOn();
}
//Ignore the rest.
}
We'll execute this method like this:
> SoundTreeExample ste = new SoundTreeExample();
> ste.setUp2()
- Draw a diagram of what the nodes (branches, nodes, everything) connected to root will look like. Be sure to show what's contained in each node, and be sure to show what the child and next references point to – and distinguish between them.
- Describe the sound that we’ll hear.
Comments? Questions? Sample answers you'd like feedback on?
What's the significance of "public SoundBranch root(){return root;}"? I removed it and setUp2 played fine.
Hmmm...I typed in ste.root() and it returned a bunch of information on samples and next's
why do we use sound branches again? just to cluster sounds?
It's just a method for gaining access to the root outside the SoundTreeExample class – it's an accessor. We use SoundBranches to cluster sounds, and to apply operations (like scaling) to the children in the branch. A useful branch to build would be RepeatBranch that might repeat the children's sound a certain number of times. Mark Guzdial |
Links to this Page