toneAC v1.2 - Twice the volume, higher quality, higher frequency, etc.

Example 4: Random sound

This is just a random. To make it random to the human ear, the frequency is not linear.
It can be used as startup-sound or to simulate that device is totally confused.
Set the volume to your own need.

// Random sound
// public domain

int i, j, frequency, volume, duration;

for( i=0; i<1000; i++)
{
  j = random (5, 60);
  frequency = j * j;
  volume = random(6, 11);
  toneAC( frequency, volume, 0, true);
  j = random( 1, 12);
  duration = j * j;
  delay( duration);
}
noToneAC();
  
delay(2000);

Example 5 : misuse of the toneAC library

The next example is able to generate noise sounds.
Both random functions are part of the delay. The random change in volume is needed for the noise.

// example of noise sounds with toneAC library
// public domain
//
// The lower and higher frequency define the sound.
//     300, 1500 : noise
//     340, 345   : computer noise
//     600, 14500 : rain drops noise

#define FREQUENCY_LOWER   300
#define FREQUENCY_HIGHER   1500
  
int i, frequency, volume;

for( i=0; i<10000; i++)
{
  volume = random(6, 11);
  frequency = random( FREQUENCY_LOWER, FREQUENCY_HIGHER);
  toneAC( frequency, volume, 0, true);
  delay(1);
}
noToneAC();
  
delay(2000);