Commit db2025fc authored by Simon A. Eugster's avatar Simon A. Eugster

First preparations for audio spectrum scopes, using kiss_fft

svn path=/trunk/kdenlive/; revision=5108
parent 1e8b41a1
......@@ -3,11 +3,14 @@ project(kdenlive)
set(BASE_VERSION 0.7.9)
set(LIBMLT_REQUIRED_VERSION 0.5.10)
#set(CMAKE_C_FLAGS " -std=c99 " ${CMAKE_C_FLAGS} " -std=c99")
option(RELEASE_BUILD "Remove compilation date from program version (use for stable releases)" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules)
# Search packages used by KDE.
find_package(KDE4 REQUIRED)
set(CMAKE_C_FLAGS " --std=c99") # To compile kiss_fft
include(KDE4Defaults)
include(MacroLibrary)
include(FindGettext)
......@@ -61,3 +64,6 @@ add_subdirectory(po)
add_subdirectory(man)
configure_file(${CMAKE_SOURCE_DIR}/kdenlive-config.h.cmake kdenlive-config.h @ONLY)
message("C flags are now: " ${CMAKE_C_FLAGS})
......@@ -1080,9 +1080,9 @@
borderopacity="1.0"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:zoom="0.061871844"
inkscape:cx="7437.5969"
inkscape:cy="3161.6811"
inkscape:zoom="0.49497475"
inkscape:cx="7848.5254"
inkscape:cy="5017.1078"
inkscape:document-units="px"
inkscape:current-layer="layer3"
showgrid="false"
......@@ -2041,6 +2041,17 @@
x="-3421.3643"
id="tspan13226-0-8"
sodipodi:role="line">External programs</tspan></text>
<text
sodipodi:linespacing="125%"
id="text3284"
y="-171.68839"
x="899.27069"
style="font-size:144px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;opacity:0.2017544;color:#000000;fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans Bold"
xml:space="preserve"><tspan
y="-171.68839"
x="899.27069"
id="tspan3286"
sodipodi:role="line">Keyboard Shortcuts</tspan></text>
</g>
<g
inkscape:groupmode="layer"
......@@ -2396,5 +2407,27 @@
id="tspan13264-5-65"
x="4651.2607"
y="-163.50342">Color Correction layout</tspan></text>
<text
sodipodi:linespacing="125%"
id="text3288"
y="-71.055161"
x="2257.0693"
style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
xml:space="preserve"><tspan
y="-71.055161"
x="2257.0693"
id="tspan3290"
sodipodi:role="line">Make customizable</tspan></text>
<text
xml:space="preserve"
style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-indent:0;text-align:start;text-decoration:none;line-height:125%;letter-spacing:normal;word-spacing:normal;text-transform:none;direction:ltr;block-progression:tb;writing-mode:lr-tb;text-anchor:start;color:#000000;fill:#eeeeee;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
x="1620.6732"
y="1.675822"
id="text3292"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3294"
x="1620.6732"
y="1.675822">Support workflow</tspan></text>
</g>
</svg>
add_subdirectory(widgets)
add_subdirectory(mimetypes)
add_subdirectory(kiss_fft)
macro_optional_find_package(Nepomuk)
include(FindQImageBlitz)
......@@ -16,8 +17,11 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/widgets
${CMAKE_SOURCE_DIR}/src/colorcorrection
${CMAKE_SOURCE_DIR}/src/onmonitoritems
${CMAKE_SOURCE_DIR}/src/kiss_fft
${CMAKE_SOURCE_DIR}/src/audioscopes
)
if(Nepomuk_FOUND)
include_directories(NEPOMUK_INCLUDES)
set(optional_libs ${NEPOMUK_LIBRARIES})
......@@ -44,6 +48,7 @@ else(APPLE)
macro_optional_find_package(OpenGL)
endif(APPLE)
link_libraries(
${LIBMLT_LIBRARY}
${LIBMLTPLUS_LIBRARY}
......@@ -111,9 +116,11 @@ kde4_add_ui_files(kdenlive_UI
widgets/stopmotion_ui.ui
widgets/monitorscenecontrolwidget_ui.ui
widgets/cornerswidget_ui.ui
widgets/audiospectrum_ui.ui
)
set(kdenlive_SRCS
${kdenlive_SRCS}
addclipcommand.cpp
main.cpp
mainwindow.cpp
......@@ -213,6 +220,8 @@ set(kdenlive_SRCS
tracksconfigdialog.cpp
configtrackscommand.cpp
abstractscopewidget.cpp
audioscopes/abstractaudioscopewidget.cpp
audioscopes/audiospectrum.cpp
rebuildgroupcommand.cpp
histogram.cpp
rgbparade.cpp
......@@ -241,6 +250,9 @@ set(kdenlive_SRCS
onmonitoritems/onmonitorcornersitem.cpp
monitorscenecontrolwidget.cpp
cornerswidget.cpp
kiss_fft/_kiss_fft_guts.h
kiss_fft/kiss_fft.c
kiss_fft/tools/kiss_fftr.c
)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/colorcorrection)
......
......@@ -222,7 +222,7 @@ private:
/** The semaphores ensure that the QFutures for the HUD/Scope/Background threads cannot
be assigned a new thread while it is still running. (Could cause deadlocks and other
nasty things known from parallelism. */
nasty things known from parallelism.) */
QSemaphore m_semaphoreHUD;
QSemaphore m_semaphoreScope;
QSemaphore m_semaphoreBackground;
......
This diff is collapsed.
/***************************************************************************
* Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com) *
* This file is part of kdenlive. See www.kdenlive.org. *
* *
* 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. *
***************************************************************************/
#ifndef ABSTRACTAUDIOSCOPEWIDGET_H
#define ABSTRACTAUDIOSCOPEWIDGET_H
#include <QtCore>
#include <QWidget>
class QMenu;
class Monitor;
class Render;
class AbstractAudioScopeWidget : public QWidget
{
Q_OBJECT
public:
AbstractAudioScopeWidget(Monitor *projMonitor, Monitor *clipMonitor, bool trackMouse = false, QWidget *parent = 0);
virtual ~AbstractAudioScopeWidget(); // Must be virtual because of inheritance, to avoid memory leaks
QPalette m_scopePalette;
/** Initializes widget settings (reads configuration).
Has to be called in the implementing object. */
void init();
/** Does this scope have auto-refresh enabled */
bool autoRefreshEnabled();
///// Unimplemented /////
virtual QString widgetName() const = 0;
///// Variables /////
static const QPen penThick;
static const QPen penThin;
static const QPen penLight;
static const QPen penDark;
protected:
///// Variables /////
Monitor *m_projMonitor;
Monitor *m_clipMonitor;
Render *m_activeRender;
/** The context menu. Feel free to add new entries in your implementation. */
QMenu *m_menu;
/** Enables auto refreshing of the scope.
This is when a new frame is shown on the active monitor.
Resize events always force a recalculation. */
QAction *m_aAutoRefresh;
/** Realtime rendering. Should be disabled if it is not supported.
Use the accelerationFactor variable passed to the render functions as a hint of
how many times faster the scope should be calculated. */
QAction *m_aRealtime;
/** The mouse position; Updated when the mouse enters the widget
AND mouse tracking has been enabled. */
QPoint m_mousePos;
/** Knows whether the mouse currently lies within the widget or not.
Can e.g. be used for drawing a HUD only when the mouse is in the widget. */
bool m_mouseWithinWidget;
/** Offset from the widget's borders */
const uchar offset;
/** The rect on the widget we're painting in.
Can be used by the implementing widget, e.g. in the render methods.
Is updated when necessary (size changes). */
QRect m_scopeRect;
/** Images storing the calculated layers. Will be used on repaint events. */
QImage m_imgHUD;
QImage m_imgScope;
QImage m_imgBackground;
/** The acceleration factors can be accessed also by other renderer tasks,
e.g. to display the scope's acceleration factor in the HUD renderer. */
int m_accelFactorHUD;
int m_accelFactorScope;
int m_accelFactorBackground;
/** Reads the widget's configuration.
Can be extended in the implementing subclass (make sure to run readConfig as well). */
virtual void readConfig();
/** Writes the widget configuration.
Implementing widgets have to implement an own method and run it in their destructor. */
void writeConfig();
/** Identifier for the widget's configuration. */
QString configName();
///// Unimplemented Methods /////
/** Where on the widget we can paint in.
May also update other variables that depend on the widget's size. */
virtual QRect scopeRect() = 0;
/** @brief HUD renderer. Must emit signalHUDRenderingFinished(). @see renderScope */
virtual QImage renderHUD(uint accelerationFactor) = 0;
/** @brief Scope renderer. Must emit signalScopeRenderingFinished()
when calculation has finished, to allow multi-threading.
accelerationFactor hints how much faster than usual the calculation should be accomplished, if possible. */
virtual QImage renderScope(uint accelerationFactor,
const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples) = 0;
/** @brief Background renderer. Must emit signalBackgroundRenderingFinished(). @see renderScope */
virtual QImage renderBackground(uint accelerationFactor) = 0;
/** Must return true if the HUD layer depends on the input monitor.
If it does not, then it does not need to be re-calculated when
a new frame from the monitor is incoming. */
virtual bool isHUDDependingOnInput() const = 0;
/** @see isHUDDependingOnInput() */
virtual bool isScopeDependingOnInput() const = 0;
/** @see isHUDDependingOnInput() */
virtual bool isBackgroundDependingOnInput() const = 0;
///// Can be reimplemented /////
/** Calculates the acceleration factor to be used by the render thread.
This method can be refined in the subclass if required. */
virtual uint calculateAccelFactorHUD(uint oldMseconds, uint oldFactor);
virtual uint calculateAccelFactorScope(uint oldMseconds, uint oldFactor);
virtual uint calculateAccelFactorBackground(uint oldMseconds, uint oldFactor);
///// Reimplemented /////
void mouseMoveEvent(QMouseEvent *);
void leaveEvent(QEvent *);
void mouseReleaseEvent(QMouseEvent *);
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *); // Called when the widget is activated via the Menu entry
// void raise(); // Called only when manually calling the event -> useless
protected slots:
/** Forces an update of all layers. */
void forceUpdate(bool doUpdate = true);
void forceUpdateHUD();
void forceUpdateScope();
void forceUpdateBackground();
void slotAutoRefreshToggled(bool);
signals:
/** mseconds represent the time taken for the calculation,
accelerationFactor is the acceleration factor that has been used. */
void signalHUDRenderingFinished(uint mseconds, uint accelerationFactor);
void signalScopeRenderingFinished(uint mseconds, uint accelerationFactor);
void signalBackgroundRenderingFinished(uint mseconds, uint accelerationFactor);
/** For the mouse position itself see m_mousePos.
To check whether the mouse has leaved the widget, see m_mouseWithinWidget. */
void signalMousePositionChanged();
/** Do we need the renderer to send its frames to us? */
void requestAutoRefresh(bool);
private:
/** Counts the number of frames that have been rendered in the active monitor.
The frame number will be reset when the calculation starts for the current frame. */
QAtomicInt m_newHUDFrames;
QAtomicInt m_newScopeFrames;
QAtomicInt m_newBackgroundFrames;
/** Counts the number of updates that, unlike new frames, force a recalculation
of the scope, like for example a resize event. */
QAtomicInt m_newHUDUpdates;
QAtomicInt m_newScopeUpdates;
QAtomicInt m_newBackgroundUpdates;
/** The semaphores ensure that the QFutures for the HUD/Scope/Background threads cannot
be assigned a new thread while it is still running. (Could cause deadlocks and other
nasty things known from parallelism.) */
QSemaphore m_semaphoreHUD;
QSemaphore m_semaphoreScope;
QSemaphore m_semaphoreBackground;
QFuture<QImage> m_threadHUD;
QFuture<QImage> m_threadScope;
QFuture<QImage> m_threadBackground;
bool initialDimensionUpdateDone;
bool m_requestForcedUpdate;
QImage m_scopeImage;
QVector<int16_t> m_audioFrame; //NEW
int m_freq;
int m_nChannels;
int m_nSamples;
QString m_widgetName;
void prodHUDThread();
void prodScopeThread();
void prodBackgroundThread();
public slots:
/** @brief Must be called when the active monitor has shown a new frame.
This slot must be connected in the implementing class, it is *not*
done in this abstract class. */
void slotActiveMonitorChanged(bool isClipMonitor);
private slots:
void customContextMenuRequested(const QPoint &pos);
/** To be called when a new frame has been received.
The scope then decides whether and when it wants to recalculate the scope, depending
on whether it is currently visible and whether a calculation thread is already running. */
void slotRenderZoneUpdated();
void slotRenderZoneUpdated(QImage);//OLD
void slotReceiveAudio(const QVector<int16_t> sampleData, const int freq, const int num_channels, const int num_samples); // NEW, TODO comment
/** The following slots are called when rendering of a component has finished. They e.g. update
the widget and decide whether to immediately restart the calculation thread. */
void slotHUDRenderingFinished(uint mseconds, uint accelerationFactor);
void slotScopeRenderingFinished(uint mseconds, uint accelerationFactor);
void slotBackgroundRenderingFinished(uint mseconds, uint accelerationFactor);
/** Resets the acceleration factors to 1 when realtime rendering is disabled. */
void slotResetRealtimeFactor(bool realtimeChecked);
};
#endif // ABSTRACTAUDIOSCOPEWIDGET_H
#include "audiospectrum.h"
#include "tools/kiss_fftr.h"
AudioSpectrum::AudioSpectrum(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent) :
AbstractAudioScopeWidget(projMonitor, clipMonitor, true, parent)
{
init();
}
QString AudioSpectrum::widgetName() const { return QString("audiospectrum"); }
bool AudioSpectrum::isBackgroundDependingOnInput() const { return false; }
bool AudioSpectrum::isScopeDependingOnInput() const { return false; }
bool AudioSpectrum::isHUDDependingOnInput() const { return false; }
QImage AudioSpectrum::renderBackground(uint) { return QImage(); }
QImage AudioSpectrum::renderScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples)
{
return QImage();
}
QImage AudioSpectrum::renderHUD(uint) { return QImage(); }
QRect AudioSpectrum::scopeRect() {
return QRect(0,0,40,40);
}
void AudioSpectrum::readConfig()
{
}
#ifndef AUDIOSPECTRUM_H
#define AUDIOSPECTRUM_H
#include <QtCore>
#include "abstractaudioscopewidget.h"
#include "ui_audiospectrum_ui.h"
class AudioSpectrum_UI;
class AudioSpectrum : public AbstractAudioScopeWidget {
Q_OBJECT
public:
AudioSpectrum(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent = 0);
// Implemented virtual methods
QString widgetName() const;
protected:
///// Implemented methods /////
QRect scopeRect();
QImage renderHUD(uint accelerationFactor);
QImage renderScope(uint accelerationFactor, const QVector<int16_t> audioFrame, const int freq, const int num_channels, const int num_samples);
QImage renderBackground(uint accelerationFactor);
bool isHUDDependingOnInput() const;
bool isScopeDependingOnInput() const;
bool isBackgroundDependingOnInput() const;
virtual void readConfig();
private:
Ui::AudioSpectrum_UI *ui;
};
#endif // AUDIOSPECTRUM_H
1.2.9 2010-05-27
threadsafe ( including OpenMP )
first edition of kissfft.hh the C++ template fft engine
1.2.8
Changed memory.h to string.h -- apparently more standard
Added openmp extensions. This can have fairly linear speedups for larger FFT sizes.
1.2.7
Shrank the real-fft memory footprint. Thanks to Galen Seitz.
1.2.6 (Nov 14, 2006) The "thanks to GenArts" release.
Added multi-dimensional real-optimized FFT, see tools/kiss_fftndr
Thanks go to GenArts, Inc. for sponsoring the development.
1.2.5 (June 27, 2006) The "release for no good reason" release.
Changed some harmless code to make some compilers' warnings go away.
Added some more digits to pi -- why not.
Added kiss_fft_next_fast_size() function to help people decide how much to pad.
Changed multidimensional test from 8 dimensions to only 3 to avoid testing
problems with fixed point (sorry Buckaroo Banzai).
1.2.4 (Oct 27, 2005) The "oops, inverse fixed point real fft was borked" release.
Fixed scaling bug for inverse fixed point real fft -- also fixed test code that should've been failing.
Thanks to Jean-Marc Valin for bug report.
Use sys/types.h for more portable types than short,int,long => int16_t,int32_t,int64_t
If your system does not have these, you may need to define them -- but at least it breaks in a
loud and easily fixable way -- unlike silently using the wrong size type.
Hopefully tools/psdpng.c is fixed -- thanks to Steve Kellog for pointing out the weirdness.
1.2.3 (June 25, 2005) The "you want to use WHAT as a sample" release.
Added ability to use 32 bit fixed point samples -- requires a 64 bit intermediate result, a la 'long long'
Added ability to do 4 FFTs in parallel by using SSE SIMD instructions. This is accomplished by
using the __m128 (vector of 4 floats) as kiss_fft_scalar. Define USE_SIMD to use this.
I know, I know ... this is drifting a bit from the "kiss" principle, but the speed advantages
make it worth it for some. Also recent gcc makes it SOO easy to use vectors of 4 floats like a POD type.
1.2.2 (May 6, 2005) The Matthew release
Replaced fixed point division with multiply&shift. Thanks to Jean-Marc Valin for
discussions regarding. Considerable speedup for fixed-point.
Corrected overflow protection in real fft routines when using fixed point.
Finder's Credit goes to Robert Oschler of robodance for pointing me at the bug.
This also led to the CHECK_OVERFLOW_OP macro.
1.2.1 (April 4, 2004)
compiles cleanly with just about every -W warning flag under the sun
reorganized kiss_fft_state so it could be read-only/const. This may be useful for embedded systems
that are willing to predeclare twiddle factors, factorization.
Fixed C_MUL,S_MUL on 16-bit platforms.
tmpbuf will only be allocated if input & output buffers are same
scratchbuf will only be allocated for ffts that are not multiples of 2,3,5
NOTE: The tmpbuf,scratchbuf changes may require synchronization code for multi-threaded apps.
1.2 (Feb 23, 2004)
interface change -- cfg object is forward declaration of struct instead of void*
This maintains type saftey and lets the compiler warn/error about stupid mistakes.
(prompted by suggestion from Erik de Castro Lopo)
small speed improvements
added psdpng.c -- sample utility that will create png spectrum "waterfalls" from an input file
( not terribly useful yet)
1.1.1 (Feb 1, 2004 )
minor bug fix -- only affects odd rank, in-place, multi-dimensional FFTs
1.1 : (Jan 30,2004)
split sample_code/ into test/ and tools/
Removed 2-D fft and added N-D fft (arbitrary)
modified fftutil.c to allow multi-d FFTs
Modified core fft routine to allow an input stride via kiss_fft_stride()
(eased support of multi-D ffts)
Added fast convolution filtering (FIR filtering using overlap-scrap method, with tail scrap)
Add kfc.[ch]: the KISS FFT Cache. It takes care of allocs for you ( suggested by Oscar Lesta ).
1.0.1 (Dec 15, 2003)
fixed bug that occurred when nfft==1. Thanks to Steven Johnson.
1.0 : (Dec 14, 2003)
changed kiss_fft function from using a single buffer, to two buffers.
If the same buffer pointer is supplied for both in and out, kiss will
manage the buffer copies.
added kiss_fft2d and kiss_fftr as separate source files (declarations in kiss_fft.h )
0.4 :(Nov 4,2003) optimized for radix 2,3,4,5
0.3 :(Oct 28, 2003) woops, version 2 didn't actually factor out any radices other than 2.
Thanks to Steven Johnson for finding this one.
0.2 :(Oct 27, 2003) added mixed radix, only radix 2,4 optimized versions
0.1 :(May 19 2003) initial release, radix 2 only
add_subdirectory(tools)
Copyright (c) 2003-2010 Mark Borgerding
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
KFVER=129
doc:
@echo "Start by reading the README file. If you want to build and test lots of stuff, do a 'make testall'"
@echo "but be aware that 'make testall' has dependencies that the basic kissfft software does not"
testall:
# The simd and int32_t types may or may not work on your machine
make -C test DATATYPE=simd CFLAGADD="$(CFLAGADD)" test
make -C test DATATYPE=int32_t CFLAGADD="$(CFLAGADD)" test
make -C test DATATYPE=int16_t CFLAGADD="$(CFLAGADD)" test
make -C test DATATYPE=float CFLAGADD="$(CFLAGADD)" test
make -C test DATATYPE=double CFLAGADD="$(CFLAGADD)" test
tarball: clean
hg archive -r v$(KFVER) -t tgz kiss_fft$(KFVER).tar.gz
hg archive -r v$(KFVER) -t zip kiss_fft$(KFVER).zip
clean:
cd test && make clean
cd tools && make clean
rm -f kiss_fft*.tar.gz *~ *.pyc kiss_fft*.zip
asm: kiss_fft.s
kiss_fft.s: kiss_fft.c kiss_fft.h _kiss_fft_guts.h
[ -e kiss_fft.s ] && mv kiss_fft.s kiss_fft.s~ || true
gcc -S kiss_fft.c -O3 -mtune=native -ffast-math -fomit-frame-pointer -unroll-loops -dA -fverbose-asm
gcc -o kiss_fft_short.s -S kiss_fft.c -O3 -mtune=native -ffast-math -fomit-frame-pointer -dA -fverbose-asm -DFIXED_POINT
[ -e kiss_fft.s~ ] && diff kiss_fft.s~ kiss_fft.s || true
KISS FFT - A mixed-radix Fast Fourier Transform based up on the principle,
"Keep It Simple, Stupid."
There are many great fft libraries already around. Kiss FFT is not trying
to be better than any of them. It only attempts to be a reasonably efficient,
moderately useful FFT that can use fixed or floating data types and can be
incorporated into someone's C program in a few minutes with trivial licensing.
USAGE:
The basic usage for 1-d complex FFT is:
#include "kiss_fft.h"
kiss_fft_cfg cfg = kiss_fft_alloc( nfft ,is_inverse_fft ,0,0 );
while ...
... // put kth sample in cx_in[k].r and cx_in[k].i
kiss_fft( cfg , cx_in , cx_out );
... // transformed. DC is in cx_out[0].r and cx_out[0].i
free(cfg);
Note: frequency-domain data is stored from dc up to 2pi.
so cx_out[0] is the dc bin of the FFT
and cx_out[nfft/2] is the Nyquist bin (if exists)
Declarations are in "kiss_fft.h", along with a brief description of the
functions you'll need to use.
Code definitions for 1d complex FFTs are in kiss_fft.c.
You can do other cool stuff with the extras you'll find in tools/
* multi-dimensional FFTs
* real-optimized FFTs (returns the positive half-spectrum: (nfft/2+1) complex frequency bins)
* fast convolution FIR filtering (not available for fixed point)
* spectrum image creation
The core fft and most tools/ code can be compiled to use float, double
or Q15 short samples. The default is float.
BACKGROUND:
I started coding this because I couldn't find a fixed point FFT that didn't
use assembly code. I started with floating point numbers so I could get the
theory straight before working on fixed point issues. In the end, I had a
little bit of code that could be recompiled easily to do ffts with short, float
or double (other types should be easy too).
Once I got my FFT working, I was curious about the speed compared to
a well respected and highly optimized fft library. I don't want to criticize
this great library, so let's call it FFT_BRANDX.
During this process, I learned:
1. FFT_BRANDX has more than 100K lines of code. The core of kiss_fft is about 500 lines (cpx 1-d).
2. It took me an embarrassingly long time to get FFT_BRANDX working.
3. A simple program using FFT_BRANDX is 522KB. A similar program using kiss_fft is 18KB (without optimizing for size).
4. FFT_BRANDX is roughly twice as fast as KISS FFT in default mode.
It is wonderful that free, highly optimized libraries like FFT_BRANDX exist.
But such libraries carry a huge burden of complexity necessary to extract every
last bit of performance.
Sometimes simpler is better, even if it's not better.
FREQUENTLY ASKED QUESTIONS:
Q: Can I use kissfft in a project with a ___ license?
A: Yes. See LICENSE below.
Q: Why don't I get the output I expect?
A: The two most common causes of this are
1) scaling : is there a constant multiplier between what you got and what you want?
2) mixed build environment -- all code must be compiled with same preprocessor
definitions for FIXED_POINT and kiss_fft_scalar
Q: Will you write/debug my code for me?
A: Probably not unless you pay me. I am happy to answer pointed and topical questions, but
I may refer you to a book, a forum, or some other resource.
PERFORMANCE:
(on Athlon XP 2100+, with gcc 2.96, float data type)
Kiss performed 10000 1024-pt cpx ffts in .63 s of cpu time.
For comparison, it took md5sum twice as long to process the same amount of data.
Transforming 5 minutes of CD quality audio takes less than a second (nfft=1024).
DO NOT:
... use Kiss if you need the Fastest Fourier Transform in the World
... ask me to add features that will bloat the code
UNDER THE HOOD:
Kiss FFT uses a time decimation, mixed-radix, out-of-place FFT. If you give it an input buffer
and output buffer that are the same, a temporary buffer will be created to hold the data.
No static data is used. The core routines of kiss_fft are thread-safe (but not all of the tools directory).
No scaling is done for the floating point version (for speed).
Scaling is done both ways for the fixed-point version (for overflow prevention).
Optimized butterflies are used for factors 2,3,4, and 5.
The real (i.e. not complex) optimization code only works for even length ffts. It does two half-length
FFTs in parallel (packed into real&imag), and then combines them via twiddling. The result is
nfft/2+1 complex frequency bins from DC to Nyquist. If you don't know what this means, search the web.
The fast convolution filtering uses the overlap-scrap method, slightly
modified to put the scrap at the tail.
LICENSE:
Revised BSD License, see COPYING for verbiage.
Basically, "free to use&change, give credit where due, no guarantees"
Note this license is compatible with GPL at one end of the spectrum and closed, commercial software at
the other end. See http://www.fsf.org/licensing/licenses
A commercial license is available which removes the requirement for attribution. Contact me for details.
TODO:
*) Add real optimization for odd length FFTs
*) Document/revisit the input/output fft scaling
*) Make doc describing the overlap (tail) scrap fast convolution filtering in kiss_fastfir.c
*) Test all the ./tools/ code with fixed point (kiss_fastfir.c doesn't work, maybe others)
AUTHOR: