# C.14. Chapter 14

## C.14.1. Exercises

C.14.1.1. Implement a beep sound similar to the stereo beep at the beginning, but with a variable frequency (see Listing C.38). Make the frequency change very slowly between 220.0 and 660.0 to achieve a siren effect. If you want to keep the source simple, don't do different things for the left and right channels.
C.14.1.2. Complete the missing cases in the StereoBalanceControl module above. See Listings C.39 and C.40 for the answers.
C.14.1.3. Rewrite the stereo beep example in a way that the beeps are spinning in circles from the left channel to the right channel and back to the left channel. Listing C.41 highlights the code to do this.

C.14.1.1. Implement a beep sound similar to the stereo beep at the beginning, but with a variable frequency (see Listing C.38). Make the frequency change very slowly between 220.0 and 660.0 to achieve a siren effect. If you want to keep the source simple, don't do different things for the left and right channels.

Example C.38. Implementing a Beep Sound with Variable Frequency

 1  2 // exercise1.cc 3  4 #include "artsflow.h" 5 #include "connect.h" 6  7 using namespace Arts; 8  9  10 int main() 11 { 12  Dispatcher dispatcher; 13  14  Synth_FREQUENCY freq1,freqmod; // object creation 15  Synth_WAVE_SIN sin1,sinmod; 16  Synth_MUL mulmod; 17  Synth_ADD addmod; 18  Synth_PLAY play; 19  20  // the modulation frequency 21  setValue(freqmod, 0.3); 22  connect(freqmod, sinmod); 23  24  // bring it from the range [-1..1] to [-220..220] 25  setValue(mulmod,"invalue1",220.0); 26  connect(sinmod,mulmod,"invalue2"); 27  28  // add 440, to achieve the desired range: [220..660] 29  setValue(addmod,"invalue1",440.0); 30  connect(mulmod,addmod,"invalue2"); 31  32  // and use it as input for the beep generation 33  connect(addmod,freq1); 34  connect(freq1, sin1); // object connection 35  36  connect(sin1, play, "invalue_left"); 37  connect(sin1, play, "invalue_right"); 38  39  // start and go ;-) 40  freq1.start(); freqmod.start(); 41  sin1.start(); sinmod.start(); 42  addmod.start(); mulmod.start(); 43  play.start(); 44  dispatcher.run(); 45 } 46

C.14.1.2. Complete the missing cases in the StereoBalanceControl module above. See Listings C.39 and C.40 for the answers.

 1  2  case sbLeftOnly: 3  for(i=0;i

Example C.40. The Missing Cases in balance.cc

 1  2 if(strcmp(argv[1],leftonly) == 0) 3  bcontrol.balance(sbLeftOnly); 4 if(strcmp(argv[1],rightonly) == 0) 5  bcontrol.balance(sbRightOnly); 6 if(strcmp(argv[1],reverse) == 0) 7  bcontrol.balance(sbReverse); 8

C.14.1.3. Rewrite the stereo beep example in a way that the beeps are spinning in circles from the left channel to the right channel and back to the left channel. Listing C.41 highlights the code to do this.