First Commit
This commit is contained in:
191
3rdparty/freesurround/include/FreeSurroundDecoder.h
vendored
Normal file
191
3rdparty/freesurround/include/FreeSurroundDecoder.h
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
// SPDX-FileCopyrightText: 2007-2010 Christian Kothe, 2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "kiss_fftr.h"
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <complex>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* The FreeSurround decoder.
|
||||
*/
|
||||
class FreeSurroundDecoder
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* The supported output channel setups.
|
||||
* A channel setup is defined by the set of channels that are present. Here is a graphic
|
||||
* of the cs_5point1 setup: http://en.wikipedia.org/wiki/File:5_1_channels_(surround_sound)_label.svg
|
||||
*/
|
||||
enum class ChannelSetup
|
||||
{
|
||||
Stereo,
|
||||
Surround41,
|
||||
Surround51,
|
||||
Surround71,
|
||||
Legacy, // same channels as cs_5point1 but different upmixing transform; does not support the focus control
|
||||
MaxCount
|
||||
};
|
||||
|
||||
static constexpr int grid_res = 21; // resolution of the lookup grid
|
||||
using LUT = const float (*)[grid_res];
|
||||
|
||||
/**
|
||||
* Create an instance of the decoder.
|
||||
* @param setup The output channel setup -- determines the number of output channels
|
||||
* and their place in the sound field.
|
||||
* @param blocksize Granularity at which data is processed by the decode() function.
|
||||
* Must be a power of two and should correspond to ca. 10ms worth of single-channel
|
||||
* samples (default is 4096 for 44.1Khz data). Do not make it shorter or longer
|
||||
* than 5ms to 20ms since the granularity at which locations are decoded
|
||||
* changes with this.
|
||||
*/
|
||||
FreeSurroundDecoder(ChannelSetup setup = ChannelSetup::Surround51, unsigned blocksize = 4096);
|
||||
~FreeSurroundDecoder();
|
||||
|
||||
/**
|
||||
* Decode a chunk of stereo sound. The output is delayed by half of the blocksize.
|
||||
* This function is the only one needed for straightforward decoding.
|
||||
* @param input Contains exactly blocksize (multiplexed) stereo samples, i.e. 2*blocksize numbers.
|
||||
* @return A pointer to an internal buffer of exactly blocksize (multiplexed) multichannel samples.
|
||||
* The actual number of values depends on the number of output channels in the chosen
|
||||
* channel setup.
|
||||
*/
|
||||
float* Decode(float* input);
|
||||
|
||||
/**
|
||||
* Flush the internal buffer.
|
||||
*/
|
||||
void Flush();
|
||||
|
||||
// --- soundfield transformations
|
||||
// These functions allow to set up geometric transformations of the sound field after it has been decoded.
|
||||
// The sound field is best pictured as a 2-dimensional square with the listener in its
|
||||
// center which can be shifted or stretched in various ways before it is sent to the
|
||||
// speakers. The order in which these transformations are applied is as listed below.
|
||||
|
||||
/**
|
||||
* Allows to wrap the soundfield around the listener in a circular manner.
|
||||
* Determines the angle of the frontal sound stage relative to the listener, in degrees.
|
||||
* A setting of 90° corresponds to standard surround decoding, 180° stretches the front stage from
|
||||
* ear to ear, 270° wraps it around most of the head. The side and rear content of the sound
|
||||
* field is compressed accordingly behind the listerer. (default: 90, range: [0°..360°])
|
||||
*/
|
||||
void SetCircularWrap(float v);
|
||||
|
||||
/**
|
||||
* Allows to shift the soundfield forward or backward.
|
||||
* Value range: [-1.0..+1.0]. 0 is no offset, positive values move the sound
|
||||
* forward, negative values move it backwards. (default: 0)
|
||||
*/
|
||||
void SetShift(float v);
|
||||
|
||||
/**
|
||||
* Allows to scale the soundfield backwards.
|
||||
* Value range: [0.0..+5.0] -- 0 is all compressed to the front, 1 is no change, 5 is scaled 5x backwards (default: 1)
|
||||
*/
|
||||
void SetDepth(float v);
|
||||
|
||||
/**
|
||||
* Allows to control the localization (i.e., focality) of sources.
|
||||
* Value range: [-1.0..+1.0] -- 0 means unchanged, positive means more localized, negative means more ambient
|
||||
* (default: 0)
|
||||
*/
|
||||
void SetFocus(float v);
|
||||
|
||||
// --- rendering parameters
|
||||
// These parameters control how the sound field is mapped onto speakers.
|
||||
|
||||
/**
|
||||
* Set the presence of the front center channel(s).
|
||||
* Value range: [0.0..1.0] -- fully present at 1.0, fully replaced by left/right at 0.0 (default: 1).
|
||||
* The default of 1.0 results in spec-conformant decoding ("movie mode") while a value of 0.7 is
|
||||
* better suited for music reproduction (which is usually mixed without a center channel).
|
||||
*/
|
||||
void SetCenterImage(float v);
|
||||
|
||||
/**
|
||||
* Set the front stereo separation.
|
||||
* Value range: [0.0..inf] -- 1.0 is default, 0.0 is mono.
|
||||
*/
|
||||
void SetFrontSeparation(float v);
|
||||
|
||||
/**
|
||||
* Set the rear stereo separation.
|
||||
* Value range: [0.0..inf] -- 1.0 is default, 0.0 is mono.
|
||||
*/
|
||||
void SetRearSeparation(float v);
|
||||
|
||||
// --- bass redirection (to LFE)
|
||||
|
||||
/**
|
||||
* Enable/disable LFE channel (default: false = disabled)
|
||||
*/
|
||||
void SetBassRedirection(bool v);
|
||||
|
||||
/**
|
||||
* Set the lower end of the transition band, in Hz/Nyquist (default: 40/22050).
|
||||
*/
|
||||
void SetLowCutoff(float v);
|
||||
|
||||
/**
|
||||
* Set the upper end of the transition band, in Hz/Nyquist (default: 90/22050).
|
||||
*/
|
||||
void SetHighCutoff(float v);
|
||||
|
||||
// --- info
|
||||
|
||||
/**
|
||||
* Number of samples currently held in the buffer.
|
||||
*/
|
||||
unsigned GetSamplesBuffered();
|
||||
|
||||
private:
|
||||
using cplx = std::complex<double>;
|
||||
|
||||
struct ChannelMap
|
||||
{
|
||||
std::span<const LUT> luts;
|
||||
const float* xsf;
|
||||
};
|
||||
|
||||
static const std::array<ChannelMap, static_cast<size_t>(ChannelSetup::MaxCount)> s_channel_maps;
|
||||
|
||||
void BufferedDecode(float* input);
|
||||
|
||||
// get the index (and fractional offset!) in a piecewise-linear channel allocation grid
|
||||
static int MapToGrid(double& x);
|
||||
|
||||
// constants
|
||||
const ChannelMap& cmap; // the channel setup
|
||||
unsigned N, C; // number of samples per input/output block, number of output channels
|
||||
|
||||
// parameters
|
||||
float circular_wrap; // angle of the front soundstage around the listener (90°=default)
|
||||
float shift; // forward/backward offset of the soundstage
|
||||
float depth; // backward extension of the soundstage
|
||||
float focus; // localization of the sound events
|
||||
float center_image; // presence of the center speaker
|
||||
float front_separation; // front stereo separation
|
||||
float rear_separation; // rear stereo separation
|
||||
float lo_cut, hi_cut; // LFE cutoff frequencies
|
||||
bool use_lfe; // whether to use the LFE channel
|
||||
|
||||
// FFT data structures
|
||||
std::vector<double> lt, rt, dst; // left total, right total (source arrays), time-domain destination buffer array
|
||||
std::vector<cplx> lf, rf; // left total / right total in frequency domain
|
||||
kiss_fftr_cfg forward = nullptr;
|
||||
kiss_fftr_cfg inverse = nullptr; // FFT buffers
|
||||
|
||||
// buffers
|
||||
bool buffer_empty = true; // whether the buffer is currently empty or dirty
|
||||
std::vector<float> inbuf; // stereo input buffer (multiplexed)
|
||||
std::vector<float> outbuf; // multichannel output buffer (multiplexed)
|
||||
std::vector<double> wnd; // the window function, precomputed
|
||||
std::vector<std::vector<cplx>> signal; // the signal to be constructed in every channel, in the frequency domain
|
||||
};
|
||||
127
3rdparty/freesurround/include/kiss_fft.h
vendored
Normal file
127
3rdparty/freesurround/include/kiss_fft.h
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
#ifndef KISS_FFT_H
|
||||
#define KISS_FFT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// we're using doubles here...
|
||||
#define kiss_fft_scalar double
|
||||
|
||||
/*
|
||||
ATTENTION!
|
||||
If you would like a :
|
||||
-- a utility that will handle the caching of fft objects
|
||||
-- real-only (no imaginary time component ) FFT
|
||||
-- a multi-dimensional FFT
|
||||
-- a command-line utility to perform ffts
|
||||
-- a command-line utility to perform fast-convolution filtering
|
||||
|
||||
Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c
|
||||
in the tools/ directory.
|
||||
*/
|
||||
|
||||
#ifdef USE_SIMD
|
||||
# include <xmmintrin.h>
|
||||
# define kiss_fft_scalar __m128
|
||||
#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes,16)
|
||||
#define KISS_FFT_FREE _mm_free
|
||||
#else
|
||||
#define KISS_FFT_MALLOC malloc
|
||||
#define KISS_FFT_FREE free
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FIXED_POINT
|
||||
#include <sys/types.h>
|
||||
# if (FIXED_POINT == 32)
|
||||
# define kiss_fft_scalar int32_t
|
||||
# else
|
||||
# define kiss_fft_scalar int16_t
|
||||
# endif
|
||||
#else
|
||||
# ifndef kiss_fft_scalar
|
||||
/* default is float */
|
||||
# define kiss_fft_scalar float
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
kiss_fft_scalar r;
|
||||
kiss_fft_scalar i;
|
||||
}kiss_fft_cpx;
|
||||
|
||||
typedef struct kiss_fft_state* kiss_fft_cfg;
|
||||
|
||||
/*
|
||||
* kiss_fft_alloc
|
||||
*
|
||||
* Initialize a FFT (or IFFT) algorithm's cfg/state buffer.
|
||||
*
|
||||
* typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL);
|
||||
*
|
||||
* The return value from fft_alloc is a cfg buffer used internally
|
||||
* by the fft routine or NULL.
|
||||
*
|
||||
* If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc.
|
||||
* The returned value should be free()d when done to avoid memory leaks.
|
||||
*
|
||||
* The state can be placed in a user supplied buffer 'mem':
|
||||
* If lenmem is not NULL and mem is not NULL and *lenmem is large enough,
|
||||
* then the function places the cfg in mem and the size used in *lenmem
|
||||
* and returns mem.
|
||||
*
|
||||
* If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough),
|
||||
* then the function returns NULL and places the minimum cfg
|
||||
* buffer size in *lenmem.
|
||||
* */
|
||||
|
||||
kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem);
|
||||
|
||||
/*
|
||||
* kiss_fft(cfg,in_out_buf)
|
||||
*
|
||||
* Perform an FFT on a complex input buffer.
|
||||
* for a forward FFT,
|
||||
* fin should be f[0] , f[1] , ... ,f[nfft-1]
|
||||
* fout will be F[0] , F[1] , ... ,F[nfft-1]
|
||||
* Note that each element is complex and can be accessed like
|
||||
f[k].r and f[k].i
|
||||
* */
|
||||
void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout);
|
||||
|
||||
/*
|
||||
A more generic version of the above function. It reads its input from every Nth sample.
|
||||
* */
|
||||
void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride);
|
||||
|
||||
/* If kiss_fft_alloc allocated a buffer, it is one contiguous
|
||||
buffer and can be simply free()d when no longer needed*/
|
||||
#define kiss_fft_free free
|
||||
|
||||
/*
|
||||
Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up
|
||||
your compiler output to call this before you exit.
|
||||
*/
|
||||
void kiss_fft_cleanup(void);
|
||||
|
||||
|
||||
/*
|
||||
* Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5)
|
||||
*/
|
||||
int kiss_fft_next_fast_size(int n);
|
||||
|
||||
/* for real ffts, we need an even size */
|
||||
#define kiss_fftr_next_fast_size_real(n) \
|
||||
(kiss_fft_next_fast_size( ((n)+1)>>1)<<1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
46
3rdparty/freesurround/include/kiss_fftr.h
vendored
Normal file
46
3rdparty/freesurround/include/kiss_fftr.h
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef KISS_FTR_H
|
||||
#define KISS_FTR_H
|
||||
|
||||
#include "kiss_fft.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Real optimized version can save about 45% cpu time vs. complex fft of a real seq.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
typedef struct kiss_fftr_state *kiss_fftr_cfg;
|
||||
|
||||
|
||||
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem);
|
||||
/*
|
||||
nfft must be even
|
||||
|
||||
If you don't care to allocate space, use mem = lenmem = NULL
|
||||
*/
|
||||
|
||||
|
||||
void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata);
|
||||
/*
|
||||
input timedata has nfft scalar points
|
||||
output freqdata has nfft/2+1 complex points
|
||||
*/
|
||||
|
||||
void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata);
|
||||
/*
|
||||
input freqdata has nfft/2+1 complex points
|
||||
output timedata has nfft scalar points
|
||||
*/
|
||||
|
||||
#define kiss_fftr_free free
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user