Copyright © 2008-2019 MultiMedia Soft

How to generate wave tones, noises, DTMF tones and text to speech

Previous pageReturn to chapter overviewNext page

Apart from loading and editing sound files, Active Sound Editor allows generating several kinds of sound from scratch:

 

Pure wave tones

Monaural, Binaural and other composite wave tones

Sliding wave tones

Noises

DTMF tones

Text to speech

 

 

 

Pure wave tones

 

A pure wave tone is typically a tone with a sinusoidal waveform having an amplitude and a frequency. The component allows creating sinusoidal, square, sawtooth and triangular waveforms through the SoundGenerator.WaveToneGenerate method;  this method creates and loads into the editor a mono, stereo or multi-channel (up to 7.1) wave tone having a given duration and a fixed amplitude and frequency.

 

 

Monaural, Binaural and other composite wave tones

 

Pure wave tones described in the previous section can be combined together to create more complex waveforms; in order to create a composite waveform you need to establish the sample rate and the number of channels of the audio stream through the SoundGenerator.CompositeWaveTonePrepare method.

 

After this step, you can start adding pure wave tones through the SoundGenerator.CompositeWaveToneAddNewWaveTone method; there is no limitation to the number of wave tones you can add to the composite wave tone and each pure wave tone can be placed at a given offset respect to the beginning of the audio stream and on a specific channel; typical composite wave tones that can be created through this feature are the following:

 

Binaural wave tones are produced when two pure wave tones, having different frequencies, combine directly in the brain of the listener and are produced by sending two different pure wave tones, having different frequencies, to two different channels of the audio stream. Below a couple of code snippets which show how to create a binaural stereo waveform.

 

Visual Basic 6

 

' prepare the audio stream to compose (44100, stereo)

ActiveSoundEditor1.SoundGenerator.CompositeWaveTonePrepare 44100, 2

 

Dim nChannel as Integer

 

' add the first 3 seconds long sine tone on left channel of the stream (400 hz on channel 0)

nChannel = 0

ActiveSoundEditor1.SoundGenerator.CompositeWaveToneAddNewWaveTone SOUNDGEN_WAVE_TYPE_SINE, 400, 1, 3000, 0, nChannel

 

' add the second 3 seconds long sine tone on right channel of the stream (480 hz on channel 1)

ActiveSoundEditor1.SoundGenerator.CompositeWaveToneAddNewWaveTone SOUNDGEN_WAVE_TYPE_SINE, 480, 1, 3000, 0, nChannel+1

 

' generate the audio stream with a small fade of 10 ms and load it into the editor

ActiveSoundEditor1.SoundGenerator.CompositeWaveToneGenerate 10, 10

 

 

Visual C++

 

// prepare the audio stream to compose (44100, stereo)

m_editor1.GetSoundGenerator().CompositeWaveTonePrepare (44100, 2);

 

// add the first 3 seconds long sine tone on left channel of the stream (400 hz on channel 0)

int nChannel = 0;

m_editor1.GetSoundGenerator().CompositeWaveToneAddNewWaveTone (SOUNDGEN_WAVE_TYPE_SINE, 400, 1.0f, 3000, 0, nChannel);

 

// add the second 3 seconds long sine tone on right channel of the stream (480 hz on channel 1)

m_editor1.GetSoundGenerator().CompositeWaveToneAddNewWaveTone (SOUNDGEN_WAVE_TYPE_SINE, 480, 1.0f, 3000, 0, nChannel+1);

 

// generate the audio stream with a small fade of 10 ms and load it into the editor

m_editor1.GetSoundGenerator().CompositeWaveToneGenerate (10, 10);

 

 

Monaural wave tones are produced when two or more pure wave tones, having different frequencies, combine digitally or naturally before the sounds reach the ears, as opposed to combining in the brain like binaural wave tones. The component allows creating composite wave tones with more than two pure wave tones combined together by adding, always on the same channel, two or more pure wave tones, each having its own frequency and amplitude. Below a couple of code snippets which show how to create a monaural stereo waveform.

 

Visual Basic 6

 

' prepare the audio stream to compose (44100, stereo)

ActiveSoundEditor1.SoundGenerator.CompositeWaveTonePrepare 44100, 2

 

' loop on the two channels (left and right)

Dim nChannel as Integer

For nChannel = 0 To 1

   ' add a 3 seconds long 400 hz sine tone on the current channel

   ActiveSoundEditor1.SoundGenerator.CompositeWaveToneAddNewWaveTone SOUNDGEN_WAVE_TYPE_SINE, 400, 1, 3000, 0, nChannel

 

   ' add a 3 seconds long 480 hz sine tone on the current channel

   ActiveSoundEditor1.SoundGenerator.CompositeWaveToneAddNewWaveTone SOUNDGEN_WAVE_TYPE_SINE, 480, 1, 3000, 0, nChannel

Next nChannel

 

' generate the audio stream with a small fade of 10 ms and load it into the editor

ActiveSoundEditor1.SoundGenerator.CompositeWaveToneGenerate 10, 10

 

 

Visual C++

 

// prepare the audio stream to compose (44100, stereo)

m_editor1.GetSoundGenerator().CompositeWaveTonePrepare (44100, 2);

 

// loop on the two channels (left and right)

for (int nChannel = 0; nChannel < 2; nChannel++)

{

   // add a 3 seconds long 400 hz sine tone on the current channel

   m_editor1.GetSoundGenerator().CompositeWaveToneAddNewWaveTone (SOUNDGEN_WAVE_TYPE_SINE, 400, 1.0f, 3000, 0, nChannel);

 

   // add a 3 seconds long 480 hz sine tone on the current channel

   m_editor1.GetSoundGenerator().CompositeWaveToneAddNewWaveTone (SOUNDGEN_WAVE_TYPE_SINE, 480, 1.0f, 3000, 0, nChannel);

}

 

// generate the audio stream with a small fade of 10 ms and load it into the editor

m_editor1.GetSoundGenerator().CompositeWaveToneGenerate (10, 10);

 

 

As you can see inside the snippets above, once all of the needed pure wave tones have been added to the composite wave tone, this can be generated and loaded into the editor through a call to the SoundGenerator.CompositeWaveToneGenerate method.

 

 

Sliding wave tones

 

Sliding wave tones are obtained by dynamically modifying, during a given interval, the frequency and/or the amplitude of a pure wave tone. The component allows creating sinusoidal, square and sawtooth waveforms through the SoundGenerator.SlidingWaveToneGenerate method.

 

 

Noises

 

Noises are obtained by generating a random signal with a constant power spectral density. The component allows creating white, pink and brown noises through the SoundGenerator.NoiseGenerate method.

 

 

DTMF tones

 

DTMF (Dual Tone Multi Frequency) tones are used for telecommunication signaling over analog telephone lines in the voice-frequency band between telephone handsets and other communications devices and the switching center. The component allows creating DTMF tones through the SoundGenerator.DtmfStringGenerate method.

 

 

Text to speech

 

Text to speech is the artificial production of human speech and is obtained by leveraging the Microsoft's Speech API installed on Windows systems. Text is converted into an audio stream containing spoken voice through the usage of voices installed inside the system; the total number of voices installed inside the system can be obtained through the SpeechVoicesNumGet method while attributes of each single voice can be obtained through the SpeechVoiceAttributeGet method.

 

The component allows creating text to speech through the SoundGenerator.SpeechGenerateFromFile and SoundGenerator.SpeechGenerateFromString methods. The text file or the string of text may eventually contain XML markup: see the MSDN documentation for a tutorial about XML markup syntax.

 

 

A sample of generation of a multi-channel audio stream in Visual Basic 6 and Visual C++ can be found inside the following sample installed with the product's setup package:

- SoundEditor