quick exercise
play

Quick Exercise Write a Sound method named toThreeValues() that - PowerPoint PPT Presentation

Quick Exercise Write a Sound method named toThreeValues() that converts the sound to only three values: Quick Solution if ( value > threshold ) newValue = maximumValue; else if ( value < -threshold ) newValue = -maximumValue; else


  1. Quick Exercise Write a Sound method named toThreeValues() that converts the sound to only three values:

  2. Quick Solution if ( value > threshold ) newValue = maximumValue; else if ( value < -threshold ) newValue = -maximumValue; else newValue = 0; In image processing, we call this posterizing . In audio processing, we call it clipping .

  3. Alternate Solution for ( SoundSample s : this.getSamples() ) { int value = s.getValue(); ... s.setValue( newValue ); } A SoundSample in a Sound . is just like a Pixel in an Image .

  4. On Homework 4 • Reuse existing code. • Take small steps. • Make helper methods when you notice repetition. • Ask questions soon.

  5. My First Sound Clip I have a slight problem...

  6. Quick Exercise Why write two for loops in increaseAndDecrease() , instead of one for loop with an alternative action? for ( int i = 0; i < this.getLength(); i++ ) { value = this.getSampleValueAt(i); if ( i < half ) this.setSampleValueAt( i, value*2 ); else this.setSampleValueAt( i, value/2 ); } How many tests get run in the second version? In the first version?

  7. Quick Exercise How can we create a version of increaseAndDecrease() that rises linearly from the beginning to the middle and then falls linearly from the middle to the end?

  8. Upcoming Days WED Bring headphones to the lab. THU Finish reading Chapter 9. Begin work on Homework 5. TUE No class WED Lab as usual THU No class TUE Submit Homework 5. Read Chapter 10.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend