hendriks73 / jipes

Open source library that allows you to efficiently compute audio features.
GNU Lesser General Public License v2.1
32 stars 9 forks source link

ConstantQ #2

Open Murivan opened 5 months ago

Murivan commented 5 months ago

I am having some issues with the ConstantQ Transform. By analyzing the same file with the same chain, but with different min and max frequencies I am getting results that don't seem to be consistent.

This is a minimal example: SignalSource source = new AudioSignalSource(new File("test.wav"));

    int windowLength = 2048;
    WindowFunction windowFunction = new WindowFunction.Hamming(windowLength);

    int hopSize = 1024;
    float minFrequency = 8.1757f;
    float maxFrequency = 12543.853f;
    int binsPerSemitone = 1;

    SignalPump<AudioBuffer> pump = new SignalPump<>(source);
    SignalPipeline<AudioBuffer, LogFrequencySpectrum> cqtPipeline = new SignalPipeline<>(
            new Mono(),                                             // if there are more than one channel, reduce them to mono
            new SlidingWindow(windowFunction.getLength(), hopSize),
            new Mapping<>(AudioBufferFunctions.createMapFunction(windowFunction)),
            new ConstantQTransform(minFrequency, maxFrequency, 12 * binsPerSemitone),
            new AbstractSignalProcessor<LogFrequencySpectrum, ArrayList<LogFrequencySpectrum>>("specID") {  // aggregate the CQTs to a spectrum with id "specID" (needed to access it in the results)
                private final ArrayList<LogFrequencySpectrum> spectrogram = new ArrayList<>();

                @Override
                protected ArrayList<LogFrequencySpectrum> processNext(LogFrequencySpectrum input) throws IOException {
                    this.spectrogram.add(input);
                    return this.spectrogram;
                }
            }
    );
    pump.add(cqtPipeline);
    Map<Object, Object> results = pump.pump();
    ArrayList<LogFrequencySpectrum> result = (ArrayList<LogFrequencySpectrum>) results.get("specID");

Thanks for helping.

hendriks73 commented 5 months ago

What's the expected outcome and what's the actual outcome?

Murivan commented 5 months ago

I was expecting that running it with float minFrequency = 8.1757f; float maxFrequency = 12543.853f;

and with float minFrequency = 8.1757f; float maxFrequency = 2093.00f;

would give me, minus the numerical approximations, the same results for the bins that exist in both CQTs. However the results are different.