When musicians work with additive synthesis, they will often wrap envelopes around the sounds, and even around each added sine wave. An envelope changes the amplitude over time: It might start out small, then grow (rapidly or slowly), then hold at a certain value during the sound, and then drop before the sound ends. That kind of pattern is sometimes called the attack-sustain-decay (ASD) envelope. Pianos tend to attack quickly then decay quickly. Flutes tend to attack slowly and sustain as long as you want. Try implementing that for the sine and square wave generators.

What will be an ideal response?


```
/**
* Method to c r e a t e a piano sound from a s ine wave
* @param f r e q the f r e quenc y o f the sound wave
* @param maxAmplitude the maximum ampl i tude ( volume ) of the wave
*/
public s tat ic Sound createPianoSoundSineWave ( int f r eq , int maxAmplitude )
{
Sound sineWave = Sound . createSineWave ( f r eq , maxAmplitude ) ;
int l en = sineWave . getLength ( ) ;
sineWave . de c r eas eVolBe for e Index ( ( int ) ( l en * 0 . 2 ) , 1 0 ) ;
sineWave . de c r eas eVolAf t e r Index ( ( int ) ( l en * 0 . 8 ) , 1 0 ) ;
return sineWave ;
}
/**
* Method to c r e a t e a f l u t e sound from a s ine wave
* @param f r e q the f r e quenc y o f the sound wave
* @param maxAmplitude the maximum ampl i tude ( volume ) of the wave
*/
public s tat ic Sound createFluteSoundSineWave ( int f r eq , int maxAmplitude )
{
Sound sineWave = Sound . createSineWave ( f r eq , maxAmplitude ) ;
int l en = sineWave . getLength ( ) ;
sineWave . de c r eas eVolBe for e Index ( ( int ) ( l en * 0 . 5 ) , 1 0 ) ;
return sineWave ;
}
/**
* Method to modi fy a sound to s t a r t at lower v o l and inc r e a s e
* the volume l i n e a r l y in num s t e p s to the volume at the pas sed inde x
* @param inde x the inde x to s top the change at
* @param numSteps the number of s t e p s to inc r e a s e
*/
public void de c r eas eVolBe for e Index ( int index , int numSteps )
{
int l e n g t h I n t e r v a l = index / numSteps ;
int cur r Index = 0 ;
double increment = 1 . 0 / numSteps ;
double f a c t o r = increment ;
int value ;
for ( int j = 0 ; j < numSteps ; j++)
{
for ( int i = 0 ; i < l e n g t h I n t e r v a l ; i++)
{
cur r Index = j * l e n g t h I n t e r v a l + i ;
value = this . getSampleValueAt ( cur r Index ) ;
this . setSampleValueAt ( cur r Index , ( int ) ( value * f a c t o r ) ) ;
}
f a c t o r = f a c t o r + increment ;
}
}
/**
```

Computer Science & Information Technology

You might also like to view...

Case-Based Critical Thinking QuestionsCase 2-3Helen wants to create a Web site based on her famous cooking show. She would like to provide instructions on how to create some of her favorite dishes. She would like her recipes to be displayed in very simple, step-by-step pages. Overall, the entire Web site would have what type of structure?

A. linear B. mixed C. protected D. hierarchical

Computer Science & Information Technology

Which method is useful for scoring answer sheets for survey questionnaires?

A) data strips B) bar codes C) punch out forms D) mark sense forms E) MICR

Computer Science & Information Technology

Explain why the onion router prevents any intermediate node from knowing the true source and destination of communication

What will be an ideal response?

Computer Science & Information Technology

Critical Thinking QuestionsCase 3-1George runs a mid-size accounting practice and recently upgraded to Excel 2010. He expects sales to grow in the next few months during tax season. After that, he would like to begin upgrading some of the equipment and furniture for the employees in his office. He will start with the Reception area, which has the most visibility. In George's Sales Data worksheet, the result for a formula in cell H14 is ######. What should George do? a.increase the width of column Hc.run the calculation again to find the available valueb.provide a correct argument or operandd.replace the incorrect formula in cell H14 with one that does not divide by zero

What will be an ideal response?

Computer Science & Information Technology