### Progressive Key Estimation from Audio Stream
Source: https://mixxxdj.github.io/libkeyfinder/index.html
This example demonstrates progressive key estimation from an audio stream, suitable for real-time analysis or when audio is processed in packets. It utilizes a workspace for efficient memory management during analysis.
```cpp
KeyFinder::AudioData a;
a.setFrameRate(yourAudioStream.framerate);
a.setChannels(yourAudioStream.channels);
a.addToSampleCount(yourAudioStream.packetLength);
static KeyFinder::KeyFinder k;
// the workspace holds the memory allocations for analysis of a single track
KeyFinder::Workspace w;
while (someType yourPacket = newAudioPacket()) {
for (int i = 0; i < yourPacket.length; i++) {
a.setSample(i, yourPacket[i]);
}
k.progressiveChromagram(a, w);
// if you want to grab progressive key estimates...
KeyFinder::key_t key = k.keyOfChromagram(w);
doSomethingWithMostRecentKeyEstimate(key);
}
// if you only want a single key estimate, or to squeeze
// every last bit of audio from the working buffer after
// progressive estimates...
k.finalChromagram(w);
// and finally...
KeyFinder::key key = k.keyOfChromagram(w);
doSomethingWithFinalKeyEstimate(key);
```
--------------------------------
### Basic Key Estimation
Source: https://mixxxdj.github.io/libkeyfinder/index.html
Use this snippet for a straightforward estimation of the musical key from a complete audio stream. Ensure KeyFinder and AudioData objects are properly initialized and populated with audio data.
```cpp
// Static because it retains useful resources for repeat use
static KeyFinder::KeyFinder k;
// Build an empty audio object
KeyFinder::AudioData a;
// Prepare the object for your audio stream
a.setFrameRate(yourAudioStream.framerate);
a.setChannels(yourAudioStream.channels);
a.addToSampleCount(yourAudioStream.length);
// Copy your audio into the object
for (int i = 0; i < yourAudioStream.length; i++) {
a.setSample(i, yourAudioStream[i]);
}
// Run the analysis
KeyFinder::key_t key = k.keyOfAudio(a);
// And do something with the result
doSomethingWith(key);
```
--------------------------------
### execute
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter.html
Executes the Fast Fourier Transform on the input data.
```APIDOC
## execute()
### Description
Executes the Fast Fourier Transform on the input data.
### Method
POST
### Endpoint
/FftAdapter/execute
```
--------------------------------
### KeyFinder::AudioData Methods
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1AudioData-members.html
This section details the various methods available for interacting with AudioData objects, including methods for modifying frame and sample counts, manipulating iterators, appending and prepending data, discarding or slicing samples, downsampling, reducing to mono, and accessing or setting audio samples.
```APIDOC
## KeyFinder::AudioData Methods
### Description
Provides a comprehensive list of methods for managing and querying audio data. These methods allow for manipulation of audio buffers, iteration control, and data transformation.
### Methods
- **addToFrameCount**(unsigned int newFrames)
- Description: Adds a specified number of frames to the audio data.
- **addToSampleCount**(unsigned int newSamples)
- Description: Adds a specified number of samples to the audio data.
- **advanceReadIterator**(unsigned int by=1)
- Description: Advances the read iterator by a specified number of frames.
- **advanceWriteIterator**(unsigned int by=1)
- Description: Advances the write iterator by a specified number of frames.
- **append**(const AudioData &that)
- Description: Appends the contents of another AudioData object to the current one.
- **AudioData**()
- Description: Default constructor for the AudioData class.
- **discardFramesFromFront**(unsigned int discardFrameCount)
- Description: Removes a specified number of frames from the beginning of the audio data.
- **downsample**(unsigned int factor, bool shortcut=true)
- Description: Reduces the sample rate of the audio data by a given factor.
- **getChannels**() const
- Description: Returns the number of audio channels.
- **getFrameCount**() const
- Description: Returns the total number of frames in the audio data.
- **getFrameRate**() const
- Description: Returns the frame rate (sample rate) of the audio data.
- **getSample**(unsigned int index) const
- Description: Retrieves a sample at a specific index.
- **getSampleAtReadIterator**() const
- Description: Retrieves the sample at the current read iterator position.
- **getSampleByFrame**(unsigned int frame, unsigned int channel) const
- Description: Retrieves a sample at a specific frame and channel.
- **getSampleCount**() const
- Description: Returns the total number of samples in the audio data.
- **prepend**(const AudioData &that)
- Description: Prepends the contents of another AudioData object to the current one.
- **readIteratorWithinUpperBound**() const
- Description: Checks if the read iterator is within the valid bounds.
- **reduceToMono**()
- Description: Converts the audio data to mono.
- **resetIterators**()
- Description: Resets both the read and write iterators to the beginning.
- **setChannels**(unsigned int newChannels)
- Description: Sets the number of audio channels.
- **setFrameRate**(unsigned int newFrameRate)
- Description: Sets the frame rate (sample rate) of the audio data.
- **setSample**(unsigned int index, double value)
- Description: Sets a sample at a specific index to a given value.
- **setSampleAtWriteIterator**(double value)
- Description: Sets the sample at the current write iterator position to a given value.
- **setSampleByFrame**(unsigned int frame, unsigned int channels, double value)
- Description: Sets a sample at a specific frame and channel to a given value.
- **sliceSamplesFromBack**(unsigned int sliceSampleCount)
- Description: Extracts a specified number of samples from the end of the audio data.
- **writeIteratorWithinUpperBound**() const
- Description: Checks if the write iterator is within the valid bounds.
```
--------------------------------
### collapseToOneHop
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1Chromagram.html
Collapses the chromagram data into a single hop representation.
```APIDOC
## collapseToOneHop
### Description
Collapses the chromagram data into a single hop representation.
### Method
std::vector< double >
### Endpoint
N/A (Method within a class)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Response
#### Success Response (200)
* **Return Value** (std::vector< double >) - A vector representing the chromagram collapsed into one hop.
```
--------------------------------
### SpectrumAnalyser Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1SpectrumAnalyser-members.html
Constructs a SpectrumAnalyser object with the specified frame rate, ChromaTransformFactory, and TemporalWindowFactory.
```APIDOC
## SpectrumAnalyser Constructor
### Description
Initializes a new instance of the SpectrumAnalyser class.
### Method
Constructor
### Endpoint
N/A (C++ constructor)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```cpp
// Assuming ctFactory and twFactory are valid pointers to ChromaTransformFactory and TemporalWindowFactory respectively
unsigned int frameRate = 44100;
SpectrumAnalyser analyser(frameRate, ctFactory, twFactory);
```
### Response
#### Success Response
Initializes the SpectrumAnalyser object.
#### Response Example
N/A (Constructor)
```
--------------------------------
### AudioData Class Methods
Source: https://mixxxdj.github.io/libkeyfinder/audiodata_8h_source.html
Provides an overview of the methods available for interacting with AudioData objects, including getters, setters, and manipulation functions.
```APIDOC
## AudioData Class Methods
### Description
This class provides methods for managing and manipulating audio sample data. It includes functions to get and set audio properties like channels, frame rate, and individual samples, as well as methods for modifying the audio data itself.
### Methods
**Getters:**
- `unsigned int getChannels() const;`
- `unsigned int getFrameRate() const;`
- `double getSample(unsigned int index) const;`
- `double getSampleByFrame(unsigned int frame, unsigned int channel) const;`
- `double getSampleAtReadIterator() const;`
- `unsigned int getSampleCount() const;`
- `unsigned int getFrameCount() const;`
**Setters:**
- `void setChannels(unsigned int newChannels);`
- `void setFrameRate(unsigned int newFrameRate);`
- `void setSample(unsigned int index, double value);`
- `void setSampleByFrame(unsigned int frame, unsigned int channels, double value);`
- `void setSampleAtWriteIterator(double value);`
- `void addToSampleCount(unsigned int newSamples);`
- `void addToFrameCount(unsigned int newFrames);`
**Iterator and Data Manipulation:**
- `void advanceReadIterator(unsigned int by = 1);`
- `void advanceWriteIterator(unsigned int by = 1);`
- `bool readIteratorWithinUpperBound() const;`
- `bool writeIteratorWithinUpperBound() const;`
- `void resetIterators();`
- `void append(const AudioData& that);`
- `void prepend(const AudioData& that);`
- `void discardFramesFromFront(unsigned int discardFrameCount);`
- `void reduceToMono();`
- `void downsample(unsigned int factor, bool shortcut = true);`
- `AudioData* sliceSamplesFromBack(unsigned int sliceSampleCount);`
### Constructor
- `AudioData();`
### Parameters
- **`getSampleByFrame`**: `frame` (unsigned int), `channel` (unsigned int)
- **`setSampleByFrame`**: `frame` (unsigned int), `channels` (unsigned int), `value` (double)
- **`advanceReadIterator`**: `by` (unsigned int, optional, defaults to 1)
- **`advanceWriteIterator`**: `by` (unsigned int, optional, defaults to 1)
- **`discardFramesFromFront`**: `discardFrameCount` (unsigned int)
- **`downsample`**: `factor` (unsigned int), `shortcut` (bool, optional, defaults to true)
- **`sliceSamplesFromBack`**: `sliceSampleCount` (unsigned int)
### Return Values
- **Getters**: Return the corresponding property or sample value.
- **`advanceReadIterator`, `advanceWriteIterator`**: No return value.
- **`readIteratorWithinUpperBound`, `writeIteratorWithinUpperBound`**: Returns `true` if the iterator is within bounds, `false` otherwise.
- **`sliceSamplesFromBack`**: Returns a pointer to a new AudioData object containing the sliced samples.
```
--------------------------------
### LibKeyFinder License and Copyright
Source: https://mixxxdj.github.io/libkeyfinder/workspace_8h_source.html
This snippet contains the copyright notice and licensing information for the LibKeyFinder library, adhering to the GNU General Public License v3.
```c++
1 /*************************************************************************
2
3 Copyright 2011-2015 Ibrahim Sha'ath
4
5 This file is part of LibKeyFinder.
6
7 LibKeyFinder is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 LibKeyFinder is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with LibKeyFinder. If not, see .
19
20 *************************************************************************/
21
22 #ifndef WORKSPACE_H
23 #define WORKSPACE_H
24
25 #include "audiodata.h"
26 #include "binode.h"
27 #include "chromagram.h"
28 #include "fftadapter.h"
29
30 namespace KeyFinder {
31
32 class Workspace {
33 public:
34 Workspace();
35 ~Workspace();
36 AudioData remainderBuffer;
37 AudioData preprocessedBuffer;
38 Chromagram* chromagram;
39 FftAdapter* fftAdapter;
40 std::vector* lpfBuffer;
41 };
42
43 } // namespace KeyFinder
44
45 #endif // WORKSPACE_H
```
--------------------------------
### ChromaTransformFactory Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1ChromaTransformFactory-members.html
Constructs a ChromaTransformFactory object.
```APIDOC
## ChromaTransformFactory()
### Description
Constructs a new instance of the ChromaTransformFactory class.
### Method
Constructor
### Parameters
None
```
--------------------------------
### KeyFinder::InverseFftAdapter::getOutput
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter-members.html
Retrieves the output value for a given bin. This method is const.
```APIDOC
## getOutput(unsigned int bin) const
### Description
Retrieves the output value for a given bin.
### Method
(Not specified in source)
### Endpoint
(Not specified in source)
### Parameters
#### Path Parameters
- **bin** (unsigned int) - Description: The bin for which to retrieve the output.
### Request Example
(Not specified in source)
### Response
(Not specified in source)
```
--------------------------------
### TemporalWindowFactory Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1TemporalWindowFactory-members.html
Constructs a TemporalWindowFactory object. This is the default constructor for the KeyFinder::TemporalWindowFactory class.
```APIDOC
## TemporalWindowFactory()
### Description
Constructs a TemporalWindowFactory object. This is the default constructor for the KeyFinder::TemporalWindowFactory class.
### Method
KeyFinder::TemporalWindowFactory::TemporalWindowFactory
```
--------------------------------
### execute
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter.html
Executes the inverse Fast Fourier Transform calculation.
```APIDOC
## execute()
### Description
Performs the inverse Fast Fourier Transform using the input samples that have been set. The results are stored internally and can be retrieved using `getOutput`.
```
--------------------------------
### KeyFinder::InverseFftAdapter::InverseFftAdapter
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter-members.html
Constructor for the InverseFftAdapter class.
```APIDOC
## InverseFftAdapter(unsigned int frameSize)
### Description
Constructor for the InverseFftAdapter class.
### Method
(Not specified in source)
### Endpoint
(Not specified in source)
### Parameters
#### Path Parameters
- **frameSize** (unsigned int) - Description: The size of the frame.
### Request Example
(Not specified in source)
### Response
(Not specified in source)
```
--------------------------------
### ToneProfile Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1ToneProfile.html
Constructs a ToneProfile object with a custom profile.
```APIDOC
## ToneProfile Constructor
### Description
Constructs a ToneProfile object with a custom profile.
### Method
Constructor
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
* **customProfile** (const std::vector< double > &) - Description: A vector of doubles representing the custom tone profile.
```
--------------------------------
### KeyFinder Class Methods
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1KeyFinder.html
This section details the public member functions of the KeyFinder class that can be used to analyze audio and determine its musical key.
```APIDOC
## Public Member Functions
### `progressiveChromagram`
**Description**: Computes a progressive chromagram from audio data.
**Method**: void
**Parameters**:
- `audio` (AudioData) - The input audio data.
- `workspace` (Workspace&) - A reference to the workspace object to store intermediate results.
### `finalChromagram`
**Description**: Finalizes the chromagram computation.
**Method**: void
**Parameters**:
- `workspace` (Workspace&) - A reference to the workspace object.
### `keyOfChromagram`
**Description**: Estimates the musical key from a pre-computed chromagram.
**Method**: key_t
**Parameters**:
- `workspace` (const Workspace&) - A const reference to the workspace object containing the chromagram.
**Returns**: The estimated musical key.
### `keyOfAudio`
**Description**: Estimates the musical key directly from audio data.
**Method**: key_t
**Parameters**:
- `audio` (const AudioData&) - The input audio data.
**Returns**: The estimated musical key.
### `keyOfChromaVector`
**Description**: Estimates the musical key from a chroma vector using optional major and minor profile overrides.
**Method**: key_t
**Parameters**:
- `chromaVector` (const std::vector< double >&) - The input chroma vector.
- `overrideMajorProfile` (const std::vector< double >&) - An optional override for the major profile.
- `overrideMinorProfile` (const std::vector< double >&) - An optional override for the minor profile.
**Returns**: The estimated musical key.
```
--------------------------------
### KeyFinder::FftAdapter::getOutputReal
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter-members.html
Retrieves the real component of the FFT output for a specific bin.
```APIDOC
## KeyFinder::FftAdapter::getOutputReal
### Description
Retrieves the real component of the FFT output for a specific bin.
### Method
(Not specified in source, likely a member function call)
### Parameters
#### Path Parameters
- **bin** (unsigned int) - Description: The index of the bin for which to retrieve the real component.
### Response
#### Success Response
- **real_component** (double) - Description: The real component of the FFT output for the specified bin.
```
--------------------------------
### KeyFinder::FftAdapter::FftAdapter
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter-members.html
Constructor for the FftAdapter class. Initializes an FftAdapter object with a specified frame size.
```APIDOC
## KeyFinder::FftAdapter::FftAdapter
### Description
Constructor for the FftAdapter class. Initializes an FftAdapter object with a specified frame size.
### Method
(Not specified in source, likely a constructor call)
### Parameters
#### Path Parameters
- **frameSize** (unsigned int) - Description: The size of the frame for FFT processing.
```
--------------------------------
### ChromaTransformWrapper Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1ChromaTransformFactory_1_1ChromaTransformWrapper-members.html
Constructs a ChromaTransformWrapper object. This constructor initializes the wrapper with a specified frame rate and a ChromaTransform object.
```APIDOC
## ChromaTransformWrapper(unsigned int frameRate, const ChromaTransform *const transform)
### Description
Constructs a ChromaTransformWrapper object, initializing it with the provided frame rate and ChromaTransform.
### Method
Constructor
### Parameters
#### Path Parameters
- **frameRate** (unsigned int) - Required - The frame rate for the ChromaTransform.
- **transform** (const ChromaTransform *const) - Required - A pointer to the ChromaTransform object.
```
--------------------------------
### setInput
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter.html
Sets a single input sample for the FFT computation.
```APIDOC
## setInput(unsigned int sample, double real)
### Description
Sets a single input sample for the FFT computation.
### Method
POST
### Endpoint
/FftAdapter/setInput
### Parameters
#### Request Body
- **sample** (unsigned int) - Required - The index of the sample to set.
- **real** (double) - Required - The real part of the sample value.
```
--------------------------------
### ChromaTransform Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1ChromaTransform.html
Constructs a ChromaTransform object with a specified frame rate.
```APIDOC
## ChromaTransform Constructor
### Description
Constructs a ChromaTransform object with a specified frame rate.
### Parameters
#### Path Parameters
- **frameRate** (unsigned int) - Required - The frame rate of the audio.
### Method
[CONSTRUCTOR]
### Endpoint
[N/A - Constructor]
```
--------------------------------
### TemporalWindowWrapper Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1TemporalWindowFactory_1_1TemporalWindowWrapper.html
Constructs a TemporalWindowWrapper object with a specified frame size.
```APIDOC
## TemporalWindowWrapper(unsigned int frameSize)
### Description
Constructs a TemporalWindowWrapper object.
### Parameters
#### Path Parameters
- **frameSize** (unsigned int) - Required - The size of the frame for the temporal window.
```
--------------------------------
### FftAdapter Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter.html
Constructs an FftAdapter object with a specified frame size.
```APIDOC
## FftAdapter(unsigned int frameSize)
### Description
Constructs an FftAdapter object with a specified frame size.
### Parameters
#### Path Parameters
- **frameSize** (unsigned int) - Required - The size of the frame for the FFT.
```
--------------------------------
### getOutputReal
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter.html
Retrieves the real component of the FFT output for a given bin.
```APIDOC
## getOutputReal(unsigned int bin)
### Description
Retrieves the real component of the FFT output for a given bin.
### Method
GET
### Endpoint
/FftAdapter/getOutputReal
### Parameters
#### Query Parameters
- **bin** (unsigned int) - Required - The index of the FFT bin.
### Returns
- **double** - The real component of the output.
```
--------------------------------
### KeyFinder::Chromagram::collapseToOneHop
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1Chromagram-members.html
Collapses the Chromagram data into a single hop representation.
```APIDOC
## collapseToOneHop
### Description
Collapses the Chromagram data into a single hop representation. This operation is performed on a const object, meaning it does not modify the original Chromagram.
### Method
(Not specified, likely a member function call)
### Parameters
None
### Returns
(Not specified, likely a new Chromagram object or a representation of the collapsed data)
### Code Example
```cpp
Chromagram chromagram;
// ... populate chromagram ...
auto collapsed_chromagram = chromagram.collapseToOneHop();
```
```
--------------------------------
### InverseFftAdapter Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter.html
Constructs an InverseFftAdapter with a specified frame size.
```APIDOC
## InverseFftAdapter(unsigned int frameSize)
### Description
Constructs an InverseFftAdapter object, initializing it with the given frame size for FFT operations.
### Parameters
#### Path Parameters
- **frameSize** (unsigned int) - Required - The size of the frame for FFT processing.
```
--------------------------------
### KeyFinder::FftAdapter
Source: https://mixxxdj.github.io/libkeyfinder/fftadapter_8h_source.html
Handles the forward Fast Fourier Transform (FFT) operation. It allows setting input samples and retrieving the real and imaginary components, as well as the magnitude of the FFT output.
```APIDOC
## KeyFinder::FftAdapter
### Description
Provides functionality for performing a forward Fast Fourier Transform (FFT). Users can initialize the adapter with a frame size, set input real-valued samples, execute the transform, and retrieve the real, imaginary, and magnitude components of the output bins.
### Methods
- **FftAdapter(unsigned int frameSize)**: Constructor to initialize the FFT adapter with a specified frame size.
- **~FftAdapter()**: Destructor to clean up resources.
- **unsigned int getFrameSize() const**: Returns the configured frame size of the FFT adapter.
- **void setInput(unsigned int sample, double real)**: Sets a real-valued input sample at a specific index.
- **void execute()**: Executes the FFT transformation on the set input samples.
- **double getOutputReal(unsigned int bin) const**: Retrieves the real component of the output at a given frequency bin.
- **double getOutputImaginary(unsigned int bin) const**: Retrieves the imaginary component of the output at a given frequency bin.
- **double getOutputMagnitude(unsigned int bin) const**: Retrieves the magnitude of the output at a given frequency bin.
```
--------------------------------
### KeyClassifier Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1KeyClassifier.html
Constructs a KeyClassifier object with specified major and minor key profiles.
```APIDOC
## KeyClassifier(const std::vector< double > &majorProfile, const std::vector< double > &minorProfile)
### Description
Constructs a KeyClassifier object with specified major and minor key profiles.
### Parameters
#### Path Parameters
- **majorProfile** (const std::vector< double > &) - Description not available
- **minorProfile** (const std::vector< double > &) - Description not available
```
--------------------------------
### setInput
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter.html
Sets a complex input sample for the inverse FFT calculation.
```APIDOC
## setInput(unsigned int sample, double real, double imaginary)
### Description
Sets a complex number (real and imaginary parts) for a specific sample index in the input buffer for the inverse FFT.
### Parameters
#### Path Parameters
- **sample** (unsigned int) - Required - The index of the sample to set.
- **real** (double) - Required - The real part of the complex sample.
- **imaginary** (double) - Required - The imaginary part of the complex sample.
```
--------------------------------
### KeyFinder::FftAdapter::getFrameSize
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter-members.html
Retrieves the current frame size configured for the FftAdapter.
```APIDOC
## KeyFinder::FftAdapter::getFrameSize
### Description
Retrieves the current frame size configured for the FftAdapter.
### Method
(Not specified in source, likely a member function call)
### Parameters
(No parameters specified in source)
### Response
#### Success Response
- **frameSize** (unsigned int) - Description: The current frame size.
```
--------------------------------
### KeyFinder::Chromagram::Chromagram
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1Chromagram-members.html
Constructs a new Chromagram object.
```APIDOC
## Chromagram Constructor
### Description
Constructs a new Chromagram object, optionally with a specified number of hops.
### Method
(Constructor)
### Parameters
* **hops** (unsigned int) - Optional. The number of hops to initialize the Chromagram with. Defaults to 0.
### Code Example
```cpp
// Default constructor
Chromagram chromagram1;
// Constructor with specified hops
Chromagram chromagram2(100);
```
```
--------------------------------
### getHops
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1Chromagram.html
Returns the total number of hops in the chromagram.
```APIDOC
## getHops
### Description
Returns the total number of hops in the chromagram.
### Method
unsigned int
### Endpoint
N/A (Method within a class)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Response
#### Success Response (200)
* **Return Value** (unsigned int) - The number of hops.
```
--------------------------------
### KeyFinder::keyOfAudio
Source: https://mixxxdj.github.io/libkeyfinder/keyfinder_8h_source.html
Analyzes an entire audio file to determine its musical key.
```APIDOC
## keyOfAudio
### Description
Analyzes an entire audio file to determine its musical key.
### Signature
`key_t keyOfAudio(const AudioData& audio)`
### Parameters
* `audio` (const AudioData&) - The audio data to analyze.
### Returns
`key_t` - The estimated musical key.
```
--------------------------------
### KeyFinder::InverseFftAdapter::getFrameSize
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter-members.html
Retrieves the frame size of the adapter. This method is const.
```APIDOC
## getFrameSize() const
### Description
Retrieves the frame size of the adapter.
### Method
(Not specified in source)
### Endpoint
(Not specified in source)
### Parameters
(None specified in source)
### Request Example
(Not specified in source)
### Response
(Not specified in source)
```
--------------------------------
### Chromagram Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1Chromagram.html
Constructs a Chromagram object. An optional number of hops can be specified.
```APIDOC
## Chromagram Constructor
### Description
Constructs a Chromagram object. An optional number of hops can be specified.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
* **hops** (unsigned int) - Optional - The number of hops for the chromagram.
```
--------------------------------
### KeyFinder::WindowFunction
Source: https://mixxxdj.github.io/libkeyfinder/windowfunctions_8h_source.html
The WindowFunction class provides methods for generating various types of window functions and performing convolution operations, essential for audio analysis tasks like key detection.
```APIDOC
## KeyFinder::WindowFunction
### Description
Provides methods for generating window functions and performing convolution.
### Methods
* **window**
- **Description**: Calculates a window function of a specified type.
- **Parameters**:
- `windowType` (temporal_window_t): The type of window function to generate.
- `sample` (int): The current sample index.
- `width` (int): The total width of the window.
- **Returns**: (double) The value of the window function at the given sample.
* **gaussianWindow**
- **Description**: Calculates a Gaussian window function.
- **Parameters**:
- `sample` (int): The current sample index.
- `width` (int): The total width of the window.
- `sigma` (double): The standard deviation of the Gaussian function.
- **Returns**: (double) The value of the Gaussian window function at the given sample.
* **convolve**
- **Description**: Performs a convolution operation between an input signal and a window function.
- **Parameters**:
- `input` (const std::vector&): The input signal data.
- `window` (const std::vector&): The window function to convolve with.
- **Returns**: (std::vector) The result of the convolution.
```
--------------------------------
### KeyFinder Class Declaration
Source: https://mixxxdj.github.io/libkeyfinder/keyfinder_8h_source.html
Declares the KeyFinder class, its public methods for audio analysis (progressive and whole-file), and private helper functions. It also lists the factory objects it utilizes.
```cpp
#ifndef KEYFINDER_H
#define KEYFINDER_H
#include "audiodata.h"
#include "lowpassfilterfactory.h"
#include "chromatransformfactory.h"
#include "spectrumanalyser.h"
#include "keyclassifier.h"
namespace KeyFinder {
class KeyFinder {
public:
// for progressive analysis
void progressiveChromagram(AudioData audio, Workspace& workspace);
void finalChromagram(Workspace& workspace);
key_t keyOfChromagram(const Workspace& workspace) const;
// for analysis of a whole audio file
key_t keyOfAudio(const AudioData& audio);
// for experimentation with alternative tone profiles
key_t keyOfChromaVector(const std::vector& chromaVector, const std::vector& overrideMajorProfile, const std::vector& overrideMinorProfile) const;
private:
void preprocess(AudioData& workingAudio, Workspace& workspace, bool flushRemainderBuffer = false);
void chromagramOfBufferedAudio(Workspace& workspace);
key_t keyOfChromaVector(const std::vector& chromaVector) const;
LowPassFilterFactory lpfFactory;
ChromaTransformFactory ctFactory;
TemporalWindowFactory twFactory;
};
} // namespace KeyFinder
#endif
```
--------------------------------
### ChromaTransformWrapper Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1ChromaTransformFactory_1_1ChromaTransformWrapper.html
Constructs a ChromaTransformWrapper object with the specified frame rate and ChromaTransform.
```APIDOC
## ChromaTransformWrapper Constructor
### Description
Constructs a ChromaTransformWrapper object with the specified frame rate and ChromaTransform.
### Parameters
* **frameRate** (unsigned int) - The frame rate associated with the transform.
* **transform** (const ChromaTransform *const) - A pointer to the ChromaTransform object.
```
--------------------------------
### KeyFinder::FftAdapter::setInput
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter-members.html
Sets the real component of an input sample for the FFT processing.
```APIDOC
## KeyFinder::FftAdapter::setInput
### Description
Sets the real component of an input sample for the FFT processing.
### Method
(Not specified in source, likely a member function call)
### Parameters
#### Path Parameters
- **sample** (unsigned int) - Description: The index of the sample to set.
- **real** (double) - Description: The real value of the sample.
```
--------------------------------
### KeyFinder::InverseFftAdapter::frameSize
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter-members.html
Protected member representing the frame size of the adapter.
```APIDOC
## frameSize
### Description
Protected member representing the frame size of the adapter.
### Method
(Not specified in source)
### Endpoint
(Not specified in source)
### Parameters
(None specified in source)
### Request Example
(Not specified in source)
### Response
(Not specified in source)
```
--------------------------------
### KeyFinder::InverseFftAdapter
Source: https://mixxxdj.github.io/libkeyfinder/fftadapter_8h_source.html
Handles the inverse Fast Fourier Transform (IFFT) operation. It allows setting input samples with real and imaginary parts and retrieving the output.
```APIDOC
## KeyFinder::InverseFftAdapter
### Description
Provides functionality for performing an inverse Fast Fourier Transform (IFFT). Users can initialize the adapter with a frame size, set input samples with both real and imaginary components, execute the transform, and retrieve the resulting output.
### Methods
- **InverseFftAdapter(unsigned int frameSize)**: Constructor to initialize the Inverse FFT adapter with a specified frame size.
- **~InverseFftAdapter()**: Destructor to clean up resources.
- **unsigned int getFrameSize() const**: Returns the configured frame size of the Inverse FFT adapter.
- **void setInput(unsigned int sample, double real, double imaginary)**: Sets an input sample with its real and imaginary components at a specific index.
- **void execute()**: Executes the Inverse FFT transformation on the set input samples.
- **double getOutput(unsigned int bin) const**: Retrieves the output value at a given bin after the inverse transformation.
```
--------------------------------
### KeyFinder::InverseFftAdapter::priv
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter-members.html
Protected member, likely for internal use.
```APIDOC
## priv
### Description
Protected member, likely for internal use.
### Method
(Not specified in source)
### Endpoint
(Not specified in source)
### Parameters
(None specified in source)
### Request Example
(Not specified in source)
### Response
(Not specified in source)
```
--------------------------------
### LowPassFilterWrapper Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1LowPassFilterFactory_1_1LowPassFilterWrapper-members.html
Constructs a LowPassFilterWrapper object with the specified parameters.
```APIDOC
## LowPassFilterWrapper Constructor
### Description
Constructs a LowPassFilterWrapper object with the specified order, frame rate, corner frequency, FFT frame size, and a pointer to a LowPassFilter.
### Parameters
- **order** (unsigned int) - Required - The order of the low-pass filter.
- **frameRate** (unsigned int) - Required - The frame rate of the audio processing.
- **cornerFrequency** (double) - Required - The corner frequency of the low-pass filter.
- **fftFrameSize** (unsigned int) - Required - The size of the FFT frame.
- **filter** (const LowPassFilter *const) - Required - A pointer to the LowPassFilter object.
```
--------------------------------
### AudioData Public Member Functions
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1AudioData.html
This section details the public member functions available for the AudioData class, allowing users to interact with and modify audio data.
```APIDOC
## AudioData Class
### Description
Provides methods to manage and manipulate audio sample data.
### Public Member Functions
#### `getChannels()`
* **Description**: Returns the number of audio channels.
* **Returns**: `unsigned int` - The number of channels.
#### `getFrameRate()`
* **Description**: Returns the audio frame rate.
* **Returns**: `unsigned int` - The frame rate.
#### `getSample(unsigned int index)`
* **Description**: Retrieves a sample value at a specific index.
* **Parameters**:
* `index` (unsigned int) - The index of the sample to retrieve.
* **Returns**: `double` - The sample value.
#### `getSampleByFrame(unsigned int frame, unsigned int channel)`
* **Description**: Retrieves a sample value at a specific frame and channel.
* **Parameters**:
* `frame` (unsigned int) - The frame number.
* `channel` (unsigned int) - The channel number.
* **Returns**: `double` - The sample value.
#### `getSampleAtReadIterator()`
* **Description**: Retrieves the sample value at the current read iterator position.
* **Returns**: `double` - The sample value.
#### `getSampleCount()`
* **Description**: Returns the total number of samples.
* **Returns**: `unsigned int` - The total sample count.
#### `getFrameCount()`
* **Description**: Returns the total number of frames.
* **Returns**: `unsigned int` - The total frame count.
#### `setChannels(unsigned int newChannels)`
* **Description**: Sets the number of audio channels.
* **Parameters**:
* `newChannels` (unsigned int) - The new number of channels.
#### `setFrameRate(unsigned int newFrameRate)`
* **Description**: Sets the audio frame rate.
* **Parameters**:
* `newFrameRate` (unsigned int) - The new frame rate.
#### `setSample(unsigned int index, double value)`
* **Description**: Sets a sample value at a specific index.
* **Parameters**:
* `index` (unsigned int) - The index of the sample to set.
* `value` (double) - The new sample value.
#### `setSampleByFrame(unsigned int frame, unsigned int channels, double value)`
* **Description**: Sets a sample value at a specific frame and channel.
* **Parameters**:
* `frame` (unsigned int) - The frame number.
* `channels` (unsigned int) - The channel number.
* `value` (double) - The new sample value.
#### `setSampleAtWriteIterator(double value)`
* **Description**: Sets the sample value at the current write iterator position.
* **Parameters**:
* `value` (double) - The new sample value.
#### `addToSampleCount(unsigned int newSamples)`
* **Description**: Adds to the total sample count.
* **Parameters**:
* `newSamples` (unsigned int) - The number of samples to add.
#### `addToFrameCount(unsigned int newFrames)`
* **Description**: Adds to the total frame count.
* **Parameters**:
* `newFrames` (unsigned int) - The number of frames to add.
#### `advanceReadIterator(unsigned int by=1)`
* **Description**: Advances the read iterator by a specified number of positions.
* **Parameters**:
* `by` (unsigned int, optional) - The number of positions to advance. Defaults to 1.
#### `advanceWriteIterator(unsigned int by=1)`
* **Description**: Advances the write iterator by a specified number of positions.
* **Parameters**:
* `by` (unsigned int, optional) - The number of positions to advance. Defaults to 1.
#### `readIteratorWithinUpperBound() const`
* **Description**: Checks if the read iterator is within the upper bound.
* **Returns**: `bool` - True if within bounds, false otherwise.
#### `writeIteratorWithinUpperBound() const`
* **Description**: Checks if the write iterator is within the upper bound.
* **Returns**: `bool` - True if within bounds, false otherwise.
#### `resetIterators()`
* **Description**: Resets both the read and write iterators to their starting positions.
#### `append(const AudioData &that)`
* **Description**: Appends the audio data from another `AudioData` object to the end of this object.
* **Parameters**:
* `that` (const AudioData &) - The `AudioData` object to append.
#### `prepend(const AudioData &that)`
* **Description**: Prepends the audio data from another `AudioData` object to the beginning of this object.
* **Parameters**:
* `that` (const AudioData &) - The `AudioData` object to prepend.
#### `discardFramesFromFront(unsigned int discardFrameCount)`
* **Description**: Discards a specified number of frames from the front of the audio data.
* **Parameters**:
* `discardFrameCount` (unsigned int) - The number of frames to discard.
#### `reduceToMono()`
* **Description**: Reduces the audio data to mono by averaging the channels.
#### `downsample(unsigned int factor, bool shortcut=true)`
* **Description**: Downsamples the audio data by a specified factor.
* **Parameters**:
* `factor` (unsigned int) - The downsampling factor.
* `shortcut` (bool, optional) - Whether to use a shortcut method for downsampling. Defaults to true.
#### `sliceSamplesFromBack(unsigned int sliceSampleCount)`
* **Description**: Creates a new `AudioData` object containing a slice of samples from the back of the current data.
* **Parameters**:
* `sliceSampleCount` (unsigned int) - The number of samples to include in the slice.
* **Returns**: `AudioData*` - A pointer to the new `AudioData` object containing the slice.
```
--------------------------------
### KeyFinder::FftAdapter::getOutputMagnitude
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter-members.html
Retrieves the magnitude of the FFT output for a specific bin.
```APIDOC
## KeyFinder::FftAdapter::getOutputMagnitude
### Description
Retrieves the magnitude of the FFT output for a specific bin.
### Method
(Not specified in source, likely a member function call)
### Parameters
#### Path Parameters
- **bin** (unsigned int) - Description: The index of the bin for which to retrieve the magnitude.
### Response
#### Success Response
- **magnitude** (double) - Description: The magnitude of the FFT output for the specified bin.
```
--------------------------------
### KeyFinder::WindowFunction::window
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1WindowFunction-members.html
Generates a window function based on a specified window type. Supports various standard windowing techniques.
```APIDOC
## KeyFinder::WindowFunction::window
### Description
Generates a window function based on a specified window type. Supports various standard windowing techniques.
### Method
const
### Parameters
#### Path Parameters
- **windowType** (temporal_window_t) - Required - The type of window to generate (e.g., Hann, Hamming, Blackman).
- **sample** (int) - Required - The current sample index.
- **width** (int) - Required - The total width of the window.
### Response
#### Success Response (200)
- **result** (std::vector< double >) - The generated window function.
```
--------------------------------
### KeyFinder::Chromagram::getHops
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1Chromagram-members.html
Retrieves the number of hops in the Chromagram.
```APIDOC
## getHops
### Description
Retrieves the number of hops currently stored in the Chromagram object.
### Method
(Not specified, likely a member function call)
### Parameters
None
### Returns
* **unsigned int** - The number of hops.
### Code Example
```cpp
Chromagram chromagram;
// ... populate chromagram ...
unsigned int num_hops = chromagram.getHops();
```
```
--------------------------------
### getTemporalWindow
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1TemporalWindowFactory_1_1TemporalWindowWrapper.html
Retrieves a pointer to the temporal window data.
```APIDOC
## getTemporalWindow()
### Description
Returns a constant pointer to the temporal window data.
### Returns
- **const std::vector< double >*** - A pointer to the temporal window data.
```
--------------------------------
### filter
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1LowPassFilter.html
Applies the low-pass filter to the provided audio data using the given workspace and an optional shortcut factor.
```APIDOC
## filter
### Description
Applies the low-pass filter to the provided audio data using the given workspace and an optional shortcut factor.
### Parameters
* **audio** (AudioData &) - The audio data to filter.
* **workspace** (Workspace &) - The workspace to use for filtering.
* **shortcutFactor** (unsigned int) - Optional. Defaults to 1. Description not available.
```
--------------------------------
### KeyFinder::FftAdapter::execute
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1FftAdapter-members.html
Executes the Fast Fourier Transform (FFT) operation. This method is part of the FftAdapter class and is used to process audio frames.
```APIDOC
## KeyFinder::FftAdapter::execute
### Description
Executes the Fast Fourier Transform (FFT) operation. This method is used to process audio frames.
### Method
(Not specified in source, likely a member function call)
### Parameters
(No parameters specified in source)
### Response
(No return type or response details specified in source)
```
--------------------------------
### getOutput
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1InverseFftAdapter.html
Retrieves the computed output value for a specific frequency bin after the inverse FFT.
```APIDOC
## getOutput(unsigned int bin) const
### Description
Returns the computed value for a given frequency bin after the inverse FFT has been executed.
### Parameters
#### Path Parameters
- **bin** (unsigned int) - Required - The index of the frequency bin to retrieve the output for.
### Returns
- **double** - The computed output value for the specified bin.
```
--------------------------------
### LowPassFilter Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1LowPassFilter.html
Constructs a LowPassFilter object with specified parameters for order, frame rate, corner frequency, and FFT frame size.
```APIDOC
## LowPassFilter Constructor
### Description
Constructs a LowPassFilter object with specified parameters for order, frame rate, corner frequency, and FFT frame size.
### Parameters
* **order** (unsigned int) - Description not available.
* **frameRate** (unsigned int) - Description not available.
* **cornerFrequency** (double) - Description not available.
* **fftFrameSize** (unsigned int) - Description not available.
```
--------------------------------
### LowPassFilter Constructor
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1LowPassFilter-members.html
Constructs a LowPassFilter object with specified parameters for order, frame rate, corner frequency, and FFT frame size.
```APIDOC
## LowPassFilter::LowPassFilter
### Description
Initializes a new instance of the `LowPassFilter` class with the provided configuration parameters.
### Method Signature
`LowPassFilter(unsigned int order, unsigned int frameRate, double cornerFrequency, unsigned int fftFrameSize)`
### Parameters
* **order** (`unsigned int`): The order of the low-pass filter.
* **frameRate** (`unsigned int`): The frame rate of the audio data.
* **cornerFrequency** (`double`): The corner frequency of the filter.
* **fftFrameSize** (`unsigned int`): The size of the FFT frame.
```
--------------------------------
### chromagramOfWholeFrames
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1SpectrumAnalyser-members.html
Calculates the chromagram for all frames of the audio data using the provided FFT adapter. This is a public method intended for direct use by library users.
```APIDOC
## chromagramOfWholeFrames
### Description
Calculates the chromagram for all frames of the audio data.
### Method
const
### Endpoint
N/A (C++ method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```cpp
// Assuming audioData is an AudioData object and fftAdapter is an FftAdapter object
SpectrumAnalyser analyser(...);
KeyFinder::Chromagram chromagram = analyser.chromagramOfWholeFrames(audioData, fftAdapter);
```
### Response
#### Success Response
- **chromagram** (KeyFinder::Chromagram) - The calculated chromagram of the audio frames.
#### Response Example
```json
// Example representation of a Chromagram object (actual structure may vary)
{
"frames": [
[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]
]
}
```
```
--------------------------------
### getOrder
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1LowPassFilterFactory_1_1LowPassFilterWrapper-members.html
Retrieves the order of the low-pass filter.
```APIDOC
## getOrder
### Description
Returns the order of the low-pass filter.
### Returns
- **unsigned int** - The order of the filter.
```
--------------------------------
### getOrder
Source: https://mixxxdj.github.io/libkeyfinder/classKeyFinder_1_1LowPassFilterFactory_1_1LowPassFilterWrapper.html
Retrieves the order of the low-pass filter.
```APIDOC
## getOrder
### Description
Retrieves the order of the low-pass filter.
### Method
unsigned int
### Returns
The order of the filter.
```