Permalink
Browse files

added an override for the forward(float[], int startAt) to FFT and an…

… additional version of apply to the window function to support it.
  • Loading branch information...
1 parent ecdf887 commit fe7fb88241537dbcca7b6971656888b991a0ac98 Damien Di Fede committed Apr 12, 2011
View
Binary file not shown.
View
Binary file not shown.
@@ -72,14 +72,11 @@ public void scaleBand(int i, float s)
Minim.error("Can't scale a frequency band by a negative value.");
return;
}
- if (spectrum[i] != 0)
- {
- real[i] /= spectrum[i];
- imag[i] /= spectrum[i];
- spectrum[i] *= s;
- real[i] *= spectrum[i];
- imag[i] *= spectrum[i];
- }
+
+ real[i] *= s;
+ imag[i] *= s;
+ spectrum[i] *= s;
+
if (i != 0 && i != timeSize / 2)
{
real[timeSize - i] = real[i];
@@ -159,12 +156,29 @@ public void forward(float[] buffer)
}
doWindow(buffer);
// copy samples to real/imag in bit-reversed order
- bitReverseSamples(buffer);
+ bitReverseSamples(buffer, 0);
// perform the fft
fft();
// fill the spectrum buffer with amplitudes
fillSpectrum();
}
+
+ @Override
+ public void forward(float[] buffer, int startAt)
+ {
+ if ( buffer.length - startAt < timeSize )
+ {
+ Minim.error( "FourierTransform.forward: not enough samples in the buffer between " +
+ startAt + " and " + buffer.length + " to perform a transform."
+ );
+ return;
+ }
+
+ windowFunction.apply( buffer, startAt, timeSize );
+ bitReverseSamples(buffer, startAt);
+ fft();
+ fillSpectrum();
+ }
/**
* Performs a forward transform on the passed buffers.
@@ -224,11 +238,11 @@ private void buildReverseTable()
// copies the values in the samples array into the real array
// in bit reversed order. the imag array is filled with zeros.
- private void bitReverseSamples(float[] samples)
+ private void bitReverseSamples(float[] samples, int startAt)
{
- for (int i = 0; i < samples.length; i++)
+ for (int i = 0; i < timeSize; ++i)
{
- real[i] = samples[reverse[i]];
+ real[i] = samples[ startAt + reverse[i] ];
imag[i] = 0.0f;
}
}
@@ -76,6 +76,21 @@ public void apply(float[] samples)
samples[n] *= value(samples.length, n);
}
}
+
+ /**
+ * Apply the window to a portion of this sample buffer,
+ * given an offset from the beginning of the buffer
+ * and the number of samples to be windowed.
+ */
+ public void apply(float[] samples, int offset, int length)
+ {
+ this.length = length;
+
+ for(int n = offset; n < offset + length; ++n)
+ {
+ samples[n] *= value(length, n - offset);
+ }
+ }
/**
* Generates the curve of the window function.

0 comments on commit fe7fb88

Please sign in to comment.