KRDSP abstraction WIP
This commit is contained in:
@@ -244,7 +244,7 @@ void KRAudioManager::renderReverbImpulseResponse(int impulse_response_offset, in
|
|||||||
memset(reverb_sample_data_complex.realp + frame_count, 0, frame_count * sizeof(float));
|
memset(reverb_sample_data_complex.realp + frame_count, 0, frame_count * sizeof(float));
|
||||||
memset(reverb_sample_data_complex.imagp, 0, fft_size * sizeof(float));
|
memset(reverb_sample_data_complex.imagp, 0, fft_size * sizeof(float));
|
||||||
|
|
||||||
vDSP_fft_zip(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], &reverb_sample_data_complex, 1, fft_size_log2, kFFTDirection_Forward);
|
KRDSP::FFTForward(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], &reverb_sample_data_complex, fft_size_log2);
|
||||||
|
|
||||||
float scale = 0.5f / fft_size;
|
float scale = 0.5f / fft_size;
|
||||||
|
|
||||||
@@ -273,9 +273,9 @@ void KRAudioManager::renderReverbImpulseResponse(int impulse_response_offset, in
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
vDSP_fft_zip(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], &impulse_block_data_complex, 1, fft_size_log2, kFFTDirection_Forward);
|
KRDSP::FFTForward(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], &impulse_block_data_complex, fft_size_log2);
|
||||||
KRDSP::Multiply(&reverb_sample_data_complex, &impulse_block_data_complex, &conv_data_complex, fft_size);
|
KRDSP::Multiply(&reverb_sample_data_complex, &impulse_block_data_complex, &conv_data_complex, fft_size);
|
||||||
vDSP_fft_zip(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], &conv_data_complex, 1, fft_size_log2, kFFTDirection_Inverse);
|
KRDSP::FFTInverse(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], &conv_data_complex, fft_size_log2);
|
||||||
KRDSP::Scale(conv_data_complex.realp, scale, fft_size);
|
KRDSP::Scale(conv_data_complex.realp, scale, fft_size);
|
||||||
|
|
||||||
|
|
||||||
@@ -834,7 +834,7 @@ void KRAudioManager::initHRTF()
|
|||||||
sample->sample(0, 128, channel, spectral.realp, 1.0f, false);
|
sample->sample(0, 128, channel, spectral.realp, 1.0f, false);
|
||||||
memset(spectral.realp + 128, 0, sizeof(float) * 128);
|
memset(spectral.realp + 128, 0, sizeof(float) * 128);
|
||||||
memset(spectral.imagp, 0, sizeof(float) * 256);
|
memset(spectral.imagp, 0, sizeof(float) * 256);
|
||||||
vDSP_fft_zip(m_fft_setup[8 - KRENGINE_AUDIO_BLOCK_LOG2N], &spectral, 1, 8, kFFTDirection_Forward);
|
KRDSP::FFTForward(m_fft_setup[8 - KRENGINE_AUDIO_BLOCK_LOG2N], &spectral, 8);
|
||||||
m_hrtf_spectral[channel][pos] = spectral;
|
m_hrtf_spectral[channel][pos] = spectral;
|
||||||
}
|
}
|
||||||
sample_index++;
|
sample_index++;
|
||||||
@@ -1041,7 +1041,7 @@ void KRAudioManager::initAudio()
|
|||||||
|
|
||||||
m_reverb_sequence = 0;
|
m_reverb_sequence = 0;
|
||||||
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
||||||
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = vDSP_create_fftsetup( KRENGINE_REVERB_MAX_FFT_LOG2, kFFTRadix2);
|
KRDSP::CreateFFTWorkspace(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N], KRENGINE_REVERB_MAX_FFT_LOG2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----====---- Initialize HRTF Engine ----====----
|
// ----====---- Initialize HRTF Engine ----====----
|
||||||
@@ -1203,15 +1203,12 @@ void KRAudioManager::cleanupAudio()
|
|||||||
m_reverb_impulse_responses_weight[i] = 0.0f;
|
m_reverb_impulse_responses_weight[i] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
// Apple vDSP
|
|
||||||
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
for(int i=KRENGINE_AUDIO_BLOCK_LOG2N; i <= KRENGINE_REVERB_MAX_FFT_LOG2; i++) {
|
||||||
if(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]) {
|
if(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]) {
|
||||||
vDSP_destroy_fftsetup(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]);
|
KRDSP::DestroyFFTWorkspace(m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N]);
|
||||||
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = NULL;
|
m_fft_setup[i - KRENGINE_AUDIO_BLOCK_LOG2N] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAudioManager::~KRAudioManager()
|
KRAudioManager::~KRAudioManager()
|
||||||
@@ -1359,7 +1356,11 @@ KRAudioBuffer *KRAudioManager::getBuffer(KRAudioSample &audio_sample, int buffer
|
|||||||
// ----====---- Make room in the cache for a new buffer ----====----
|
// ----====---- Make room in the cache for a new buffer ----====----
|
||||||
if(m_bufferCache.size() >= KRENGINE_AUDIO_MAX_POOL_SIZE) {
|
if(m_bufferCache.size() >= KRENGINE_AUDIO_MAX_POOL_SIZE) {
|
||||||
// delete a random entry from the cache
|
// delete a random entry from the cache
|
||||||
|
#ifdef __APPLE__
|
||||||
int index_to_delete = arc4random() % m_bufferCache.size();
|
int index_to_delete = arc4random() % m_bufferCache.size();
|
||||||
|
#else
|
||||||
|
int index_to_delete = rand() % m_bufferCache.size();
|
||||||
|
#endif
|
||||||
std::vector<KRAudioBuffer *>::iterator itr_to_delete = m_bufferCache.begin() + index_to_delete;
|
std::vector<KRAudioBuffer *>::iterator itr_to_delete = m_bufferCache.begin() + index_to_delete;
|
||||||
delete *itr_to_delete;
|
delete *itr_to_delete;
|
||||||
m_bufferCache.erase(itr_to_delete);
|
m_bufferCache.erase(itr_to_delete);
|
||||||
@@ -1675,13 +1676,9 @@ void KRAudioManager::renderHRTF()
|
|||||||
|
|
||||||
float scale = 0.5f / fft_size;
|
float scale = 0.5f / fft_size;
|
||||||
|
|
||||||
vDSP_fft_zip(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N],
|
KRDSP::FFTForward(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], hrtf_sample, fft_size_log2);
|
||||||
hrtf_sample, 1,
|
|
||||||
fft_size_log2, kFFTDirection_Forward);
|
|
||||||
KRDSP::Multiply(hrtf_sample, &hrtf_spectral, hrtf_convolved, fft_size);
|
KRDSP::Multiply(hrtf_sample, &hrtf_spectral, hrtf_convolved, fft_size);
|
||||||
vDSP_fft_zip(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N],
|
KRDSP::FFTInverse(m_fft_setup[fft_size_log2 - KRENGINE_AUDIO_BLOCK_LOG2N], hrtf_convolved, fft_size_log2);
|
||||||
hrtf_convolved, 1,
|
|
||||||
fft_size_log2, kFFTDirection_Inverse);
|
|
||||||
KRDSP::Scale(hrtf_convolved->realp, scale, fft_size);
|
KRDSP::Scale(hrtf_convolved->realp, scale, fft_size);
|
||||||
|
|
||||||
int output_offset = (m_output_accumulation_block_start) % (KRENGINE_REVERB_MAX_SAMPLES * KRENGINE_MAX_OUTPUT_CHANNELS);
|
int output_offset = (m_output_accumulation_block_start) % (KRENGINE_REVERB_MAX_SAMPLES * KRENGINE_MAX_OUTPUT_CHANNELS);
|
||||||
|
|||||||
@@ -197,10 +197,7 @@ private:
|
|||||||
void renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData);
|
void renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE__
|
KRDSP::FFTWorkspace m_fft_setup[KRENGINE_REVERB_MAX_FFT_LOG2 - KRENGINE_AUDIO_BLOCK_LOG2N + 1];
|
||||||
// Apple vDSP
|
|
||||||
FFTSetup m_fft_setup[KRENGINE_REVERB_MAX_FFT_LOG2 - KRENGINE_AUDIO_BLOCK_LOG2N + 1];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
__int64_t m_audio_frame; // Number of audio frames processed since the start of the application
|
__int64_t m_audio_frame; // Number of audio frames processed since the start of the application
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,43 @@
|
|||||||
|
|
||||||
namespace KRDSP {
|
namespace KRDSP {
|
||||||
|
|
||||||
|
|
||||||
|
void CreateFFTWorkspace(FFTWorkspace &workspace, size_t length)
|
||||||
|
{
|
||||||
|
#ifdef KRDSP_APPLE_VDSP
|
||||||
|
workspace = vDSP_create_fftsetup(length, kFFTRadix2);
|
||||||
|
#else
|
||||||
|
#error TODO - Implement
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void DestroyFFTWorkspace(FFTWorkspace &workspace)
|
||||||
|
{
|
||||||
|
#ifdef KRDSP_APPLE_VDSP
|
||||||
|
vDSP_destroy_fftsetup(workspace);
|
||||||
|
#else
|
||||||
|
#error TODO - Implement
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void FFTForward(const FFTWorkspace &workspace, SplitComplex *src, size_t count)
|
||||||
|
{
|
||||||
|
#ifdef KRDSP_APPLE_VDSP
|
||||||
|
vDSP_fft_zip(workspace, src, 1, count, kFFTDirection_Forward);
|
||||||
|
#else
|
||||||
|
#error TODO - Implement
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void FFTInverse(const FFTWorkspace &workspace, SplitComplex *src, size_t count)
|
||||||
|
{
|
||||||
|
#ifdef KRDSP_APPLE_VDSP
|
||||||
|
vDSP_fft_zip(workspace, src, 1, count, kFFTDirection_Inverse);
|
||||||
|
#else
|
||||||
|
#error TODO - Implement
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Int16ToFloat(const short *src, size_t srcStride, float *dest, size_t destStride, size_t count)
|
void Int16ToFloat(const short *src, size_t srcStride, float *dest, size_t destStride, size_t count)
|
||||||
{
|
{
|
||||||
#ifdef KRDSP_APPLE_VDSP
|
#ifdef KRDSP_APPLE_VDSP
|
||||||
|
|||||||
@@ -37,13 +37,20 @@ namespace KRDSP {
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// Apple vDSP
|
// Apple vDSP
|
||||||
typedef DSPSplitComplex SplitComplex;
|
typedef DSPSplitComplex SplitComplex;
|
||||||
|
typedef FFTSetup FFTWorkspace;
|
||||||
#else
|
#else
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float *realp;
|
float *realp;
|
||||||
float *imagp;
|
float *imagp;
|
||||||
} SplitComplex;
|
} SplitComplex;
|
||||||
|
|
||||||
|
typedef int FFTWorkspace; // FINDME!! KIP!! TODO!! IMPLEMENT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void CreateFFTWorkspace(FFTWorkspace &workspace, size_t length);
|
||||||
|
void DestroyFFTWorkspace(FFTWorkspace &workspace);
|
||||||
|
void FFTForward(const FFTWorkspace &workspace, SplitComplex *src, size_t count);
|
||||||
|
void FFTInverse(const FFTWorkspace &workspace, SplitComplex *src, size_t count);
|
||||||
void Int16ToFloat(const short *src, size_t srcStride, float *dest, size_t destStride, size_t count);
|
void Int16ToFloat(const short *src, size_t srcStride, float *dest, size_t destStride, size_t count);
|
||||||
void Scale(float *buffer, float scale, size_t count);
|
void Scale(float *buffer, float scale, size_t count);
|
||||||
void ScaleCopy(const float *src, float scale, float *dest, size_t count);
|
void ScaleCopy(const float *src, float scale, float *dest, size_t count);
|
||||||
|
|||||||
Reference in New Issue
Block a user