CSE 8A Chapter 9.4-9.6: Lecture 18 Reading Assignment Notes

23 views2 pages

Document Summary

9. 4 reversing a sound public void reverse () Sound orig = new sound(this. getfilename()); int length = this. getlength(); for (int targetindex = 0, sourceindex = length-1; targetindex < length && sourceindex > 0; targetindex++, sourceindex) this. setsamplevalueat(targetindex, orig. getsamplevalueat(sourceindex)); The code above reverses the sound object that this is called on. First, we make a copy of the caller sound object in this method. Then, we loop through both the caller sound object and its copy (called orig) 9. 5 mirroring a sound public void mirrorfronttoback() int length = this. getlength(); int mirrorpoint = length / 2; int value = 0; for (int i = 0; i < mirrorpoint; i++) { value = this. getsamplevalueat(i); this. setsamplevalueat(length-1-i,value); This code mirrors a sound: extremely like mirroring a picture. First, we declare a mirror point of the sound. Then, we loop from 0 to the mirror point: we get the sample in the beginning and mirror it to the other side of the sound.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents