Generating simple sounds is easy. All you need is an oscillator in the range 20 to 20.000Hz, an amplifier and a speaker. Such a circuit can generate any tone that a human can hear. By changing the frequency of the oscillator you change the emitted tone. Qbasic has a command that does just this: sound. Sound lets you specify a few parameters, with the most important being the frequency. By changing this frequency over time simple sound effects could be produced.

A better way to generate sound is sampling:

A sound wave has an intensity that varies over time. A microphone (with preamplifier) can convert this intensity to an electric signal with the same shape. An Analog to Digital Converter (ADC) can then convert this electric signal in a digital number. This is, however, not a continuous process but a discrete process, this means that every x ms the amplitude (voltage or current) of the signal is measured and converted to a digital number. This results in a digital approximation of the original signal. How good this approximation is depends on how frequently the signal is sampled. Of course more samples means more memory space is consumed and also more expensive hardware is needed. The price of an ADC depends on precision (how many bits represent the sample) and how many samples it can take per second (there are more parameters, but those are pretty much out of scope for this book).

Now you have an array of numbers. Of course now you want to turn this array back into sound. This is done with a Digital to Analog Converter (DAC). This part converts a digital value back into an electric signal. After this DAC there is a filter to smooth the wave, an amplifier and a speaker. Feed the array sample by sample to the DAC at the same rate as they were sampled and you hear the original sound back.

The advantage of this approach is it's (relative) simplicity. The disadvantage is its enormous memory consumption.

More advanced methods would be storing encoded sound (e.g. MP3). This is more tricky since it needs a decoder, yet these days integrated circuits with complete mp3 decoders exist, which makes this an interesting method to look for.

A preamplifier is used when a signal with very small amplitude has to be amplified. Preamplifiers are very linear (they cause very little distortion in the signal) but are very inefficient with power. They amplify a signal, coming from e.g. a microphone, which commonly has an amplitude of 1mV or less to a more useful amplitude of 100mV and up. Since they are so inefficient preamplifier circuits aren't used for power amplifiers.

Amplifiers allow a low power signal to be outputed through a speaker with significant power. Amplifiers commonly allow some distortion of the signal in order to preserve power. (except for class A amplifiers which consume a lot of power, but have little distortion).

Amplifiers can be built with ICs, discrete components or bought as a module.

An analog to digital converter (short: ADC) converts an analog signal to a digital value. ADCs have a certain accuracy, expressed in bit, e.g. 8bit, 10bit and 16bit. This means that the ADC will have a binary number with 8, 10 and respectively 16 bits. The highest value represented by this binary number correspondents to the reference voltage put on a special input of the ADC. e.g. If we have an 8bit ADC and we put on this special input 5V, then the value 255 means 5V. It's precision will be 1/255 * 5 V or 0.02V. Each time we add 1 to the binary number, the represented voltage increases by 0.02V.
A second point about ADCs is their timing. ADCs take some time to do a conversion. The faster they are, the more accurate they digitalise the signal (or in other words the higher the frequency of a signal can be), and the more expensive they are.

The DAC converts a digital value into a voltage level. The work either with a reference voltage or "rail-to-rail", which means that their highest digital input value represents a voltage level (almost) equal to the DACs supply voltage. Simulare to the ADC the DAC has a certain accuracy in bit and requires some time to make a conversion.