Sound Generator

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]



Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only



Problem Description

SoundGen generates complex wave forms and sends then to the PC sound card as '.wav' formatted streams.

Sine Trumpet?
Composite Sawtooth Composite Square

Background & Techniques

Math and Engineering students sooner or later discover the Fourier Analysis miracle - any stable waveform may be decomposed into a set of sine waves of appropriate frequency, phase and amplitude.    I recall working for hours to convince myself that this could really be true.   Similarly we may generate a set of sine waves which, when summed will reproduce any waveform.  So, for example, if we start with a basic sine wave and then add another with twice the frequency and half the amplitude and one with three times the frequency and 1/3 the amplitude, etc.  the resulting waveform starts looking like a sawtooth wave.

Here's a summary of the main features of the program:     

bulletGenerate sounds with an arbitrary number of frequency components and save them as '.snd' files.
bulletEach frequency component has a unique frequency, phase, amplitude and wave shape.  Normally you will be using Sine waves to build composite sounds, but "Square", "Sawtooth" and "Triangular" shapes are also available.
bulletSound files may be created, changed and deleted. Predefined sample definitions are provided for
bulletComposite Square Wave: Sum(1/N* sin(N*wt)) for all odd N.
bulletComposite Sawtooth Wave: Sum(1/N* sin(N*wt)) for all N.
bulletand a few others.
bulletThe frequency and amplitude of sounds may be scaled for playback using the "Volume" and "Frequency" track bars. These affect the playback only and do not change the sound file definitions.
bulletLeft click on a sound name (the left-most list) to select a new sound. Right click to bring up a menu of available actions.  This list is initially populated with all sound files located in the same folder as the SoundGen program. 
bulletFor a selected sound, the right side list shows a list of the frequency components of the sound. 
bullet Click to select a component, 
bulletuse Enter (or double click) to modify, 
bulletPress the Insert key to create a new component, or 
bullet Delete key delete a selected components. 
bullet Click the check box to included/exclude a particular component from the composite sound.
bulletA "Wave View" page displays a few cycles of the currently generated waveform.  

Notes for programmers:

bulletMemory streams are used to hold one second's worth of generated waveforms.  The streams are played using the  PlaySound function from MMSystem unit.  The SND_LOOP parameter causes the sound to play continuously until stopped.  
bulletProcedure MakeComplexSound does the bulk of the work in preparing the formatted stream for PlaySound.
bulletA CheckBoxList is used to display frequency component information.  Clicking the checkbox will include or exclude that particular components.  There is a quirk that must be handled when using the OnCheckClick exit - clicking the checkbox  also triggers the OnClick exit.   I set a flag in OnCheckExit to indicate to OnClick the type of click that occurred.  

Addendum October 8, 2005:  I needed a "click" sound today for a Metronome program.  I decided to modify SoundGen to create it.  So we added a "duration" field which controls how long the sound plays.  Five milliseconds of almost any waveform will produce a nice click sound, but triangle wave shapes sound best to me.  I also added a "Save as Wave file" button to save the  files created (by rhian hanson).   The original version, and now sounds with duration set to 0, generate 1 second's worth of sound that play in a continuous loop.   When such files are saved as wave files, the one second's worth is saved.   Duration is now saved and reloaded for sound definition files also.  

February 10, 2016:  Version 3.0 uploaded today adds an option to create the "Touch-Tone" sounds used in modern landline telephone connecting protocols.   The technology referred to as Dual Tone Multi-Frequency, DTMF, encoding. It combines two frequencies to create 16 distinct tones for  digits '0' through '9', letters 'A' through 'D', plus '*' and '#' special characters as illustrated in this grid at right.  Multiple characters in a string may be played and saved  in a "wave" audio format file.  This may prove useful in a future program decoding audio tones back to characters.     

Running/Exploring the Program  

bulletDownload source 
bulletDownload executable

Suggestions for Further Explorations



Created:  November 11,2003

Modified: July 29, 2017





  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.