Compare commits
4 commits
c231a9097e
...
90cc6ba034
Author | SHA1 | Date | |
---|---|---|---|
|
90cc6ba034 | ||
|
d7e47f31d6 | ||
|
b2c4906ea8 | ||
|
598fd814e4 |
3 changed files with 26 additions and 10 deletions
15
Audio/ThirdParty/deadbeef/fft_accelerate.c
vendored
15
Audio/ThirdParty/deadbeef/fft_accelerate.c
vendored
|
@ -60,19 +60,24 @@ static void
|
||||||
_init_buffers(int fft_size) {
|
_init_buffers(int fft_size) {
|
||||||
if(fft_size != _fft_size) {
|
if(fft_size != _fft_size) {
|
||||||
fft_free();
|
fft_free();
|
||||||
|
_fft_size = 0;
|
||||||
|
|
||||||
_dftSetup = vDSP_DFT_zrop_CreateSetup(NULL, fft_size * 2, vDSP_DFT_FORWARD);
|
_dftSetup = vDSP_DFT_zrop_CreateSetup(NULL, fft_size * 2, vDSP_DFT_FORWARD);
|
||||||
|
if(!_dftSetup) return;
|
||||||
|
|
||||||
_dftBuffer.realp = _memalign_calloc(fft_size, sizeof(Float32), 16);
|
_dftBuffer.realp = _memalign_calloc(fft_size, sizeof(Float32), 16);
|
||||||
_dftBuffer.imagp = _memalign_calloc(fft_size, sizeof(Float32), 16);
|
_dftBuffer.imagp = _memalign_calloc(fft_size, sizeof(Float32), 16);
|
||||||
|
if(!_dftBuffer.realp || !_dftBuffer.imagp) return;
|
||||||
|
|
||||||
_window = _memalign_calloc(fft_size * 2, sizeof(Float32), 16);
|
_window = _memalign_calloc(fft_size * 2, sizeof(Float32), 16);
|
||||||
|
if(!_window) return;
|
||||||
vDSP_blkman_window(_window, fft_size * 2, 0);
|
vDSP_blkman_window(_window, fft_size * 2, 0);
|
||||||
|
|
||||||
Float32 normFactor = 2.0f / (fft_size * 2);
|
Float32 normFactor = 2.0f / (fft_size * 2);
|
||||||
vDSP_vsmul(_window, 1, &normFactor, _window, 1, fft_size * 2);
|
vDSP_vsmul(_window, 1, &normFactor, _window, 1, fft_size * 2);
|
||||||
|
|
||||||
_rawSpectrum = (struct SpectrumData *) _memalign_calloc(sizeof(struct SpectrumData) + sizeof(Float32) * fft_size, 1, 16);
|
_rawSpectrum = (struct SpectrumData *) _memalign_calloc(sizeof(struct SpectrumData) + sizeof(Float32) * fft_size, 1, 16);
|
||||||
|
if(!_rawSpectrum) return;
|
||||||
_rawSpectrum->length = fft_size;
|
_rawSpectrum->length = fft_size;
|
||||||
|
|
||||||
_fft_size = fft_size;
|
_fft_size = fft_size;
|
||||||
|
@ -80,7 +85,14 @@ _init_buffers(int fft_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void fft_calculate(const float *data, float *freq, int fft_size) {
|
void fft_calculate(const float *data, float *freq, int fft_size) {
|
||||||
|
if(!freq || !fft_size) return;
|
||||||
_init_buffers(fft_size);
|
_init_buffers(fft_size);
|
||||||
|
if(!_fft_size || !data) {
|
||||||
|
// Decibels
|
||||||
|
float kZeroLevel = -128.0;
|
||||||
|
vDSP_vfill(&kZeroLevel, freq, 1, fft_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Split the waveform
|
// Split the waveform
|
||||||
DSPSplitComplex dest = { _dftBuffer.realp, _dftBuffer.imagp };
|
DSPSplitComplex dest = { _dftBuffer.realp, _dftBuffer.imagp };
|
||||||
|
@ -111,7 +123,7 @@ void fft_calculate(const float *data, float *freq, int fft_size) {
|
||||||
cblas_scopy(fft_size, rawSpectrum, 1, freq, 1);
|
cblas_scopy(fft_size, rawSpectrum, 1, freq, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fft_free(void) {
|
void __attribute__((destructor)) fft_free(void) {
|
||||||
free(_dftBuffer.realp);
|
free(_dftBuffer.realp);
|
||||||
free(_dftBuffer.imagp);
|
free(_dftBuffer.imagp);
|
||||||
free(_window);
|
free(_window);
|
||||||
|
@ -123,4 +135,5 @@ void fft_free(void) {
|
||||||
_dftBuffer.imagp = NULL;
|
_dftBuffer.imagp = NULL;
|
||||||
_window = NULL;
|
_window = NULL;
|
||||||
_rawSpectrum = NULL;
|
_rawSpectrum = NULL;
|
||||||
|
_dftSetup = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
|
#import <Accelerate/Accelerate.h>
|
||||||
|
|
||||||
#import "analyzer.h"
|
#import "analyzer.h"
|
||||||
|
|
||||||
#import "Logging.h"
|
#import "Logging.h"
|
||||||
|
@ -416,16 +418,14 @@ extern NSString *CogPlaybackDidStopNotificiation;
|
||||||
for(int i = 0; i < 11; ++i) {
|
for(int i = 0; i < 11; ++i) {
|
||||||
float maxValue = 0.0;
|
float maxValue = 0.0;
|
||||||
float maxMax = 0.0;
|
float maxMax = 0.0;
|
||||||
for(int j = 0; j < maxBars; ++j) {
|
{
|
||||||
const int barBase = i * barStep;
|
const int barBase = i * barStep;
|
||||||
const int barIndex = barBase + j;
|
const int barEnd = (barBase + maxBars) <= _draw_data.bar_count ? (barBase + maxBars) : _draw_data.bar_count;
|
||||||
if(barIndex < _draw_data.bar_count) {
|
{
|
||||||
if(bar[barIndex].bar_height > maxValue) {
|
const int stride = sizeof(ddb_analyzer_draw_bar_t) / sizeof(Float32);
|
||||||
maxValue = bar[barIndex].bar_height;
|
const int barCount = barEnd - barBase + 1;
|
||||||
}
|
vDSP_maxv(&bar[barBase].bar_height, stride, &maxValue, barCount);
|
||||||
if(bar[barIndex].peak_ypos > maxMax) {
|
vDSP_maxv(&bar[barBase].peak_ypos, stride, &maxMax, barCount);
|
||||||
maxMax = bar[barIndex].peak_ypos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SCNNode *node = nodes[i + 1];
|
SCNNode *node = nodes[i + 1];
|
||||||
|
|
3
Visualization/ThirdParty/deadbeef/analyzer.h
vendored
3
Visualization/ThirdParty/deadbeef/analyzer.h
vendored
|
@ -23,6 +23,8 @@
|
||||||
#ifndef analyzer_h
|
#ifndef analyzer_h
|
||||||
#define analyzer_h
|
#define analyzer_h
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,6 +54,7 @@ typedef struct {
|
||||||
float xpos;
|
float xpos;
|
||||||
float peak_ypos;
|
float peak_ypos;
|
||||||
float bar_height;
|
float bar_height;
|
||||||
|
uint32_t unused;
|
||||||
} ddb_analyzer_draw_bar_t;
|
} ddb_analyzer_draw_bar_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in a new issue