Created
October 29, 2016 20:23
-
-
Save dedmen/20619ed7a3df216e7c0df28573425200 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void process(short * samples, int channels, int sampleCount, TS3_VECTOR pos, float direction) | |
{ | |
for (int q = 0; q < channels * sampleCount; q++) | |
{ | |
input_buffer.push_back(samples[q]); //channels * sampleCount function calls | |
} | |
if (input_buffer.size() > clunk::Hrtf::WINDOW_SIZE * (unsigned int) channels * 2) | |
{ | |
const int to_process = (int) input_buffer.size(); | |
clunk::Buffer src(to_process * sizeof(short)); | |
short* src_s = new short[input_buffer.size()]; | |
for (int q = 0; q < to_process; q++) | |
{ | |
src_s[q] = input_buffer.at(0);//channels * sampleCount function calls | |
input_buffer.pop_front();//channels * sampleCount function calls | |
} | |
src.set_data(src_s, to_process * sizeof(short), true); | |
int output_size = to_process; | |
output_size -= clunk::Hrtf::WINDOW_SIZE * channels * 2; | |
short* dst_s = new short[output_size]; | |
memset(dst_s, 0, output_size * sizeof(short)); | |
clunk::Buffer dst(output_size * sizeof(short)); | |
dst.set_data(dst_s, output_size * sizeof(short), true); | |
int processed = hrft.process(SAMPLE_RATE, dst, channels, src, channels, clunk::v3f(x_, y_, z_), 1.0f); | |
for (int q = processed * channels; q < to_process; q++) | |
{ | |
input_buffer.push_back(src_s[q]);//channels*sampleCount - processed function calls | |
} | |
for (int q = 0; q < output_size; q++) | |
{ | |
output_buffer.push_back(dst_s[q]);//channels*sampleCount - 1024*channels function calls | |
} | |
} | |
int q = 0; | |
while (q < sampleCount * channels) | |
{ | |
if (output_buffer.size() > 0)//sampleCount * channels function calls | |
{ | |
samples[q] = output_buffer.at(0);//MAX(sampleCount * channels,output_buffer.size()) function calls | |
output_buffer.pop_front();//MAX(sampleCount * channels,output_buffer.size()) function calls | |
} | |
else | |
{ | |
samples[q] = 0; | |
} | |
q++; | |
} | |
} | |
//optimized | |
void process(short * samples, int channels, int sampleCount, Direction3D pos, AngleRadians direction) | |
{ | |
input_buffer.insert(input_buffer.end(), samples, samples + (sampleCount*channels)); | |
if (input_buffer.size() > clunk::Hrtf::WINDOW_SIZE * channels * 2) | |
{ | |
const int to_process = (int) input_buffer.size(); | |
clunk::Buffer src(to_process * sizeof(short)); | |
src.set_data(input_buffer.data(), to_process * sizeof(short), false);//This is used as const so we can just pass input_buffers data ptr | |
int output_size = to_process - clunk::Hrtf::WINDOW_SIZE * channels * 2; | |
short* dst_s = new short[output_size]; //Will be owned by clunk::Buffer which takes care of deleting | |
memset(dst_s, 0, output_size * sizeof(short)); | |
clunk::Buffer dst(output_size * sizeof(short)); | |
dst.set_data(dst_s, output_size * sizeof(short), true); | |
int processed = hrft.process(SAMPLE_RATE, dst, channels, src, channels, clunk::v3f(x_, y_, z_), 1.0f); | |
input_buffer.erase(input_buffer.begin(), input_buffer.begin() + processed * channels); //Erase processed data and keep leftover | |
output_buffer.insert(output_buffer.end(), dst_s, dst_s + output_size); | |
} | |
if (output_buffer.size() < sampleCount * channels) { | |
memset(samples, 0, sampleCount * channels * sizeof(short)); | |
} else { | |
memcpy(samples, output_buffer.data(), sampleCount * channels * sizeof(short)); | |
output_buffer.erase(output_buffer.begin(), output_buffer.begin() + sampleCount * channels); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment