for (int i = 0; i < 64; i++) { fir64Coff[i] = (double_t)(1 << 10); //Hanning Window (less noise than hamming? fir64Coff[i] *= 0.5 * (1 - cos((2 * M_PI * i)/ (64 - 1))); //Hamming Window // fir64Coff[i] *= 0.54 - 0.46 * cos((2 * M_PI * i) / (64 - 1)); //Nuttall Window // fir64Coff[i] *= 0.355768f - 0.487396*cos((2*M_PI*i)/(64 -1)) + 0.144232*cos((4*M_PI*i)/(64-1))-0.012604*cos((6*M_PI*i)/(64-1)); //Cosine Window // fir64Coff[i] *= sin((M_PI * i)/(64-1)); //Blackman Harris // double_t w = (2 * M_PI * i) / 64; // fir64Coff[i] *= 0.422323 - 0.49755 * cos(w) + 0.07922 * cos(2 * w); }

- (uint64_t)getBytes:(void *)buffer sampleCount:(long unsigned)count { if (mIsEndOfSong) { return 0; } [mutex lock]; int16_t *sampleBuffer = (int16_t *)buffer; for (uint32_t currentSample = 0; currentSample < count; currentSample++) { uint64_t testLeft = 0; uint64_t testRight = 0; int64_t sumLeft = 0; int64_t sumRight = 0; uint8_t coefficientIndex = 0; for (uint8_t i = 0; i < 8; i++) { if (currentBufferPos >= blockSize) { if (![self readChunk]) { //Here I fetch left and right channel blockSize bytes (Usually 4096) [mutex unlock]; return currentSample; } } testLeft = bufferLeft[currentBufferPos]; testRight = bufferRight[currentBufferPos]; for (uint8_t i = 0; i < 8; i++) { //Two nested for loops, 8 * 8 = 64 bits, lsb first per byte if ((testLeft & 0x01) == 0x01) { sumLeft += fir64Coff[coefficientIndex]; //These are the pre-calculated window values } else { sumLeft -= fir64Coff[coefficientIndex]; } if ((testRight & 0x01) == 0x01) { sumRight += fir64Coff[coefficientIndex]; } else { sumRight -= fir64Coff[coefficientIndex]; } testLeft >>= 1; //Next bit testRight >>= 1; coefficientIndex++; } currentBufferPos++; //next byte } sampleBuffer[(currentSample << 1) + 0] = (int16_t)sumLeft; sampleBuffer[(currentSample << 1) + 1] = (int16_t)sumRight; } [mutex unlock]; return count; }

- (void)lowPassFIR:(double_t*)firBuffer withSampleRate:(uint64_t)Fs cutOffFrequency:(uint64_t)Fc filterLength:(uint64_t)M { M = M -1; double_t Ft = (double_t)Fc / (double_t)Fs; double_t sum = 0.0f; for (uint64_t i = 0; i < M; i++) { if (i != ((double_t)M / 2)) { firBuffer[i] *= sin(2.0f * M_PI * Ft * (i - ((double_t)M / 2.0f))) / (M_PI * (i - ((double_t)M / 2.0f))); } else { firBuffer[i] *= 2.0f * Ft; } sum += firBuffer[i]; printf("%f\n", firBuffer[i]); } printf("Sum: %f\n", sum); }

**Edited by aregee, 01 September 2014 - 09:15 PM.**