March 28, 2024, 07:38:17 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


FFTW Frequency spectrum example

Started by sapero, June 30, 2009, 07:05:21 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

June 30, 2009, 07:05:21 AM Last Edit: July 03, 2009, 04:22:45 PM by sapero
This example is designed for single (at a time) spectrum control. It has autogain by default set to maximum compression, two plotting routines - one for low and one for high frequencies.
Sound samples are captured from default audio (mixer) device.

You'll need the FFTW Windows binaries (at least libfftw3-3.dll) from http://www.fftw.org/

sapero

I have added a wave plotter and some basic controls - the size of FFT array, capture/display frequency, 14 FFT window functions, auto and manual gain, and a simulation sine generator.
The vertical axis has been updated to the correct function: decibels = 20*log10(level/maxlevel).

sapero

July 04, 2009, 09:08:12 AM #2 Last Edit: July 04, 2009, 09:41:07 AM by sapero
A small update to the Gain trackbar. It will be working more "linear" if you update the two subroutines in spectrum.eba:global sub SpectrumSetGain(double dGain)
g_sdata.fAutoGain = FALSE

' dGain=0   - amplify +0dB
' dGain=100 - amplify +100dB
double amp     = __power(10, dGain/20.0)
g_sdata.absmax = g_sdata.CachedMaxGain / amp
' if the simulation is active, notify it
if (g_sdata.hSimChangeEvent) then SetEvent(g_sdata.hSimChangeEvent)
endsub


global sub SpectrumGetGain(),double
double amp = g_sdata.CachedMaxGain/g_sdata.absmax
return 20 * log10(amp)
endsub


Then in main.eba, case WM_HSCROLLSpectrumSetGain(SENDMESSAGE(win, TBM_GETPOS, 0, 0, IDC_SPECTRUMGAIN))
And in OnGainChanged subroutineint pos = newgain ' instead 100*newgain

@IDCONTROL->IDC_AUTOGAIN if (!@NOTIFYCODE) then SpectrumSetAutoGain(GETSTATE(win, @CONTROLID), FALSE) /*and nothing more with SetGain()*/

By default, the trackbar has range 0-100 so you can set the gain in the following range: +0dB (no amplify) to +100dB (amplitude * 10^5).
The noise level of my onboard sound card (including software up to direct sound capture driver) is -80dB, so for me, a +100dB amplifier is too much :)

About the simulation checkbox - if checked, a default 1kHz sine will be generated. Click anywhere on the spectrum to change the frequency. To change the default frequency, go to main.eba and change 1000 to anything you prefer in the @IDCONTROL handler for IDC_SIMULATION.

Techno

Quote from: sapero on June 30, 2009, 07:05:21 AM
This example is designed for single (at a time) spectrum control. It has autogain by default set to maximum compression, two plotting routines - one for low and one for high frequencies.
Sound samples are captured from default audio (mixer) device.

You'll need the FFTW Windows binaries (at least libfftw3-3.dll) from http://www.fftw.org/


Sapero,

When I try to build this very interesting application for me. The Build fails with the IWBasic v2.0 and v3.0 Compiler. What do I wrong. I don't understand what happens

This is the error report:

Compiling...
main.eba
File: C:\IWBDev3\include\unknwn.inc (40) Warning: Duplicate declaration of 'IUnknown', second definition ignored
File: C:\IWBDev3\bin\iwbstd.incc (465) Warning: See previous declaration
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\main.eba (47) Warning: Argument 9 (MainWndProc) does not match the declaration of IWBWNDPROC
Different return type: none, should be int
File: C:\IWBDev3\bin\iwbstd.incc (10) Warning: See previous declaration of IWBWNDPROC
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\main.eba (187) Warning: See previous declaration of MainWndProc
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\main.eba (200) Warning: Argument 9 (SpectrumWndProc) does not match the declaration of IWBWNDPROC
Different return type: none, should be int
File: C:\IWBDev3\bin\iwbstd.incc (10) Warning: See previous declaration of IWBWNDPROC
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.inc (12) Warning: See previous declaration of SpectrumWndProc
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\main.eba (217) Warning: Argument 9 (WaveWndProc) does not match the declaration of IWBWNDPROC
Different return type: none, should be int
File: C:\IWBDev3\bin\iwbstd.incc (10) Warning: See previous declaration of IWBWNDPROC
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\wave.inc (1) Warning: See previous declaration of WaveWndProc
Generating Exports
spectrum.eba
File: C:\IWBDev3\include\unknwn.inc (40) Warning: Duplicate declaration of 'IUnknown', second definition ignored
File: C:\IWBDev3\bin\iwbstd.incc (465) Warning: See previous declaration
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba (138) Error: syntax error - on
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba (163) Error: syntax error
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba (153) Error: unexpected end of sub: missing ENDIF
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba (153) Error: unexpected end of sub: missing ENDIF
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba (153) Error: unexpected end of sub: missing ENDIF
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba (153) Error: unexpected end of sub: missing ENDIF
File: c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba (153) Error: unexpected end of sub: missing ENDIF
Error(s) in compiling "c:\users\public\documents\development\iwbasic\projects\roundtable\fftw freq spectrum\v1.0\iwbasic\spectrum.eba"
wave.eba
File: C:\IWBDev3\include\unknwn.inc (40) Warning: Duplicate declaration of 'IUnknown', second definition ignored
File: C:\IWBDev3\bin\iwbstd.incc (465) Warning: See previous declaration
window.eba
Build Failed

LarryMc

Change these two lines
global sub SpectrumTurnSimulation(BOOL on, double frequency)
if (on)

to
global sub SpectrumTurnSimulation(BOOL on1, double frequency)
if (on1)


And Sapero has been gone for 3-1/2 years.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Techno

Quote from: LarryMc on May 27, 2015, 07:39:45 AM
Change these two lines
global sub SpectrumTurnSimulation(BOOL on, double frequency)
if (on)

to
global sub SpectrumTurnSimulation(BOOL on1, double frequency)
if (on1)


And Sapero has been gone for 3-1/2 years.

Thanks Larry

Sapero is such as Rose Roca an Great en Big WinApi Developer. Thank you for all this headers included with IWBasic.