i have also some ideas
- multiply method to multiplie all values, with another AudioSampleBuffer (with SSE)
- virtual destructor (to be able to use dynamic C++ features)
- an accumulate function, to sum all values (this is also very helpful to detect NANs in the buffer)
Here some very fast SSE3 code inspired by http://fastcpp.blogspot.de/2011/04/how-to-process-stl-vector-using-sse.html (with Non-SSE fallback)
float accumulate( const float *p, int N) { if (isSSE3Available()) { __m128 mmSum = _mm_setzero_ps(); int i = 0; int rounddown = N - ( N % 16 ); for(; i < rounddown ; i+=16) { __m128 v0 = _mm_loadu_ps(p + i + 0); __m128 v1 = _mm_loadu_ps(p + i + 4); __m128 s01 = _mm_add_ps(v0, v1); __m128 v2 = _mm_loadu_ps(p + i + 8); __m128 v3 = _mm_loadu_ps(p + i + 12); __m128 s23 = _mm_add_ps(v2, v3); mmSum = _mm_add_ps(mmSum, s01); mmSum = _mm_add_ps(mmSum, s23); } // add up single values until all elements are covered for(; i < N; i++) { mmSum = _mm_add_ss(mmSum, _mm_load_ss(p + i)); } // add up the four float values from mmSum into a single value and return mmSum = _mm_hadd_ps(mmSum, mmSum); mmSum = _mm_hadd_ps(mmSum, mmSum); return _mm_cvtss_f32(mmSum); } else { float s=0; const float* e = p + N; while (p!=e) { s+=*p; p++; } return s; }; } bool AudioSampleBufferTools::containsNANs( AudioSampleBuffer & asb ) { for (int c=0; c<asb.getNumChannels(); c++) { float v=accumulate(asb.getReadPointer(c),asb.getNumSamples()); if (!(v==v)) { return true; }; }; return false; }