Sound Generator

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

Search

 

Search DelphiForFun.org only

Support DFF

 

If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

In Association with Amazon.com

 

Support DFF

 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.

 

 

Contact

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

 

Search DelphiForFun.org 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.
bullet Sound files may be created, changed and deleted. Predefined sample definitions are provided for
bullet Composite Square Wave: Sum(1/N* sin(N*wt)) for all odd N.
bullet Composite Sawtooth Wave: Sum(1/N* sin(N*wt)) for all N.
bullet and a few others.
bullet The 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.
bullet Left 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. 
bullet For a selected sound, the right side list shows a list of the frequency components of the sound. 
bullet Click to select a component, 
bullet use 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.   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.  

Running/Exploring the Program  

bulletBrowse source extract 
bulletDownload source 
bulletDownload executable

Suggestions for Further Explorations

  

 

Created:  November 11,2003

Modified: May 18, 2009

 

 

 

 

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