00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * noise.h - A low complexity audio noise generator, suitable for 00005 * real time generation (current just approx AWGN) 00006 * 00007 * Written by Steve Underwood <steveu@coppice.org> 00008 * 00009 * Copyright (C) 2005 Steve Underwood 00010 * 00011 * All rights reserved. 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License as published by 00015 * the Free Software Foundation; either version 2 of the License, or 00016 * (at your option) any later version. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software 00025 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00026 * 00027 * $Id: noise.h,v 1.5 2005/11/27 15:20:30 steveu Exp $ 00028 */ 00029 00030 /*! \file */ 00031 00032 #if !defined(_NOISE_H_) 00033 #define _NOISE_H_ 00034 00035 /*! \page noise_page Noise generation 00036 00037 \section noise_page_sec_1 What does it do? 00038 It generates audio noise. Currently it only generates reasonable quality 00039 AWGN. It is designed to be of sufficiently low complexity to generate large 00040 volumes of reasonable quality noise, in real time. 00041 00042 Hoth noise is used to model indoor ambient noise when evaluating communications 00043 systems such as telephones. It is named after D.F. Hoth, who made the first 00044 systematic study of this. The official definition of Hoth noise is IEEE 00045 standard 269-2001 (revised from 269-1992), "Draft Standard Methods for Measuring 00046 Transmission Performance of Analog and Digital Telephone Sets, Handsets and Headsets." 00047 00048 The table below gives the spectral density of Hoth noise, adjusted in level to produce 00049 a reading of 50 dBA. 00050 00051 Freq (Hz) Spectral Bandwidth Total power in 00052 density 10 log_f each 1/3 octave band 00053 (dB SPL/Hz) (dB) (dB SPL) 00054 100 32.4 13.5 45.9 00055 125 30.9 14.7 45.5 00056 160 29.1 15.7 44.9 00057 200 27.6 16.5 44.1 00058 250 26.0 17.6 43.6 00059 315 24.4 18.7 43.1 00060 400 22.7 19.7 42.3 00061 500 21.1 20.6 41.7 00062 630 19.5 21.7 41.2 00063 800 17.8 22.7 40.4 00064 1000 16.2 23.5 39.7 00065 1250 14.6 24.7 39.3 00066 1600 12.9 25.7 38.7 00067 2000 11.3 26.5 37.8 00068 2500 9.6 27.6 37.2 00069 3150 7.8 28.7 36.5 00070 4000 5.4 29.7 34.8 00071 5000 2.6 30.6 33.2 00072 6300 -1.3 31.7 30.4 00073 8000 -6.6 32.7 26.0 00074 00075 The tolerance for each 1/3rd octave band is กำ3dB. 00076 00077 \section awgn_page_sec_2 How does it work? 00078 The central limit theorem says if you add a few random numbers together, 00079 the result starts to look Gaussian. In this case we sum 8 random numbers. 00080 The result is fast, and perfectly good as a noise source for many purposes. 00081 It should not be trusted as a high quality AWGN generator, for elaborate 00082 modelling purposes. 00083 */ 00084 00085 enum 00086 { 00087 NOISE_CLASS_AWGN = 1, 00088 NOISE_CLASS_HOTH 00089 }; 00090 00091 /*! 00092 Noise generator descriptor. This contains all the state information for an instance 00093 of the noise generator. 00094 */ 00095 typedef struct 00096 { 00097 int class_of_noise; 00098 int quality; 00099 int32_t rms; 00100 uint32_t rndnum; 00101 int32_t state; 00102 } noise_state_t; 00103 00104 #ifdef __cplusplus 00105 extern "C" { 00106 #endif 00107 00108 /*! Initialise an audio noise generator. 00109 \brief Initialise an audio noise generator. 00110 \param s The noise generator context. 00111 \param seed A seed for the underlying random number generator. 00112 \param level The noise power level in dBmO. 00113 \param class_of_noise The class of noise (e.g. AWGN). 00114 \param quality A parameter which permits speed and accuracy of the noise 00115 generation to be adjusted. 00116 \return A pointer to the noise generator context. 00117 */ 00118 noise_state_t *noise_init(noise_state_t *s, int seed, int level, int class_of_noise, int quality); 00119 00120 /*! Generate a sample of audio noise. 00121 \brief Generate a sample of audio noise. 00122 \param s The noise generator context. 00123 \return The generated sample. 00124 */ 00125 int16_t noise(noise_state_t *s); 00126 00127 #ifdef __cplusplus 00128 } 00129 #endif 00130 00131 #endif 00132 /*- End of file ------------------------------------------------------------*/