Skip to content

Commit

Permalink
Added some (small) performance helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
geraintluff committed Jun 15, 2021
1 parent 1ab078f commit a4f21c2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
42 changes: 42 additions & 0 deletions perf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef SIGNALSMITH_DSP_PERF_H
#define SIGNALSMITH_DSP_PERF_H


namespace signalsmith {
namespace perf {
/** @defgroup Performance Performance helpers
@brief Nothing serious, just some `#defines` and helpers
@{
@file
*/

/// *Really* insist that a function/method is inlined
#ifndef SIGNALSMITH_INLINE
#ifdef __GNUC__
#define SIGNALSMITH_INLINE __attribute__((always_inline)) inline
#elif defined(__MSVC__)
#define SIGNALSMITH_INLINE __forceinline inline
#else
#define SIGNALSMITH_INLINE inline
#endif
#endif

/** @brief Complex-multiplication (with optional conjugate second-arg), without handling NaN/Infinity
The `std::complex` multiplication has edge-cases around NaNs which slow things down and prevent auto-vectorisation.
*/
template <bool conjugateSecond=false, typename V>
static SIGNALSMITH_INLINE std::complex<V> mul(const std::complex<V> &a, const std::complex<V> &b) {
return conjugateSecond ? std::complex<V>{
b.real()*a.real() + b.imag()*a.imag(),
b.real()*a.imag() - b.imag()*a.real()
} : std::complex<V>{
a.real()*b.real() - a.imag()*b.imag(),
a.real()*b.imag() + a.imag()*b.real()
};
}

/** @} */
}} // signalsmith::perf::

#endif // include guard
4 changes: 2 additions & 2 deletions spectral.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace spectral {
\diagram{stft-buffer-validity.svg}
You move the valid index along using `.ensureValid()`, passing in a functor which provides spectra (using `.analyse()` and/or direct modification through `.spectrum(c)`):
You move the valid index along using `.ensureValid()`, passing in a functor which provides spectra (using `.analyse()` and/or direct modification through `.spectrum[c]`):
\code
void processSample(...) {
Expand Down Expand Up @@ -302,7 +302,7 @@ namespace spectral {

/** Analyse a multi-channel input, for any type where `data[channel][index]` returns samples
Results can be read/edited using `.spectrum()`. */
Results can be read/edited using `.spectrum`. */
template<class Data>
void analyse(Data &&data) {
for (int c = 0; c < channels; ++c) {
Expand Down
2 changes: 1 addition & 1 deletion windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace windows {

/**@brief Forces STFT perfect-reconstruction (WOLA) on an existing window by direct calculation.
For example, here are perfect-reconstruction versions of the approximately-optimal @ref Kaiser windows:
\diagram{kaiser-windows-heuristic-pr.svg,Note the lower overall energy\, and the pointy top for 2x bandwidth}
\diagram{kaiser-windows-heuristic-pr.svg,Note the lower overall energy\, and the pointy top for 2x bandwidth. Spectral performance is about the same, though.}
*/
template<typename Data>
void forcePerfectReconstruction(Data &data, int size, int stride) {
Expand Down

0 comments on commit a4f21c2

Please sign in to comment.