Differences

This shows you the differences between two versions of the page.

05Misc:A_Template_for_Audio_DSP_Applications [2017/09/25 15:34] (current)
Line 1: Line 1:
 +======= A Template for writing Digital Signal Processing Applications with a Sound Card under Linux and Windows =======
 +
 +<html>
 +<h2>Description</h2>
 +<p>
 +dsp_template is a project that can be used as starting point for writing applications for digital signal processing (DSP) with an ordinary sound card. The project is written in C++ and uses the <a href="http://www.qtsoftware.com/" target="_blank">Qt</a> library from Trolltech, which is a portable library for writing graphical user interfaces. Furthermore, the libraries <a href="http://qwt.sourceforge.net/" target="_blank">Qwt</a>, <a href="http://www.fftw.org/" target="_blank">fftw</a> and <a href="http://www.portaudio.com/" target="_blank">portaudio</a> are included. Qwt is used for the plotting of data, fftw can be used for the fast processing of FFTs and portaudio is used for the unique access to the sound card interface. <br>
 +<br>
 +All these libraries are portable to different platforms. The application has been developed under Linux and tested for Windows, too. In principle, Mac Os should work too but I simply don't have a Mac so I can't test it ;-)
 +The portaudio is included as source code as the used version (v19_trunk) is not an official release. All other libraries are linked at runtime. Under linux, the libraries libqt4-core, libqt4-gui, libqwt5-qt4, libfftw3 and libasound2 must be installed (which can be done with &quot;apt-get install <library-name>&quot; for Debian based distributions). Under Windows precompiled DLLs can be downloaded <a href="/dsp_template/dsp_template_v0.1_dlls.zip">here</a>.
 +dsp_template is licensed under the GNU public license GPL.<br>
 +</p>
 +<p align="center"><a href="/dsp_template/dsp_template_v0.1.zip">Download dsp_template v0.1 Project Sources as zip</a></p>
 +<p align="center"><img src="/images/dsp_template.gif"></p>
 +<h2>Getting Started</h2>
 +<p>
 +  <ol>
 +    <li>The project file (dsp_template.pro) can be opened with Qt Creator, which is an integrated development tool from Trolltech. Alternatively, the qmake command can be used to parse the project file and to create a make file for the used platform (no cross-compiling is supported, I used sun's VirtaulBox to compile for Windows).
 +    </li>
 +    <li>You can try different examples by uncommenting appropriated lines in the project file with name &quot;audioprocessor_xxx.cpp/.h&quot; *and* the corresponding header in &quot;mainwindow.h&quot;. A description of the different examples can be found in the text below.<br>
 +    </li>
 +    <li>To change the name of the project just rename the project file (dsp_template.pro) to and put the same name as TARGET in the project file
 +    </li>
 +    <li>Have fun!
 +    </li>
 +  </ol>
 +</p>
 +<h2>Notes for Linux</h2>
 +<p>
 +Although the ALSA is supported by portaudio, the playback with ALSA was not possible. Hopefully this will be fixed in the next release. Nevertheless, OSS is working fine. The support of the different audio APIs can be defined in the project file (uncomment PA_USE_xxxx).<br>
 +</p>
 +<h2>Notes for Windows</h2>
 +<p>
 +For using Direct-X the Microsoft Direct-X SDK has to be installed (DXSDK_Nov08 was tested) and the header directory must be specified using &quot;win32:INCLUDEPATH&quot; in the project file (see comment).
 +</p>
 +
 +<h2>Short Description of the Files and Classes</h2>
 +<p>
 +In the following, the implemented files and classes are explained briefly:<br>
 +<br>
 +<b>main.cpp</b> - the starting point.<br>
 +This is the file where the main() method is implemented. As it is usual for Qt applications, the main window class is created here - in this case the class MainWindow.<br>
 +<br>
 +<b>wainwindow.cpp</b> - Implementation of the main window (class MainWindow)<br>
 +This is the implementation file of the main window. The GUI is mainly defined in mainwindow.ui (the Qt-UI Format) which can be edited by the Qt Assistant or the integrated IDE Qt Creator. A menu is created with one entry &quot;Settings->Sound Settings&quot; which activates a dialog where the basic sound settings, like selecting the sound device and the frame length can be done. This dialog is defined in soundsettingsdlg.ui and soundsettingsdlg.cpp. An additional QwtPlot widget is created and initialized (outside  mainwindow.ui). Furthermore, an instance of the class AudioProcessor is created, which is the starting point for the audio processing routines.<br>
 +</p>
 +<p align="center"><img src="/images/dsp_template_sound_settings.gif"></p>
 +<p>
 +<b>soundsettingsdlg.cpp</b> - Implementation of the sound settings dialog<br>
 +Based on soundsettingsdlg.ui a simple dialog is created for sound card settings.<br>
 +<br>
 +<b>pawrapper.cpp</b> - A simple c++ wrapper for portaudio<br>
 +In this class (PaWrapper) the important methods are encapsulated for configuring the sound device and to start and stop the audio processing. PaWrapper is not used directly, the application specific audio processing algorithm is implemented in a class derived from PaWrapper (the class AudioProcessor was used in the examples) which must override the virtual method ProcessingCallback(). Here the audio processing takes place.<br>
 +<br>
 +<b>fftprocessor.cpp</b> - A simple wrapper class for fftw<br>
 +By creating an fftProcessor object, the memory for input and output data is reserved and a fft plan for real input data is created. The buffers can be directly accessed via the fftIn attribute. The calculation is started with the execute() method and the result can be read from  fftOut in a complex data format.<br>
 +</p>
 +<h2>Short Description of the Examples</h2>
 +<p>
 +Example AudioProcessor implementations (from simple to more complex examples):<br>
 +audioprocessor_io_copy.cpp<br>
 +The simplest example that copies the sound card input to the output<br>
 +<br>
 +<b>audioprocessor_noise.cpp</b><br>
 +White noise is generated using the rand() function and is played back.<br>
 +<br>
 +<b>audioprocessor_sine.cpp</b><br>
 +A 1kHz sine wave is generate and played back<br>
 +<br>
 +<b>audioprocessor_fft.cpp</b><br>
 +The fftProcessor is used to calculate the spectrum of the input data in realtime. A hamming window is applied to the input data to sharpen the frequency resolution and the fft calculation is started for each frame. Every &quot;noOfFramesPerPlot&quot; frames, the Qt signal &quot;frameProcessed&quot; is emitted which is connected to the &quot;onFrameProcessed&quot; slot in the main window which replots the QwtPlot. <br>
 +
 +</p>
 +
 +<br>
 +
 +</html>
05Misc/A_Template_for_Audio_DSP_Applications.txt · Last modified: 2017/09/25 15:34 (external edit)
 (login)