virtual IAudioBuffer *get(unsigned long pos, unsigned int length) noexcept{ sptr<IAudioInfo> info(getInfo()); AudioBuffer *ret = new AudioBuffer(info->getChannels(), length, pos, info->getSamplerate()); unsigned int validInputs = 0; if(NumInputs() > 0){ for(int i = 0; i < NumInputs(); i++){ if(!InputOk(i)) continue; validInputs++; auto tmp = getFromSlot(i, pos, length); for(unsigned int j = 0; j < length; j++){ sptr<ISample> smp1(ret->get(j)); auto smp2 = getSampleFromBuffer(j, tmp); *smp1 += *smp2; ret->set(*smp1, j); } } for(unsigned int j = 0; j < length; j++){ sptr<ISample> smp(ret->get(j)); if(validInputs > 0) *smp /= (float)validInputs; ret->set(*smp, j); } } return ret; };
void Performance::measure(unsigned long length, unsigned int buflen){ if(NumInputs() == 0){ std::cout << "invalid or no Input" << std::endl; return; } double val = 0; std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); for(unsigned int i = 0; i < length; i += buflen){ if(i + buflen > length) buflen -= i + buflen - length; AudioBuffer tmp = getFromSlot(i, buflen, 0); for(unsigned int j = 0; j < buflen; j++){ val += tmp.get(j).get(0); } } std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); auto time = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count(); std::cout << "Buffer size: " << buflen << ", total Samples: " << length << ", "; std::cout << "Time used: " << time << "us, " << time / 1000000 << "s, Final value: " << val << std::endl; return; }