added initial version of spectrum analyzer - very basic at the moment
git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1125 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
@@ -28,8 +28,9 @@ SUBDIRS = \
|
||||
organic \
|
||||
patman \
|
||||
peak_controller_effect \
|
||||
$(SF2PLAYER_DIR) \
|
||||
$(SF2PLAYER_DIR) \
|
||||
$(SINGERBOT_DIR) \
|
||||
spectrum_analyzer \
|
||||
stereo_enhancer \
|
||||
stereo_matrix \
|
||||
$(STK_DIR) \
|
||||
|
||||
54
plugins/spectrum_analyzer/Makefile.am
Normal file
54
plugins/spectrum_analyzer/Makefile.am
Normal file
@@ -0,0 +1,54 @@
|
||||
AUTOMAKE_OPTIONS = foreign 1.4
|
||||
|
||||
PLUGIN_NAME = spectrumanalyzer
|
||||
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/src/gui
|
||||
|
||||
|
||||
AM_CXXFLAGS := $(AM_CXXFLAGS) $(QT_CXXFLAGS) -DPLUGIN_NAME="$(PLUGIN_NAME)"
|
||||
|
||||
|
||||
%.moc: ./%.h
|
||||
$(MOC) -o $@ $<
|
||||
|
||||
|
||||
MOC_FILES = ./spectrumanalyzer_controls.moc
|
||||
|
||||
if BUILD_WIN32
|
||||
DLL=$(PLUGIN_NAME).dll
|
||||
|
||||
$(DLL): lib$(PLUGIN_NAME).la
|
||||
$(CXX) *.o -L$(top_srcdir) -llmms-imp -shared -Wl,-no-undefined -o $@ $(QT_LDADD) && $(STRIP) $@
|
||||
|
||||
install-exec-hook: $(DLL)
|
||||
cp $< $(pkglibdir)
|
||||
rm $(pkglibdir)/lib$(PLUGIN_NAME).a $(pkglibdir)/lib$(PLUGIN_NAME).la
|
||||
else
|
||||
DLL=
|
||||
endif
|
||||
|
||||
BUILT_SOURCES = $(MOC_FILES) ./embedded_resources.h $(DLL)
|
||||
EMBEDDED_RESOURCES = $(wildcard *png)
|
||||
|
||||
./embedded_resources.h: $(EMBEDDED_RESOURCES)
|
||||
$(BIN2RES) $(EMBEDDED_RESOURCES) > $@
|
||||
|
||||
EXTRA_DIST = $(EMBEDDED_RESOURCES)
|
||||
|
||||
|
||||
CLEANFILES = $(MOC_FILES) ./embedded_resources.h
|
||||
|
||||
|
||||
|
||||
pkglib_LTLIBRARIES = libspectrumanalyzer.la
|
||||
|
||||
libspectrumanalyzer_la_SOURCES = spectrum_analyzer.cpp \
|
||||
spectrum_analyzer.h \
|
||||
spectrumanalyzer_controls.cpp \
|
||||
spectrumanalyzer_controls.h \
|
||||
spectrumanalyzer_control_dialog.cpp \
|
||||
spectrumanalyzer_control_dialog.h
|
||||
libspectrumanalyzer_la_LDFLAGS = -lfftw3
|
||||
|
||||
$(libspectrumanalyzer_la_SOURCES): ./embedded_resources.h
|
||||
BIN
plugins/spectrum_analyzer/logo.png
Normal file
BIN
plugins/spectrum_analyzer/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
398
plugins/spectrum_analyzer/spectrum_analyzer.cpp
Normal file
398
plugins/spectrum_analyzer/spectrum_analyzer.cpp
Normal file
@@ -0,0 +1,398 @@
|
||||
/*
|
||||
* spectrum_analyzer.cpp - spectrum analyzer plugin
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "spectrum_analyzer.h"
|
||||
|
||||
|
||||
#undef SINGLE_SOURCE_COMPILE
|
||||
#include "embed.cpp"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
plugin::descriptor PLUGIN_EXPORT spectrumanalyzer_plugin_descriptor =
|
||||
{
|
||||
STRINGIFY_PLUGIN_NAME( PLUGIN_NAME ),
|
||||
"Spectrum Analyzer",
|
||||
QT_TRANSLATE_NOOP( "pluginBrowser",
|
||||
"plugin for using arbitrary VST-effects "
|
||||
"inside LMMS." ),
|
||||
"Tobias Doerffel <tobydox/at/users.sf.net>",
|
||||
0x0100,
|
||||
plugin::Effect,
|
||||
new pluginPixmapLoader( "logo" ),
|
||||
NULL
|
||||
} ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
spectrumAnalyzer::spectrumAnalyzer( model * _parent,
|
||||
const descriptor::subPluginFeatures::key * _key ) :
|
||||
effect( &spectrumanalyzer_plugin_descriptor, _parent, _key ),
|
||||
m_saControls( this ),
|
||||
m_framesFilledUp( 0 ),
|
||||
m_energy( 0 )
|
||||
{
|
||||
m_specBuf = (fftw_complex *) fftw_malloc( ( BUFFER_SIZE + 1 ) *
|
||||
sizeof( fftw_complex ) );
|
||||
m_fftPlan = fftw_plan_dft_r2c_1d( BUFFER_SIZE*2, m_buffer,
|
||||
m_specBuf, FFTW_MEASURE );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
spectrumAnalyzer::~spectrumAnalyzer()
|
||||
{
|
||||
fftw_destroy_plan( m_fftPlan );
|
||||
fftw_free( m_specBuf );
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum WINDOWS
|
||||
{
|
||||
KAISER=1,
|
||||
RECTANGLE,
|
||||
HANNING,
|
||||
HAMMING
|
||||
};
|
||||
|
||||
|
||||
/* returns biggest value from abs_spectrum[spec_size] array
|
||||
|
||||
returns -1 on error
|
||||
*/
|
||||
double maximum(double *abs_spectrum, unsigned int spec_size)
|
||||
{
|
||||
double maxi=0;
|
||||
unsigned int i;
|
||||
|
||||
if ( abs_spectrum==NULL )
|
||||
return -1;
|
||||
|
||||
if (spec_size<=0)
|
||||
return -1;
|
||||
|
||||
for ( i=0; i<spec_size; i++ )
|
||||
{
|
||||
if ( abs_spectrum[i]>maxi )
|
||||
maxi=abs_spectrum[i];
|
||||
}
|
||||
|
||||
return maxi;
|
||||
}
|
||||
|
||||
|
||||
/* apply hanning or hamming window to channel
|
||||
|
||||
returns -1 on error */
|
||||
int hanming(double *timebuffer, int length, int type)
|
||||
{
|
||||
int i;
|
||||
double alpha;
|
||||
|
||||
if ( (timebuffer==NULL)||(length<=0) )
|
||||
return -1;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case HAMMING: alpha=0.54; break;
|
||||
case HANNING:
|
||||
default: alpha=0.5; break;
|
||||
}
|
||||
|
||||
for ( i=0; i<length; i++ )
|
||||
{
|
||||
timebuffer[i]=timebuffer[i]*(alpha+(1-alpha)*cos(2*M_PI*i/((double)length-1.0)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* compute absolute values of complex_buffer, save to absspec_buffer
|
||||
take care that - compl_len is not bigger than complex_buffer!
|
||||
- absspec buffer is big enough!
|
||||
|
||||
returns 0 on success, else -1 */
|
||||
int absspec(fftw_complex *complex_buffer, double *absspec_buffer, int compl_length)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( (complex_buffer==NULL)||(absspec_buffer==NULL) )
|
||||
return -1;
|
||||
if ( compl_length<=0 )
|
||||
return -1;
|
||||
|
||||
for (i=0; i<compl_length; i++)
|
||||
{
|
||||
absspec_buffer[i]=(double)sqrt(complex_buffer[i][0]*complex_buffer[i][0] + complex_buffer[i][1]*complex_buffer[i][1]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* build fewer subbands from many absolute spectrum values
|
||||
take care that - compressedbands[] array num_new elements long
|
||||
- num_old > num_new
|
||||
|
||||
returns 0 on success, else -1 */
|
||||
int compressbands(double *absspec_buffer, double *compressedband, int num_old, int num_new, int bottom, int top)
|
||||
{
|
||||
double ratio;
|
||||
int i, usefromold;
|
||||
double j;
|
||||
double j_min, j_max;
|
||||
|
||||
if ( (absspec_buffer==NULL)||(compressedband==NULL) )
|
||||
return -1;
|
||||
|
||||
if ( num_old<num_new )
|
||||
return -1;
|
||||
|
||||
if ( (num_old<=0)||(num_new<=0) )
|
||||
return -1;
|
||||
|
||||
if ( bottom<0 )
|
||||
bottom=0;
|
||||
|
||||
if ( top>=num_old )
|
||||
top=num_old-1;
|
||||
|
||||
usefromold=num_old-(num_old-top)-bottom;
|
||||
|
||||
ratio=(double)usefromold/(double)num_new;
|
||||
|
||||
// foreach new subband
|
||||
for ( i=0; i<num_new; i++ )
|
||||
{
|
||||
compressedband[i]=0;
|
||||
|
||||
j_min=(i*ratio)+bottom;
|
||||
|
||||
if ( j_min<0 )
|
||||
j_min=bottom;
|
||||
|
||||
j_max=j_min+ratio;
|
||||
|
||||
for ( j=(int)j_min; j<=j_max; j++ )
|
||||
{
|
||||
compressedband[i]+=absspec_buffer[(int)j];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int calc13octaveband31(double *absspec_buffer, double *subbands, int num_spec, double max_frequency)
|
||||
{
|
||||
static const int onethirdoctavecenterfr[] = {20, 25, 31, 40, 50, 63, 80, 100, 125, 160, 200, 250, 315, 400, 500, 630, 800, 1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000, 10000, 12500, 16000, 20000};
|
||||
int i, j;
|
||||
double f_min, f_max, frequency, bandwith;
|
||||
int j_min, j_max=0;
|
||||
double fpower;
|
||||
|
||||
|
||||
if ( (absspec_buffer==NULL)||(subbands==NULL) )
|
||||
return -1;
|
||||
|
||||
if ( num_spec<31 )
|
||||
return -1;
|
||||
|
||||
if ( max_frequency<=0 )
|
||||
return -1;
|
||||
|
||||
/*** energy ***/
|
||||
fpower=0;
|
||||
for ( i=0; i<num_spec; i++ )
|
||||
{
|
||||
absspec_buffer[i]=(absspec_buffer[i]*absspec_buffer[i])/BUFFER_SIZE;
|
||||
fpower=fpower+(2*absspec_buffer[i]);
|
||||
}
|
||||
fpower=fpower-(absspec_buffer[0]); //dc not mirrored
|
||||
|
||||
|
||||
/*** for each subband: sum up power ***/
|
||||
for ( i=0; i<31; i++ )
|
||||
{
|
||||
subbands[i]=0;
|
||||
|
||||
// calculate bandwith for subband
|
||||
frequency=onethirdoctavecenterfr[i];
|
||||
|
||||
bandwith=(pow(2, 1.0/3.0)-1)*frequency;
|
||||
|
||||
f_min=frequency-bandwith/2.0;
|
||||
f_max=frequency+bandwith/2.0;
|
||||
|
||||
j_min=(int)(f_min/max_frequency*(double)num_spec);
|
||||
|
||||
j_max=(int)(f_max/max_frequency*(double)num_spec);
|
||||
|
||||
|
||||
if ( (j_min<0)||(j_max<0) )
|
||||
{
|
||||
fprintf(stderr, "Error: calc13octaveband31() in %s line %d failed.\n", __FILE__, __LINE__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for ( j=j_min; j<=j_max; j++ )
|
||||
{
|
||||
if( j_max<num_spec )
|
||||
subbands[i]+=absspec_buffer[j];
|
||||
}
|
||||
|
||||
} //for
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* compute power of finite time sequence
|
||||
take care num_values is length of timesignal[]
|
||||
|
||||
returns power on success, else -1 */
|
||||
double signalpower(double *timesignal, int num_values)
|
||||
{
|
||||
double power=0;
|
||||
unsigned int i;
|
||||
|
||||
if ( num_values<=0 )
|
||||
return -1;
|
||||
|
||||
if( timesignal==NULL )
|
||||
return -1;
|
||||
|
||||
for ( i=0; i<num_values; i++ )
|
||||
{
|
||||
power+=timesignal[i]*timesignal[i];
|
||||
}
|
||||
|
||||
return power;
|
||||
}
|
||||
|
||||
|
||||
bool spectrumAnalyzer::processAudioBuffer( sampleFrame * _buf,
|
||||
const fpp_t _frames )
|
||||
{
|
||||
if( !isEnabled() || !isRunning () )
|
||||
{
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
fpp_t f = 0;
|
||||
if( _frames > BUFFER_SIZE )
|
||||
{
|
||||
m_framesFilledUp = 0;
|
||||
f = _frames - BUFFER_SIZE;
|
||||
}
|
||||
|
||||
const int cm = m_saControls.m_channelMode.value();
|
||||
|
||||
switch( cm )
|
||||
{
|
||||
case MergeChannels:
|
||||
for( ; f < _frames; ++f )
|
||||
{
|
||||
m_buffer[m_framesFilledUp] =
|
||||
( _buf[f][0] + _buf[f][1] ) * 0.5;
|
||||
++m_framesFilledUp;
|
||||
}
|
||||
break;
|
||||
case LeftChannel:
|
||||
for( ; f < _frames; ++f )
|
||||
{
|
||||
m_buffer[m_framesFilledUp] = _buf[f][0];
|
||||
++m_framesFilledUp;
|
||||
}
|
||||
break;
|
||||
case RightChannel:
|
||||
for( ; f < _frames; ++f )
|
||||
{
|
||||
m_buffer[m_framesFilledUp] = _buf[f][1];
|
||||
++m_framesFilledUp;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if( m_framesFilledUp < BUFFER_SIZE )
|
||||
{
|
||||
return( isRunning() );
|
||||
}
|
||||
|
||||
|
||||
hanming( m_buffer, BUFFER_SIZE, HAMMING );
|
||||
|
||||
const sample_rate_t sr = engine::getMixer()->processingSampleRate();
|
||||
const int LOWEST_FREQ = 0;
|
||||
const int HIGHEST_FREQ = 10000;//sr / 2;
|
||||
|
||||
fftw_execute( m_fftPlan );
|
||||
absspec( m_specBuf, m_absSpecBuf, BUFFER_SIZE+1 );
|
||||
if( m_saControls.m_linearSpec.value() )
|
||||
{
|
||||
compressbands( m_absSpecBuf, m_bands, BUFFER_SIZE+1,
|
||||
MAX_BANDS,
|
||||
LOWEST_FREQ*(BUFFER_SIZE+1)/(double)(sr/2),
|
||||
HIGHEST_FREQ*(BUFFER_SIZE+1)/(double)(sr/2) );
|
||||
m_energy = maximum( m_bands, MAX_BANDS );
|
||||
}
|
||||
else
|
||||
{
|
||||
calc13octaveband31( m_absSpecBuf, m_bands, BUFFER_SIZE+1, sr/2.0);
|
||||
m_energy = signalpower( m_buffer, BUFFER_SIZE );
|
||||
}
|
||||
|
||||
|
||||
m_framesFilledUp = 0;
|
||||
|
||||
checkGate( 0 );
|
||||
|
||||
return( isRunning() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
// neccessary for getting instance out of shared lib
|
||||
plugin * PLUGIN_EXPORT lmms_plugin_main( model * _parent, void * _data )
|
||||
{
|
||||
return( new spectrumAnalyzer( _parent,
|
||||
static_cast<const plugin::descriptor::subPluginFeatures::key *>(
|
||||
_data ) ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
83
plugins/spectrum_analyzer/spectrum_analyzer.h
Normal file
83
plugins/spectrum_analyzer/spectrum_analyzer.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* spectrum_analyzer.h - spectrum anaylzer
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SPECTRUM_ANALYZER_H
|
||||
#define _SPECTRUM_ANALYZER_H
|
||||
|
||||
#include <fftw3.h>
|
||||
|
||||
#include "effect.h"
|
||||
#include "spectrumanalyzer_controls.h"
|
||||
|
||||
|
||||
const int MAX_BANDS = 400;
|
||||
const int BUFFER_SIZE = 2048;
|
||||
|
||||
|
||||
class spectrumAnalyzer : public effect
|
||||
{
|
||||
public:
|
||||
enum ChannelModes
|
||||
{
|
||||
MergeChannels,
|
||||
LeftChannel,
|
||||
RightChannel
|
||||
} ;
|
||||
|
||||
spectrumAnalyzer( model * _parent,
|
||||
const descriptor::subPluginFeatures::key * _key );
|
||||
virtual ~spectrumAnalyzer();
|
||||
virtual bool processAudioBuffer( sampleFrame * _buf,
|
||||
const fpp_t _frames );
|
||||
|
||||
virtual effectControls * getControls( void )
|
||||
{
|
||||
return( &m_saControls );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
spectrumAnalyzerControls m_saControls;
|
||||
|
||||
fftw_plan m_fftPlan;
|
||||
|
||||
fftw_complex * m_specBuf;
|
||||
double m_absSpecBuf[BUFFER_SIZE+1];
|
||||
double m_buffer[BUFFER_SIZE*2];
|
||||
int m_framesFilledUp;
|
||||
|
||||
double m_bands[MAX_BANDS];
|
||||
double m_energy;
|
||||
|
||||
friend class spectrumAnalyzerControls;
|
||||
friend class spectrumView;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
120
plugins/spectrum_analyzer/spectrumanalyzer_control_dialog.cpp
Normal file
120
plugins/spectrum_analyzer/spectrumanalyzer_control_dialog.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* spectrumanaylzer_control_dialog.cpp - view for spectrum analyzer
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <QtGui/QLayout>
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
#include "spectrum_analyzer.h"
|
||||
#include "song_editor.h"
|
||||
#include "led_checkbox.h"
|
||||
|
||||
|
||||
class spectrumView : public QWidget
|
||||
{
|
||||
public:
|
||||
spectrumView( spectrumAnalyzer * _s, QWidget * _parent ) :
|
||||
QWidget( _parent ),
|
||||
m_sa( _s )
|
||||
{
|
||||
setFixedSize( 400, 200 );
|
||||
connect( engine::getSongEditor(), SIGNAL( periodicUpdate() ),
|
||||
this, SLOT( update() ) );
|
||||
}
|
||||
|
||||
virtual ~spectrumView()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void paintEvent( QPaintEvent * _pe )
|
||||
{
|
||||
QPainter p( this );
|
||||
p.fillRect( rect(), Qt::black );
|
||||
const double e = m_sa->m_energy;
|
||||
if( e <= 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const bool lin_y = m_sa->m_saControls.m_linearYAxis.value();
|
||||
double * b = m_sa->m_bands;
|
||||
const int LOWER_Y = -60; // dB
|
||||
int h;
|
||||
if( m_sa->m_saControls.m_linearSpec.value() )
|
||||
{
|
||||
p.setPen( QColor( 0, 255, 0 ) );
|
||||
for( int x = 0; x < MAX_BANDS; ++x, ++b )
|
||||
{
|
||||
if( lin_y )
|
||||
{
|
||||
h = height() * (*b / e );
|
||||
}
|
||||
else
|
||||
{
|
||||
h = (int)( height() * (20*(log10( *b / e ) ) - LOWER_Y ) / (-LOWER_Y ) );
|
||||
}
|
||||
p.drawLine( x, height(), x, height()-h );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int x = 0; x < 31; ++x, ++b )
|
||||
{
|
||||
if( lin_y )
|
||||
{
|
||||
h = height() * (*b / e );
|
||||
}
|
||||
else
|
||||
{
|
||||
h = (int)( height() * (20*(log10( *b / e ) ) - LOWER_Y ) / (-LOWER_Y ) );
|
||||
}
|
||||
p.fillRect( x*13, height()-h, 11, h, QColor( 0, 255, 0 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
spectrumAnalyzer * m_sa;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
spectrumAnalyzerControlDialog::spectrumAnalyzerControlDialog(
|
||||
spectrumAnalyzerControls * _controls ) :
|
||||
effectControlDialog( _controls )
|
||||
{
|
||||
QVBoxLayout * l = new QVBoxLayout( this );
|
||||
spectrumView * v = new spectrumView( _controls->m_effect, this );
|
||||
|
||||
ledCheckBox * lin_spec = new ledCheckBox( tr( "Linear spectrum" ), this );
|
||||
ledCheckBox * lin_y = new ledCheckBox( tr( "Linear Y axis" ), this );
|
||||
lin_spec->setModel( &_controls->m_linearSpec );
|
||||
lin_y->setModel( &_controls->m_linearYAxis );
|
||||
l->addWidget( v );
|
||||
l->addWidget( lin_spec );
|
||||
l->addWidget( lin_y );
|
||||
|
||||
}
|
||||
|
||||
|
||||
44
plugins/spectrum_analyzer/spectrumanalyzer_control_dialog.h
Normal file
44
plugins/spectrum_analyzer/spectrumanalyzer_control_dialog.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* spectrumanalyzer_control_dialog.h - view for spectrum analyzer
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SPECTRUMANALYZER_CONTROL_DIALOG_H
|
||||
#define _SPECTRUMANALYZER_CONTROL_DIALOG_H
|
||||
|
||||
#include "effect_control_dialog.h"
|
||||
|
||||
|
||||
class spectrumAnalyzerControls;
|
||||
|
||||
|
||||
class spectrumAnalyzerControlDialog : public effectControlDialog
|
||||
{
|
||||
public:
|
||||
spectrumAnalyzerControlDialog( spectrumAnalyzerControls * _controls );
|
||||
virtual ~spectrumAnalyzerControlDialog()
|
||||
{
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
59
plugins/spectrum_analyzer/spectrumanalyzer_controls.cpp
Normal file
59
plugins/spectrum_analyzer/spectrumanalyzer_controls.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* spectrumanaylzer_controls.cpp - controls for spectrum analyzer
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "spectrum_analyzer.h"
|
||||
|
||||
|
||||
|
||||
spectrumAnalyzerControls::spectrumAnalyzerControls( spectrumAnalyzer * _eff ) :
|
||||
effectControls( _eff ),
|
||||
m_effect( _eff ),
|
||||
m_linearSpec( FALSE, this, tr( "Linear spectrum" ) ),
|
||||
m_linearYAxis( TRUE, this, tr( "Linear Y-axis" ) ),
|
||||
m_channelMode( spectrumAnalyzer::MergeChannels, spectrumAnalyzer::MergeChannels, spectrumAnalyzer::RightChannel, this, tr( "Channel mode" ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void spectrumAnalyzerControls::loadSettings( const QDomElement & _this )
|
||||
{
|
||||
// m_freqModel.setValue( _this.attribute( "freq" ).toFloat() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void spectrumAnalyzerControls::saveSettings( QDomDocument & _doc,
|
||||
QDomElement & _this )
|
||||
{
|
||||
// _this.setAttribute( "freq", m_freqModel.value() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "spectrumanalyzer_controls.moc"
|
||||
|
||||
75
plugins/spectrum_analyzer/spectrumanalyzer_controls.h
Normal file
75
plugins/spectrum_analyzer/spectrumanalyzer_controls.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* spectrumanaylzer_controls.h - controls for spectrum-analyzer
|
||||
*
|
||||
* Copyright (c) 2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
|
||||
*
|
||||
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SPECTRUMANALYZER_CONTROLS_H
|
||||
#define _SPECTRUMANALYZER_CONTROLS_H
|
||||
|
||||
#include "effect_controls.h"
|
||||
#include "spectrumanalyzer_control_dialog.h"
|
||||
#include "knob.h"
|
||||
|
||||
|
||||
class spectrumAnalyzer;
|
||||
|
||||
|
||||
class spectrumAnalyzerControls : public effectControls
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
spectrumAnalyzerControls( spectrumAnalyzer * _eff );
|
||||
virtual ~spectrumAnalyzerControls()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
|
||||
virtual void loadSettings( const QDomElement & _this );
|
||||
inline virtual QString nodeName( void ) const
|
||||
{
|
||||
return( "spectrumanaylzercontrols" );
|
||||
}
|
||||
|
||||
virtual int getControlCount( void )
|
||||
{
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
virtual effectControlDialog * createView( void )
|
||||
{
|
||||
return( new spectrumAnalyzerControlDialog( this ) );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
spectrumAnalyzer * m_effect;
|
||||
boolModel m_linearSpec;
|
||||
boolModel m_linearYAxis;
|
||||
intModel m_channelMode;
|
||||
|
||||
friend class spectrumAnalyzer;
|
||||
friend class spectrumAnalyzerControlDialog;
|
||||
friend class spectrumView;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user