Skip to content
Snippets Groups Projects
Commit f52dfd3a authored by Paul Licameli's avatar Paul Licameli
Browse files

New library for math...

... note the swap of target_link_libraries lines in src/CMakeLists.txt,
needed to build at least on macOS, becuase FFT.h must be looked up first in
lib-math, not in lib-src/twolame

Also making a dependency cycle of SampleFormat and Dither!  But we will tolerate
that within one small library.
parent 749a0575
No related branches found
No related tags found
No related merge requests found
Showing
with 90 additions and 81 deletions
......@@ -58,33 +58,6 @@
// until proper public headers are created for the stuff in here.
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Supported sample formats
// ----------------------------------------------------------------------------
enum sampleFormat : unsigned
{
//! The increasing sequence of these enum values must correspond to the increasing data type width
//! These values persist in saved project files, so must not be changed in later program versions
int16Sample = 0x00020001,
int24Sample = 0x00040001,
floatSample = 0x0004000F,
//! Two synonyms for previous values that might change if more values were added
narrowestSampleFormat = int16Sample,
widestSampleFormat = floatSample,
};
// ----------------------------------------------------------------------------
// Provide the number of bytes a specific sample will take
// ----------------------------------------------------------------------------
#define SAMPLE_SIZE(SampleFormat) (SampleFormat >> 16)
// ----------------------------------------------------------------------------
// Generic pointer to sample data
// ----------------------------------------------------------------------------
typedef char *samplePtr;
typedef const char *constSamplePtr;
// ----------------------------------------------------------------------------
// The type for plugin IDs
// ----------------------------------------------------------------------------
......
......@@ -11,6 +11,7 @@ set( LIBRARIES
lib-basic-ui
lib-exceptions
lib-preferences
lib-math
)
if ( ${_OPT}has_networking )
......
#[[
A library of mathematical utilities and manipulation of samples
]]#
set( SOURCES
Dither.cpp
Dither.h
FFT.cpp
FFT.h
InterpolateAudio.cpp
InterpolateAudio.h
Matrix.cpp
Matrix.h
RealFFTf.cpp
RealFFTf.h
SampleCount.cpp
SampleCount.h
SampleFormat.cpp
SampleFormat.h
Spectrum.cpp
Spectrum.h
float_cast.h
)
set( LIBRARIES
lib-preferences-interface
PRIVATE
wxBase
)
audacity_library( lib-math "${SOURCES}" "${LIBRARIES}"
"" ""
)
File moved
......@@ -10,7 +10,7 @@
#ifndef __AUDACITY_DITHER_H__
#define __AUDACITY_DITHER_H__
#include "audacity/Types.h" // for samplePtr
#include "SampleFormat.h"
template< typename Enum > class EnumSetting;
......@@ -19,13 +19,14 @@ template< typename Enum > class EnumSetting;
enum DitherType : unsigned {
none = 0, rectangle = 1, triangle = 2, shaped = 3 };
class Dither
class MATH_API Dither
{
public:
static DitherType FastDitherChoice();
static DitherType BestDitherChoice();
static AUDACITY_DLL_API EnumSetting< DitherType > FastSetting, BestSetting;
static EnumSetting< DitherType > FastSetting;
static EnumSetting< DitherType > BestSetting;
/// Default constructor
Dither();
......
......@@ -39,7 +39,6 @@
* 9: Gaussian(a=4.5)
*/
#include "FFT.h"
#include "Internat.h"
......
......@@ -63,6 +63,7 @@ class TranslatableString;
* input array, and that NumSamples must be a power of two.
*/
MATH_API
void PowerSpectrum(size_t NumSamples, const float *In, float *Out);
/*
......@@ -72,7 +73,7 @@ void PowerSpectrum(size_t NumSamples, const float *In, float *Out);
* NumSamples must be a power of two.
*/
AUDACITY_DLL_API
MATH_API
void RealFFT(size_t NumSamples,
const float *RealIn, float *RealOut, float *ImagOut);
......@@ -81,7 +82,7 @@ void RealFFT(size_t NumSamples,
* so the output is purely real. NumSamples must be a power of
* two.
*/
AUDACITY_DLL_API
MATH_API
void InverseRealFFT(size_t NumSamples,
const float *RealIn, const float *ImagIn, float *RealOut);
......@@ -91,7 +92,7 @@ void InverseRealFFT(size_t NumSamples,
* inverse transform as well.
*/
AUDACITY_DLL_API
MATH_API
void FFT(size_t NumSamples,
bool InverseTransform,
const float *RealIn, const float *ImagIn, float *RealOut, float *ImagOut);
......@@ -120,7 +121,7 @@ enum eWindowFunctions
eWinFuncCount
};
AUDACITY_DLL_API
MATH_API
void WindowFunc(int whichFunction, size_t NumSamples, float *data);
/*
......@@ -129,7 +130,7 @@ void WindowFunc(int whichFunction, size_t NumSamples, float *data);
* otherwise about (NumSamples - 1) / 2
* All functions have 0 in data[0] except Rectangular, Hamming and Gaussians
*/
AUDACITY_DLL_API
MATH_API
void NewWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data);
/*
......@@ -139,21 +140,21 @@ void NewWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float
* otherwise about (NumSamples - 1) / 2
* All functions have 0 in data[0] except Rectangular, Hamming and Gaussians
*/
AUDACITY_DLL_API
MATH_API
void DerivativeOfWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data);
/*
* Returns the name of the windowing function (for UI display)
*/
AUDACITY_DLL_API const TranslatableString WindowFuncName(int whichFunction);
MATH_API const TranslatableString WindowFuncName(int whichFunction);
/*
* Returns the number of windowing functions supported
*/
AUDACITY_DLL_API int NumWindowFuncs();
MATH_API int NumWindowFuncs();
void DeinitFFT();
MATH_API void DeinitFFT();
#endif
File moved
......@@ -25,7 +25,6 @@
#ifndef __AUDACITY_INTERPOLATE_AUDIO__
#define __AUDACITY_INTERPOLATE_AUDIO__
#include <cstddef>
// See top of file for a description of the algorithm. Interpolates
......@@ -36,7 +35,7 @@
// side (6x the number of bad samples on either side is great). However,
// it will work with less data, and with the bad samples on one end or
// the other.
void AUDACITY_DLL_API InterpolateAudio(float *buffer, size_t len,
void MATH_API InterpolateAudio(float *buffer, size_t len,
size_t firstBad, size_t numBad);
#endif // __AUDACITY_INTERPOLATE_AUDIO__
File moved
File moved
......@@ -36,11 +36,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "RealFFTf.h"
#include <vector>
#include <stdlib.h>
#include <stdio.h>
......
#ifndef __realfftf_h
#define __realfftf_h
#include "MemoryX.h"
using fft_type = float;
......@@ -17,7 +13,7 @@ struct FFTParam {
#endif
};
struct AUDACITY_DLL_API FFTDeleter{
struct MATH_API FFTDeleter{
void operator () (FFTParam *p) const;
};
......@@ -25,11 +21,11 @@ using HFFT = std::unique_ptr<
FFTParam, FFTDeleter
>;
AUDACITY_DLL_API HFFT GetFFT(size_t);
AUDACITY_DLL_API void RealFFTf(fft_type *, const FFTParam *);
AUDACITY_DLL_API void InverseRealFFTf(fft_type *, const FFTParam *);
AUDACITY_DLL_API void ReorderToTime(const FFTParam *hFFT, const fft_type *buffer, fft_type *TimeOut);
AUDACITY_DLL_API void ReorderToFreq(const FFTParam *hFFT, const fft_type *buffer,
MATH_API HFFT GetFFT(size_t);
MATH_API void RealFFTf(fft_type *, const FFTParam *);
MATH_API void InverseRealFFTf(fft_type *, const FFTParam *);
MATH_API void ReorderToTime(const FFTParam *hFFT, const fft_type *buffer, fft_type *TimeOut);
MATH_API void ReorderToFreq(const FFTParam *hFFT, const fft_type *buffer,
fft_type *RealOut, fft_type *ImagOut);
#endif
......
File moved
......@@ -14,7 +14,7 @@
//! Positions or offsets within audio files need a wide type
/*! This type disallows implicit interconversions with narrower types */
class AUDACITY_DLL_API sampleCount
class MATH_API sampleCount
{
public:
using type = long long;
......@@ -128,7 +128,7 @@ inline sampleCount operator % (sampleCount a, sampleCount b)
// hiding the casts
// ----------------------------------------------------------------------------
AUDACITY_DLL_API
MATH_API
size_t limitSampleBufferSize( size_t bufferSize, sampleCount limit );
#endif
......@@ -35,6 +35,7 @@
*//*******************************************************************/
#include "SampleFormat.h"
#include "Dither.h" // CYCLE
#include <wx/intl.h>
#include <math.h>
......
......@@ -11,32 +11,43 @@
#ifndef __AUDACITY_SAMPLE_FORMAT__
#define __AUDACITY_SAMPLE_FORMAT__
#include "MemoryX.h"
#include <wx/defs.h>
#include "audacity/Types.h"
#include "Dither.h"
#include <cstdlib>
//
// Definitions / Meta-Information
//
enum DitherType : unsigned;
//! These global variables are assigned at application startup or after change of preferences.
extern AUDACITY_DLL_API DitherType gLowQualityDither, gHighQualityDither;
extern MATH_API DitherType gLowQualityDither, gHighQualityDither;
#if 0
// Moved to audacity/types.h
typedef enum {
// ----------------------------------------------------------------------------
// Supported sample formats
// ----------------------------------------------------------------------------
enum sampleFormat : unsigned
{
//! The increasing sequence of these enum values must correspond to the increasing data type width
//! These values persist in saved project files, so must not be changed in later program versions
int16Sample = 0x00020001,
int24Sample = 0x00040001,
floatSample = 0x0004000F
} sampleFormat;
floatSample = 0x0004000F,
/** \brief Return the size (in memory) of one sample (bytes) */
#define SAMPLE_SIZE(SampleFormat) ( size_t{ (SampleFormat) >> 16 } )
#endif
//! Two synonyms for previous values that might change if more values were added
narrowestSampleFormat = int16Sample,
widestSampleFormat = floatSample,
};
// ----------------------------------------------------------------------------
// Provide the number of bytes a specific sample will take
// ----------------------------------------------------------------------------
#define SAMPLE_SIZE(SampleFormat) (SampleFormat >> 16)
// ----------------------------------------------------------------------------
// Generic pointer to sample data
// ----------------------------------------------------------------------------
using samplePtr = char *;
using constSamplePtr = const char *;
// Used to determine how to fill in empty areas of audio.
typedef enum {
......@@ -48,7 +59,8 @@ typedef enum {
#define SAMPLE_SIZE_DISK(SampleFormat) (((SampleFormat) == int24Sample) ? \
size_t{ 3 } : SAMPLE_SIZE(SampleFormat) )
AUDACITY_DLL_API TranslatableString GetSampleFormatStr(sampleFormat format);
class TranslatableString;
MATH_API TranslatableString GetSampleFormatStr(sampleFormat format);
//
// Allocating/Freeing Samples
......@@ -128,7 +140,7 @@ private:
// Copying, Converting and Clearing Samples
//
AUDACITY_DLL_API
MATH_API
//! Copy samples from any format into the widest format, which is 32 bit float, with no dithering
/*!
@param src address of source samples
......@@ -141,7 +153,7 @@ AUDACITY_DLL_API
void SamplesToFloats(constSamplePtr src, sampleFormat srcFormat,
float *dst, size_t len, size_t srcStride = 1, size_t dstStride = 1);
AUDACITY_DLL_API
MATH_API
//! Copy samples from any format to any other format; apply dithering only if narrowing the format
/*!
@copydetails SamplesToFloats()
......@@ -153,11 +165,11 @@ void CopySamples(constSamplePtr src, sampleFormat srcFormat,
DitherType ditherType = gHighQualityDither, //!< default is loaded from a global variable
unsigned int srcStride=1, unsigned int dstStride=1);
AUDACITY_DLL_API
MATH_API
void ClearSamples(samplePtr buffer, sampleFormat format,
size_t start, size_t len);
AUDACITY_DLL_API
MATH_API
void ReverseSamples(samplePtr buffer, sampleFormat format,
int start, int len);
......@@ -166,7 +178,7 @@ void ReverseSamples(samplePtr buffer, sampleFormat format,
// are set in preferences.
//
AUDACITY_DLL_API
MATH_API
void InitDitherers();
// These are so commonly done for processing samples in floating point form in memory,
......
File moved
......@@ -21,7 +21,7 @@
calculates windowSize/2 frequency samples
*/
AUDACITY_DLL_API
MATH_API
bool ComputeSpectrum(const float * data, size_t width, size_t windowSize,
double rate, float *out, bool autocorrelation,
int windowFunc = eWinFuncHann);
......
......@@ -35,8 +35,6 @@
** long int lrint (double x) ;
*/
/* The presence of the required functions are detected during the configure
** process and the values HAVE_LRINT and HAVE_LRINTF are set accordingly in
** the config.h file.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment