There are many ways to generate tones, and the specific instances you mention are likely to use diverse techniques. But there is a general way to think about it.Using digital sampling, we can capture analogue signals as a stream of numeric values. Each value represents the instantaneous value of the waveform at a moment in time (to some predetermined precision), and provided we capture sufficiently quickly, we can capture enough detail to fully reproduce any waveform up to half of the sampling frequency (e.g. a sample rate of 48 kHz can reproduce sound frequencies up to 24 kHz).To play that back, we feed the digital samples to a digital-to-analogue converter (DAC), which reconstructs the analogue waveform which can be amplified and used to drive speakers.To generate tones, we can feed a DAC in exactly same way, but using computed sample values instead of recorded ones. For example, if we pass it a series of sine values, a sinewave will be reconstructed.So a completely general-purpose technique for generating sound of any sort is to set up a DAC fed at a constant sample rate from a buffer (a chunk of memory) which contains sample values. As the values in the buffer are consumed, we can call code functions that can fill in more values further ahead in the buffer. These values can be calculated based on mathematical formulae, or copied from a prerecorded sample.A music synthesizer or keyboard will typically use this technique, whereby the final played samples are the result of a pipeline of code routines responsible for computing the values in various ways. Different functions can act as a source of frequencies, filters, effects etc. The pipeline can be configured and manipulated by the synthesiser controls.To consider the need to generate sinewaves in more detail as an example, one technique is to precompute the values for one cycle of a sinewave at the maximum precision needed. For example, if the sampling frequency is 48 kHz, and the minimum frequency to be generated (and frequency difference needed) is 1Hz, we could divide one cycle into 48,000 angular values, and compute the sine of each one (using 16 bits, say). This is 96 kilobytes of data stored in a table (memory). If at each sample moment we just pass the next table value to the DAC, we get a 1 Hz sinewave. If we want 1000 Hz, we can just pass every 1,000th sample. To get 941 Hz, we pass every 941th sample and so on. So we can generate a sinewave of any frequency between 1 Hz to 24 kHz in 1 Hz steps. Using multiple skip values would also allow more complex tones to be generated from the same table by adding values together.If the table is filled with values based on different waveforms, any periodic function can be generated in exactly the same way (triangle, sawtooth and square, or any shape you like). For much more complex sounds that are based on sampled audio, we’d need a much larger table, but the principle is the same - by skipping samples, we can playback the table at different frequencies.DTMF is a way to encode 16 different numbers representing a 4 x 4 keypad matrix using pairs of sinewaves. One represents the row and the other the column of the pressed key. The frequencies are chosen so they have no common factors, making them distinct and relatively easy to decode even when line conditions introduce considerable distortion. DTMF can be generated as above using wavetable synthesis. Instead of a single sine value for each sample, two sample ‘skip’ values can be used, pulling out both the frequencies wanted (e.g. the number ‘1’ is 697 Hz + 1209 Hz, so sample values from our sine table at those intervals can be extracted and simply added together).A2A.