Krotos Modules 3
Loading...
Searching...
No Matches
krotos::AudioDataset Class Reference

#include <AudioDataset.h>

Inheritance diagram for krotos::AudioDataset:

Public Member Functions

 AudioDataset ()
 
 ~AudioDataset ()
 
std::vector< std::pair< std::string, float > > sample (std::string query, std::size_t k=3, bool descending=true) const
 

Private Member Functions

std::vector< File > findValidFiles () const
 
void run () override
 
bool assetsChanged ()
 
bool runAnalysis ()
 
File getFactoryAssetDirectory () const
 
File getDatasetFile () const
 
std::set< std::string > getPathsSet () const
 
std::string fixKeyErrors (std::string key) const
 
std::string extractCatID (std::string filename) const
 
bool writeCache ()
 
bool readCache ()
 
bool cacheExists ()
 
bool deleteCache ()
 
AudioBuffer< float > resampleAudioBuffer (const AudioBuffer< float > &buffer, double sampleRate, double targetRate)
 

Private Attributes

std::string m_version = "1.0"
 
std::map< std::string, std::vector< std::pair< std::string, std::vector< float > > > > m_dataset
 
std::array< std::string, 753 > CatIDSet
 

Constructor & Destructor Documentation

◆ AudioDataset()

krotos::AudioDataset::AudioDataset ( )

Constructor

◆ ~AudioDataset()

krotos::AudioDataset::~AudioDataset ( )

Destructor

Member Function Documentation

◆ assetsChanged()

bool krotos::AudioDataset::assetsChanged ( )
private

Checks whether the factory assets have changed from those cached.

Returns
true or false

◆ cacheExists()

bool krotos::AudioDataset::cacheExists ( )
private

Checks if the analysis has been previously cached to a json file.

Returns
whether the cache exists

◆ deleteCache()

bool krotos::AudioDataset::deleteCache ( )
private

Attempts to delete an existing cached json file.

Returns
whether the delete was successful

◆ extractCatID()

std::string krotos::AudioDataset::extractCatID ( std::string filename) const
private

Extracts UCS CatID key from a filename.

Parameters
filenamethe filename that potentially contains UCS data
Returns
the extracted key

◆ findValidFiles()

std::vector< File > krotos::AudioDataset::findValidFiles ( ) const
private

Searches for valid files (valid CatID and 48 kHz samplerate).

Returns
search results as a vector of filepaths

◆ fixKeyErrors()

std::string krotos::AudioDataset::fixKeyErrors ( std::string key) const
private

Corrects some CatID key errors due to mislabelled factory assets.

Parameters
keya possible CatID key
Returns
key with potential modifications

◆ getDatasetFile()

File krotos::AudioDataset::getDatasetFile ( ) const
private

Cross-platform location to cache analysis.

Returns
the full path

◆ getFactoryAssetDirectory()

File krotos::AudioDataset::getFactoryAssetDirectory ( ) const
private

Cross-platform location of factory assets to analyse (wav files).

Returns
the full path

◆ getPathsSet()

std::set< std::string > krotos::AudioDataset::getPathsSet ( ) const
private

Computes the set of filepaths used in the current analysis.

Returns
the set of filepath strings

◆ readCache()

bool krotos::AudioDataset::readCache ( )
private

Attempts to read chached analysis from file.

Returns
whether the read was successful

◆ resampleAudioBuffer()

AudioBuffer< float > krotos::AudioDataset::resampleAudioBuffer ( const AudioBuffer< float > & buffer,
double sampleRate,
double targetRate )
private

Resamples an AudioBuffer to a target samplerate

Returns
the resampled AudioBuffer

◆ run()

void krotos::AudioDataset::run ( )
overrideprivate

Worker thread for analysis.

◆ runAnalysis()

bool krotos::AudioDataset::runAnalysis ( )
private

Checks whether analysis needs to be run.

Returns
true or false

◆ sample()

std::vector< std::pair< std::string, float > > krotos::AudioDataset::sample ( std::string query,
std::size_t k = 3,
bool descending = true ) const

Searches for similar files to a query filepath using UCS CatIDs and audio embeddings.

Parameters
queryfilepath used to search for similar files
kthe number of search results to return (may return fewer than k)
descendingif true, search will be for k most similar
Returns
search results as a vector of pairs, with filepaths and similarity scores

◆ writeCache()

bool krotos::AudioDataset::writeCache ( )
private

Caches the analysis to a json file.

Returns
whether the write was successful

Member Data Documentation

◆ CatIDSet

std::array<std::string, 753> krotos::AudioDataset::CatIDSet
private

◆ m_dataset

std::map<std::string, std::vector<std::pair<std::string, std::vector<float> > > > krotos::AudioDataset::m_dataset
private

◆ m_version

std::string krotos::AudioDataset::m_version = "1.0"
private

The documentation for this class was generated from the following files: