Copyright © 2001-2019 MultiMedia Soft

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

Previous pageReturn to chapter overviewNext page

Apart from playing music files, Active DJ Studio allows creating several kinds of sound:

 

Pure wave tones

Monaural, Binaural and multi-channel 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 in two ways:

 

Through the SoundGenerator.StreamCreateTone method.

 

This way creates on a specific player a mono or stereo wave tone having a given duration and a fixed amplitude and frequency: after invoking this method the wave tone can be played just in the same way used for regular sound files, PlaySound method for starting playback, StopSound method for stopping playback, StreamOutputSpeakerSet method for redirecting the audio flow to a given speaker and so on.

 

By creating an empty multi-channel (up to 7.1) audio stream on a specific player through the SoundGenerator.StreamCreateMultiChannelEmpty method and then by adding the pure wave tone, which is always a mono audio stream, to a specific channel of the stream through the SoundGenerator.StreamChannelAddTone method. if you should need to render the same wave tone on two speakers of the stream at the same time, you would simply need to make a further call to the SoundGenerator.StreamChannelAddTone method on a different channel of the stream. Once at least one element has been added, the multi-channel audio stream can be played just in the same way used for regular sound files.

 

The pure wave tone can be added to the multi-channel at a given offset and, once reproduced completely, is automatically removed from the audio stream: if you should need to repeat the wave tone, you would have to add it again to the stream with a new call to the SoundGenerator.StreamChannelAddTone method.

 

Differently from pure wave tones created through the SoundGenerator.StreamCreateTone method, pure wave tones added to a multi-channel audio stream can be endless, meaning that they can generate a sound flow without interruption for the whole duration of the multi-channel audio stream and can be modified during playback by changing the amplitude (through the SoundGenerator.StreamElementAmplitudeSet method) and/or the frequency (through the SoundGenerator.StreamElementToneFrequencySet method).

 

 

Monaural, Binaural and multi-channel wave tones

 

Pure wave tones described in the previous section can be combined together to create more complex waveforms:

 

Binaural wave tones are produced when two pure wave tones, having different frequencies, combine directly in the brain of the listener by sending two different pure wave tones, having different frequencies, to two different channels of the audio stream. Also in this case a binaural wave tone can be created by creating an empty multi-channel (up to 7.1) audio stream on a specific player through the SoundGenerator.StreamCreateMultiChannelEmpty method and then by adding, in this case on different channels, two or more pure wave tones, each having its own frequency and amplitude, through separate calls to the SoundGenerator.StreamChannelAddTone method. Below a couple of code snippets which show how to create a binaural stereo waveform.

 

Visual Basic 6

 

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

ActiveDjStudio1.SoundGenerator.StreamCreateMultiChannelEmpty Player_0, 44100, 2

 

Dim nDummyUniqueId As Long

 

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

Dim nSpeaker As Integer

nSpeaker = 0

ActiveDjStudio1.SoundGenerator.StreamChannelAddTone Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker, 400, 1, 3000, 0, nDummyUniqueId

 

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

ActiveDjStudio1.SoundGenerator.StreamChannelAddTone Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker+1, 480, 1, 3000, 0, nDummyUniqueId

 

' play the stream

ActiveDjStudio1.PlaySound Player_0

 

 

Visual C++

 

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

m_DjStudio1.GetSoundGenerator().StreamCreateMultiChannelEmpty (Player_0, 44100, 2);

 

long nDummyUniqueId;

 

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

int nSpeaker = 0;

m_DjStudio1.GetSoundGenerator().StreamChannelAddTone (Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker, 400, 1, 3000, 0, &nDummyUniqueId);

 

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

m_DjStudio1.GetSoundGenerator().StreamChannelAddTone (Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker+1, 480, 1, 3000, 0, &nDummyUniqueId);

 

// play the stream

m_DjStudio1.PlaySound (Player_0);

 

 

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 of the listener like binaural wave tones. The component allows creating composite wave tones with more than two pure wave tones combined together. In this case a monaural wave tone can be created by creating an empty multi-channel (up to 7.1) audio stream on a specific player through the SoundGenerator.StreamCreateMultiChannelEmpty method and then by adding, always on the same channel, two or more pure wave tones, each having its own frequency and amplitude, through separate calls to the SoundGenerator.StreamChannelAddTone method. Below a couple of code snippets which show how to create a monaural stereo waveform.

 

Visual Basic 6

 

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

ActiveDjStudio1.SoundGenerator.CompositeWaveTonePrepare Player_0, 44100, 2

 

' loop on the two channels (left and right)

Dim nSpeaker as Integer

For nSpeaker = 0 To 1

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

   ActiveDjStudio1.SoundGenerator.StreamChannelAddTone Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker, 400, 1, 3000, 0, nDummyUniqueId

 

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

   ActiveDjStudio1.SoundGenerator.StreamChannelAddTone Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker, 480, 1, 3000, 0, nDummyUniqueId

Next nSpeaker

 

' play the stream

ActiveDjStudio1.PlaySound Player_0

 

 

Visual C++

 

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

m_DjStudio1.GetSoundGenerator().StreamCreateMultiChannelEmpty (Player_0, 44100, 2);

 

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

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

{

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

   m_DjStudio1.GetSoundGenerator().StreamChannelAddTone (Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker, 400, 1.0f, 3000, 0, &nDummyUniqueId);

 

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

   m_DjStudio1.GetSoundGenerator().StreamChannelAddTone (Player_0, SOUNDGEN_WAVE_TYPE_SINE, nSpeaker, 480, 1.0f, 3000, 0, &nDummyUniqueId);

}

 

// play the stream

m_DjStudio1.PlaySound (Player_0);

 

 

In both cases, as seen for pure wave tones, after one or more tones have been added to the multi-channel audio stream, this can be played just in the same way used for regular sound files: PlaySound method for starting playback, StopSound method for stopping playback.

 

Each wave tone can be added to the multi-channel at a given offset and, once reproduced completely, is automatically removed from the audio stream: if you should need to repeat these composite wave tones, you would have to add them again to the stream with new calls to the SoundGenerator.StreamChannelAddTone method.

 

Also in this case pure wave tones added to a multi-channel audio stream can be endless, meaning that they can generate a sound flow without interruption for the whole duration of the multi-channel audio stream and can be modified during playback by changing the amplitude (through the SoundGenerator.StreamElementAmplitudeSet method) and/or the frequency (through the SoundGenerator.StreamElementToneFrequencySet 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 in two ways:

 

Through the SoundGenerator.StreamCreateSlidingTone method.

 

This way creates on a specific player a mono or stereo sliding wave tone having a given duration and a starting and ending amplitude and/or frequency: after invoking this method the sliding wave tone can be played just in the same way used for regular sound files, PlaySound method for starting playback, StopSound method for stopping playback, StreamOutputSpeakerSet method for redirecting the audio flow to a given speaker and so on.

 

By creating an empty multi-channel (up to 7.1) audio stream on a specific player through the SoundGenerator.StreamCreateMultiChannelEmpty method and then by adding the sliding wave tone, which is always a mono audio stream, to a specific channel of the stream through the SoundGenerator.StreamChannelAddSlidingTone method. if you should need to render the same sliding wave tone on two speakers of the stream at the same time, you would simply need to make a further call to the SoundGenerator.StreamChannelAddSlidingTone method on a different channel of the stream. Once at least one element has been added, the multi-channel audio stream can be played just in the same way used for regular sound files.

 

Also in this case each sliding wave tone can be added to the multi-channel at a given offset and, once reproduced completely, is automatically removed from the audio stream: if you should need to repeat the same sliding wave tone, you would have to add it again to the stream with new calls to the SoundGenerator.StreamChannelAddSlidingTone 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 in two ways:

 

Through the SoundGenerator.StreamCreateNoise method.

 

This way creates on a specific player a mono or stereo noise having a given duration and a fixed amplitude: after invoking this method the noise can be played just in the same way used for regular sound files, PlaySound method for starting playback, StopSound method for stopping playback, StreamOutputSpeakerSet method for redirecting the audio flow to a given speaker and so on.

 

By creating an empty multi-channel (up to 7.1) audio stream on a specific player through the SoundGenerator.StreamCreateMultiChannelEmpty method and then by adding the noise, which is always a mono audio stream, to a specific channel of the stream through the SoundGenerator.StreamChannelAddNoise method. if you should need to render the same noise on two speakers of the stream at the same time, you would simply need to make a further call to the SoundGenerator.StreamChannelAddNoise method on a different channel of the stream. Once at least one element has been added, the multi-channel audio stream can be played just in the same way used for regular sound files.

 

The noise can be added to the multi-channel at a given offset and, once reproduced completely, is automatically removed from the audio stream: if you should need to repeat the noise, you would have to add it again to the stream with a new call to the SoundGenerator.StreamChannelAddNoise method.

 

Differently from noises created through the SoundGenerator.StreamCreateNoise method, noises added to a multi-channel audio stream can be endless, meaning that they can generate a sound flow without interruption for the whole duration of the multi-channel audio stream and can be modified during playback by changing the amplitude through the SoundGenerator.StreamElementAmplitudeSet 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 in two ways:

 

Through the SoundGenerator.StreamCreateDtmfString method.

 

This way creates on a specific player a mono or stereo audio stream having a duration which depends upon the number of characters to convert to DTMF tones and a fixed amplitude: after invoking this method, DTMF tones can be played just in the same way used for regular sound files, PlaySound method for starting playback, StopSound method for stopping playback, StreamOutputSpeakerSet method for redirecting the audio flow to a given speaker and so on.

 

By creating an empty multi-channel (up to 7.1) audio stream on a specific player through the SoundGenerator.StreamCreateMultiChannelEmpty method and then by adding the audio stream generated through the conversion of a string of characters to DTMF tones, which is always a mono audio stream, to a specific channel of the stream through the SoundGenerator.StreamChannelAddDtmfString method. if you should need to render the same DTMF tones on two speakers of the stream at the same time, you would simply need to make a further call to the SoundGenerator.StreamChannelAddDtmfString method on a different channel of the stream. Once at least one element has been added, the multi-channel audio stream can be played just in the same way used for regular sound files.

 

The mono stream containing DTMF tones can be added to the multi-channel at a given offset and, once reproduced completely, is automatically removed from the audio stream: if you should need to repeat the stream, you would have to add it again to the stream with a new call to the SoundGenerator.StreamChannelAddDtmfString 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 SoundGenerator.SpeechVoicesNumGet method while attributes of each single voice can be obtained through the SoundGenerator.SpeechVoiceAttributeGet method.

 

As seen for previous items, the component allows creating text to speech in two ways:

 

Through the SoundGenerator.StreamCreateSpeechFromFile or through the SoundGenerator.StreamCreateSpeechFromString method.

 

This way creates on a specific player a mono or stereo audio stream having a duration which depends upon the number of text's words to convert and a fixed amplitude: after invoking this method, the generated audio stream can be played just in the same way used for regular sound files, PlaySound method for starting playback, StopSound method for stopping playback, StreamOutputSpeakerSet method for redirecting the audio flow to a given speaker and so on.

 

By creating an empty multi-channel (up to 7.1) audio stream on a specific player through the SoundGenerator.StreamCreateMultiChannelEmpty method and then by adding the audio stream generated through the conversion of words of text, which is always a mono audio stream, to a specific channel of the stream through the SoundGenerator.StreamChannelAddSpeechFromFile method or through the SoundGenerator.StreamChannelAddSpeechFromString method; if you should need to render the same text on two speakers of the stream at the same time, you would simply need to make a further call to the mentioned methods on a different channel of the stream. Once at least one element has been added, the multi-channel audio stream can be played just in the same way used for regular sound files.

 

The mono stream containing the speech can be added to the multi-channel at a given offset and, once reproduced completely, is automatically removed from the audio stream: if you should need to repeat the stream, you would have to add it again to the stream with a new call to the SoundGenerator.StreamChannelAddSpeechFromFile method or through the SoundGenerator.StreamChannelAddSpeechFromString method.

 

 

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:

- SoundGenerator