Rewrite the Program so that you normalize the first second of a sound, then slowly decrease the sound in steps of 1=5 for each following second. (How many samples are in a second? getSamplingRate() is the number of samples per second for the given sound.)
What will be an ideal response?
```
public void changeVolume (double f a c t o r ,
int s t a r t ,
int end )
{
int value = 0 ;
for ( int i = s t a r t ; i < end ; i++)
{
value = this . getSampleValueAt ( i ) ;
this . setSampleValueAt ( i , ( int ) ( value ¤ f a c t o r ) ) ;
}
}
public void normal i z e ( int s t a r t , int end )
{
int max = s t a r t ;
int value = 0 ;
// loop from s t a r t to end l o o k i n g f o r the max
for ( int i = s t a r t ; i < end ; i++)
{
value = this . getSampleValueAt ( i ) ;
i f (Math . abs ( value ) > Math . abs (max) )
max = value ;
}
// determine the mu l t i p l i e r
double mu l t i p l i e r = 32767.0 / max ;
// change the volume by the mu l t i p l i e r
this . changeVolume ( mu l t i p l i e r , s t a rt , end ) ;
}
public void normSecThenDecrease ( )
{
int numInSec = ( int ) this . getSampl ingRate ( ) ;
double r educ t i on = 1 . 0 / 5 . 0 ;
double t o t a lReduc t i on = r educ t i on ;
int numSecs = this . getLength ( ) / numInSec ;
i f ( numSecs > 5)
numSecs = 5 ;
// normal i z e the f i r s t second
this . normal i z e ( 0 , numInSec ) ;
// loop changing the volume
for ( int i = 1 ; i < numSecs ; i++)
{
this . changeVolume ( 1 . 0 ¡ totalReduc t ion ,
i * numInSec ,
( i + 1)*numInSec ) ;
totalReduction = totalReduction + r eduction ;
}
}
```
You might also like to view...
When cropping an image, crop ________ appear to define the area to be removed
Fill in the blank(s) with correct word
A word flagged by Outlook using a wavy underline is a misspelled word.
Answer the following statement true (T) or false (F)