### Build and install audioFlux from source on Linux/macOS Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Compile and install audioFlux from source using Python's setup.py script. This is done after installing dependencies. ```bash $ python setup.py build $ python setup.py install ``` -------------------------------- ### Build and install audioFlux for Windows from source (cross-compilation) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Build and install audioFlux for Windows using cross-compilation on Linux/macOS. This is an alternative to pip installation for Windows. ```bash $ python setup.py build_py_win $ python setup.py install ``` -------------------------------- ### Install Target Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Installs the built audioflux library to the 'lib' directory on the target system. ```cmake install(TARGETS audioflux DESTINATION lib) ``` -------------------------------- ### Install AudioFlux using pip Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Use this command to install the audioFlux package from PyPI. ```bash pip install audioflux ``` -------------------------------- ### Build and Install Python package from source (Linux/macOS) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Build and install the audioFlux Python package from source using setup.py. ```bash python setup.py build python setup.py install ``` -------------------------------- ### Install Linux build dependencies (Ubuntu) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Install cmake and clang on Ubuntu systems for building from source. ```shell # For Ubuntu: $ sudo apt install cmake clang ``` -------------------------------- ### Build and Install Python package from source (Windows) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Build and install the audioFlux Python package for Windows using setup.py, typically via cross-compilation. ```bash python setup.py build_py_win python setup.py install ``` -------------------------------- ### Install Linux build dependencies (CentOS) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Install cmake and clang on CentOS systems for building from source. ```shell # For CentOS: $ sudo yum install -y cmake clang ``` -------------------------------- ### Install AudioFlux using pip Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Install the audioFlux package from PyPI using pip. Ensure you have Python 3.6 or newer. ```bash $ pip install audioflux ``` -------------------------------- ### Install LLVM and set compiler paths on macOS Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Install LLVM using Homebrew and set C_COMPILER_PATH and CXX_COMPILER_PATH for compilation on macOS. ```bash brew install llvm export C_COMPILER_PATH=/usr/local/opt/llvm/bin/clang export CXX_COMPILER_PATH=/usr/local/opt/llvm/bin/clang++ ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Run this command to install essential Xcode command line tools required for iOS development. ```bash xcode-select --install ``` -------------------------------- ### Install AudioFlux using conda Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Use this command to install the audioFlux package from conda channels. ```bash conda install -c tanky25 -c conda-forge audioflux ``` -------------------------------- ### Install LLVM on macOS Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Install LLVM using Homebrew on macOS. This is a dependency for building from source. ```bash $ brew install llvm ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Install Xcode Command Line Tools on macOS. This is a prerequisite for building iOS applications. ```bash $ xcode-select --install ``` -------------------------------- ### Onset Detection using Flux Novelty Source: https://github.com/libaudioflux/audioflux/blob/master/docs/examples.md This example demonstrates how to detect note onsets in an audio signal by analyzing the onset strength envelope derived from a spectrogram. It requires audio data, a BFT object for spectrogram computation, and an Onset object configured for flux novelty. ```python import numpy as np import audioflux as af from audioflux.type import SpectralFilterBankScaleType, SpectralDataType, NoveltyType import matplotlib.pyplot as plt from audioflux.display import fill_wave, fill_plot, fill_spec # Read audio data and sample rate audio_arr, sr = af.read(af.utils.sample_path('guitar_chord2')) bft_obj = af.BFT(num=128, samplate=sr, radix2_exp=11, slide_length=2048, scale_type=SpectralFilterBankScaleType.MEL, data_type=SpectralDataType.POWER) spec_arr = bft_obj.bft(audio_arr) spec_dB_arr = af.utils.power_to_db(np.abs(spec_arr)) n_fre, n_time = spec_dB_arr.shape onset_obj = af.Onset(time_length=n_time, fre_length=n_fre, slide_length=bft_obj.slide_length, samplate=bft_obj.samplate, novelty_type=NoveltyType.FLUX) point_arr, evn_arr, time_arr, value_arr = onset_obj.onset(spec_dB_arr) audio_len = audio_arr.shape[-1] fig, axes = plt.subplots(nrows=3, sharex=True) img = fill_spec(spec_dB_arr, axes=axes[0], x_coords=bft_obj.x_coords(audio_len), y_coords=bft_obj.y_coords(), x_axis='time', y_axis='log', title='Onset') ax = fill_wave(audio_arr, samplate=sr, axes=axes[1]) ax.vlines(time_arr, -1, 1, color='r', alpha=0.9, linestyle='--', label='Onsets') times = np.arange(0, evn_arr.shape[-1]) * (bft_obj.slide_length / sr) ax = fill_plot(times, evn_arr, axes=axes[2], label='Onset strength') ax.vlines(time_arr, evn_arr.min(), evn_arr.max(), color='r', alpha=0.9, linestyle='--', label='Onsets') plt.show() ``` -------------------------------- ### Install Linux build dependencies Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Install CMake and Clang on Ubuntu or CentOS systems. These are essential compilation dependencies for building audioFlux from source on Linux. ```bash # For Ubuntu: $ sudo apt install cmake clang # For CentOS: $ sudo yum install -y cmake clang ``` -------------------------------- ### audioflux.utils.sample_path Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Gets the path to a sample file. ```APIDOC ## audioflux.utils.sample_path ### Description Gets the path to a sample file. ### Method N/A (Utility function) ### Parameters * **filename** (str) - The name of the sample file. ### Response * **path** (str) - The absolute path to the sample file. ``` -------------------------------- ### Install AudioFlux using conda Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Install the audioFlux package from conda channels. This method is an alternative to pip. ```bash $ conda install -c tanky25 -c conda-forge audioflux ``` -------------------------------- ### Set MKL environment variables on Linux Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Set MKL_INCLUDE_PATH and MKL_LIB_PATH environment variables if MKL is installed on Linux. ```bash export MKL_INCLUDE_PATH=/opt/intel/oneapi/mkl/latest/include export MKL_LIB_PATH=/opt/intel/oneapi/mkl/latest/lib/intel64 ``` -------------------------------- ### Set NDK environment variables for Android Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Set the NDK_ROOT and PATH environment variables to point to your Android NDK installation for Android builds. ```bash export NDK_ROOT=~/Android/android-ndk-r16b export PATH=$NDK_ROOT:$PATH ``` -------------------------------- ### Set LLVM compiler paths on macOS Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Configure C_COMPILER_PATH and CXX_COMPILER_PATH environment variables to point to the installed LLVM clang compiler on macOS. This is required when building from source. ```bash $ export C_COMPILER_PATH=/usr/local/opt/llvm/bin/clang $ export CXX_COMPILER_PATH=/usr/local/opt/llvm/bin/clang++ ``` -------------------------------- ### Harmonic Percussive Source Separation (HPSS) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/examples.md This example decomposes an audio signal into its harmonic and percussive components using the HPSS algorithm. It involves computing spectrograms for the original, harmonic, and percussive components and visualizing them. ```python import audioflux as af from audioflux.type import SpectralDataType, WindowType, SpectralFilterBankScaleType import matplotlib.pyplot as plt from audioflux.display import fill_wave, fill_spec # Read audio data and sample rate audio_arr, sr = af.read(af.utils.sample_path('chord_metronome2')) # Compute the hpss radix2_exp = 11 slide_length = (1 << radix2_exp) // 4 hpss_obj = af.HPSS(radix2_exp=radix2_exp, window_type=WindowType.HAMM, slide_length=slide_length, h_order=21, p_order=31) h_arr, p_arr = hpss_obj.hpss(audio_arr) # Extract Linear spectrogram bft_obj = af.BFT(num=2049, radix2_exp=12, samplate=sr, data_type=SpectralDataType.POWER, scale_type=SpectralFilterBankScaleType.LINEAR) audio_arr = audio_arr[..., :h_arr.shape[-1]] origin_spec_arr = bft_obj.bft(audio_arr, result_type=1) h_spec_arr = bft_obj.bft(h_arr, result_type=1) p_spec_arr = bft_obj.bft(p_arr, result_type=1) origin_spec_arr = af.utils.power_to_abs_db(origin_spec_arr) h_spec_arr = af.utils.power_to_abs_db(h_spec_arr) p_spec_arr = af.utils.power_to_abs_db(p_spec_arr) # Display fig, axes = plt.subplots(nrows=3, sharex=True, sharey=True) fill_wave(audio_arr, samplate=sr, axes=axes[0]) fill_wave(h_arr, samplate=sr, axes=axes[1]) fill_wave(p_arr, samplate=sr, axes=axes[2]) audio_len = audio_arr.shape[-1] fig, axes = plt.subplots(nrows=3, sharex=True, sharey=True) fill_spec(origin_spec_arr, axes=axes[0], x_coords=bft_obj.x_coords(audio_len), y_coords=bft_obj.y_coords(), y_axis='log', title='origin spec') fill_spec(h_spec_arr, axes=axes[1], x_coords=bft_obj.x_coords(audio_len), y_coords=bft_obj.y_coords(), y_axis='log', title='h spec') fill_spec(p_spec_arr, axes=axes[2], x_coords=bft_obj.x_coords(audio_len), y_coords=bft_obj.y_coords(), y_axis='log', title='p spec') plt.show() ``` -------------------------------- ### View Help for Benchmark Scripts Source: https://github.com/libaudioflux/audioflux/blob/master/benchmark/README.md Execute this command to view detailed usage instructions and available options for the benchmark scripts. ```shell python run_xxx.py --help ``` -------------------------------- ### Build Android with build_android.sh Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Execute this script from the audioFlux project's scripts directory to build and compile for Android. ```bash ./build_android.sh ``` -------------------------------- ### Build iOS with build_iOS.sh Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installing.md Execute this script from the audioFlux project's scripts directory to build and compile for iOS. ```bash ./build_iOS.sh ``` -------------------------------- ### Windows Build Configuration Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Configures the build for Windows, enabling FFTW3 support and setting flags for dynamic library export. ```cmake elseif (${CMAKE_SYSTEM_NAME} MATCHES "win64") # -Wl,-rpath=. # -Wl,--out-implib,./audioflux.lib MSVC lib set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_FFTW3F -Wl,-rpath=. ") set(BUILD_SHARED_LIBS true) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS true) set(fftwPath ../scripts/windows/fftw3) include_directories(${fftwPath}) link_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR}) # add so, include source path add_library(audioflux SHARED ${SOURCES}) # link target lib target_link_libraries(audioflux fftw3f-3 ) install(TARGETS audioflux DESTINATION lib) ``` -------------------------------- ### Run Benchmark for Multiple Libraries Source: https://github.com/libaudioflux/audioflux/blob/master/benchmark/README.md Use this command to compare the performance of multiple audio feature extraction libraries. Specify the libraries, number of samples, number of runs, and test times. ```shell python run_benchmark.py -p audioflux,torchaudio,librosa -r 1000 -er 10 -t 1,5,10,100,500,1000,2000,3000 ``` -------------------------------- ### Batch Feature Extraction with FeatureExtractor Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/featureExtractor.rst Demonstrates how to initialize FeatureExtractor and extract various features like spectrogram, spectral flux, xxcc, and deconv from an audio file. Requires audioflux and SpectralFilterBankScaleType imports. ```python # Get a 880Hz's audio file import audioflux as af from audioflux.type import SpectralFilterBankScaleType sample_path = af.utils.sample_path('880') audio_arr, sr = af.read(sample_path) # Create FeatureExtractor object and extract spectrogram fa_obj = af.FeatureExtractor(transforms=['bft', 'cwt', 'cqt'], samplate=sr, radix2_exp=12, scale_type=SpectralFilterBankScaleType.OCTAVE) spec_result = fa_obj.spectrogram(audio_arr, is_continue=True) #Extract spectral/xxcc/deconv spectral_result = fa_obj.spectral(spec_result, spectral='flux', spectral_kw={'is_positive': True}) xxcc_result = fa_obj.xxcc(spec_result, cc_num=13) deconv_result = fa_obj.deconv(spec_result) ``` -------------------------------- ### Run Benchmark for a Single Library Source: https://github.com/libaudioflux/audioflux/blob/master/benchmark/README.md Use this command to test the performance of a single audio feature extraction library. Specify the library, number of samples, and test times. ```shell python run_audioflux.py -r 1000 -t 1,5,10,100,500,1000,2000,3000 ``` -------------------------------- ### Set MKL environment variables on Linux Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Configure MKL_INCLUDE_PATH and MKL_LIB_PATH environment variables if using Intel MKL library on Linux. This is optional but recommended for performance. ```bash $ export MKL_INCLUDE_PATH=/opt/intel/oneapi/mkl/latest/include $ export MKL_LIB_PATH=/opt/intel/oneapi/mkl/latest/lib/intel64 ``` -------------------------------- ### Build Android with audioFlux script Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Run the build script for Android from the audioFlux project's scripts directory. This compiles the library for Android. ```bash $ ./build_android.sh ``` -------------------------------- ### OHOS Build Configuration Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Configures the build for the OHOS platform, enabling FFTW3 support and setting optimization flags. ```cmake elseif (DEFINED OHOS_PLATFORM) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_FFTW3F ") # strip set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -DNDEBUG -Wl,-s") if(${OHOS_ARCH} MATCHES "armeabi-v7a") set(fftwPath ../scripts/ohos/fftw3/armeabi-v7a) elseif(${OHOS_ARCH} MATCHES "arm64-v8a") set(fftwPath ../scripts/ohos/fftw3/arm64-v8a) endif() ``` -------------------------------- ### Android Build Configuration Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Configures the build for Android, enabling FFTW3 support and dynamically linking against system libraries like 'log'. ```cmake elseif (${CMAKE_SYSTEM_NAME} MATCHES "android") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE_FFTW3F ") # strip set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-s") if(${CMAKE_ANDROID_ARCH_ABI} MATCHES "armeabi-v7a") set(fftwPath ../scripts/android/fftw3/armeabi-v7a) elseif(${CMAKE_ANDROID_ARCH_ABI} MATCHES "arm64-v8a") set(fftwPath ../scripts/android/fftw3/arm64-v8a) elseif(${CMAKE_ANDROID_ARCH_ABI} MATCHES "armeabi") set(fftwPath ../scripts/android/fftw3/armeabi) endif() include_directories(${fftwPath}) link_directories(${fftwPath}) # add dylib, include source path add_library(audioflux SHARED ${SOURCES}) # search system lib, ndk-10e is not support find_library ( # Sets the name of the path variable. syslibs log android) # link target lib target_link_libraries(audioflux fftw3f log) install(TARGETS audioflux DESTINATION lib) ``` -------------------------------- ### Extract CQT and Chroma CQT (Object-Oriented) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/cqt_chroma.rst Utilize the CQT class for more flexible and efficient extraction. This approach allows for pre-configuration of parameters. ```python import numpy as np import audioflux as af # Get a 220Hz's audio file path sample_path = af.utils.sample_path('220') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) # Create CQT object cqt_obj = af.CQT(num=84, samplate=sr) # Extract CQT and Chroma_cqt cqt_arr = cqt_obj.cqt(audio_arr) chroma_cqt_arr = cqt_obj.chroma(cqt_arr) ``` -------------------------------- ### Build iOS with audioFlux script Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Execute the build script for iOS within the audioFlux project's scripts directory. This compiles the library for iOS. ```bash $ ./build_iOS.sh ``` -------------------------------- ### Linux Build Configuration Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Configures the build for Linux, allowing for custom compiler paths, OpenMP, and optional MKL (Math Kernel Library) integration. ```cmake elseif (${CMAKE_SYSTEM_NAME} MATCHES "linux") set(CMAKE_C_COMPILER "/usr/bin/clang") set(CMAKE_CXX_COMPILER "/usr/bin/clang++") if (DEFINED ENV{AF_BUILD_PY_BDIST}) message("Build py_bdist version") set(OMP_PATH "../scripts/linux/openmp") set(MKL_INCLUDE_PATH "../scripts/linux/mkl/include") set(MKL_LIB_PATH "../scripts/linux/mkl") include_directories(${OMP_PATH}) link_directories(${OMP_PATH}) else() set(MKL_INCLUDE_PATH $ENV{MKL_INCLUDE_PATH}) set(MKL_LIB_PATH $ENV{MKL_LIB_PATH}) endif() message("Using MKL_INCLUDE_PATH: ${MKL_INCLUDE_PATH}") message("Using MKL_LIB_PATH: ${MKL_LIB_PATH}") if (MKL_LIB_PATH) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -DHAVE_MKL -DHAVE_OMP -fopenmp=libomp -Wl,-rpath,${MKL_LIB_PATH} ") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -DHAVE_OMP -fopenmp=libomp ") endif() if (MKL_INCLUDE_PATH) include_directories(${MKL_INCLUDE_PATH}) endif() if (MKL_LIB_PATH) link_directories(${MKL_LIB_PATH}) endif() include_directories(${PROJECT_SOURCE_DIR}) link_directories(${PROJECT_SOURCE_DIR}) # add so, include source path add_library(audioflux SHARED ${SOURCES}) # link target lib if (MKL_LIB_PATH) target_link_libraries(audioflux mkl_intel_lp64 mkl_core mkl_intel_thread omp m) else() target_link_libraries(audioflux omp m) endif() install(TARGETS audioflux DESTINATION lib) ``` -------------------------------- ### Extract CQT and Chroma CQT (Functional) Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/cqt_chroma.rst Use the functional API for straightforward extraction of CQT and Chroma CQT. Requires audio data and sample rate. ```python import numpy as np import audioflux as af # Get a 220Hz's audio file path sample_path = af.utils.sample_path('220') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) # Extract CQT cqt_arr, _ = af.cqt(audio_arr, samplate=sr) # Extract CQT_CHROMA chroma_cqt_arr = af.chroma_cqt(audio_arr, samplate=sr) ``` -------------------------------- ### iOS Build Configuration Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Configures the build for iOS, enabling the Accelerate framework and setting optimization flags for release builds. ```cmake if(${CMAKE_SYSTEM_NAME} MATCHES "iOS") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_ACCELERATE") # set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG") # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-s") add_library(audioflux ${SOURCES}) target_link_libraries(audioflux "-framework Accelerate") install(TARGETS audioflux DESTINATION lib) ``` -------------------------------- ### CQT and Chroma-CQT Spectrograms Source: https://github.com/libaudioflux/audioflux/blob/master/docs/examples.md Extracts and displays Constant-Q Transform (CQT) spectrogram and its corresponding Chroma-CQT representation. Requires audioflux, numpy, and matplotlib. ```python import numpy as np import audioflux as af import matplotlib.pyplot as plt from audioflux.display import fill_spec # Read audio data and sample rate audio_arr, sr = af.read(af.utils.sample_path('guitar_chord2')) # Create CQT object cqt_obj = af.CQT(num=84, samplate=sr) # Extract CQT and Chroma_cqt cqt_arr = cqt_obj.cqt(audio_arr) chroma_cqt_arr = cqt_obj.chroma(cqt_arr) # Display audio_len = audio_arr.shape[-1] # Display CQT fig, ax = plt.subplots() img = fill_spec(np.abs(cqt_arr), axes=ax, x_coords=cqt_obj.x_coords(audio_len), x_axis='time', y_coords=cqt_obj.y_coords(), y_axis='log', title='CQT') fig.colorbar(img, ax=ax) # Display Chroma_CQT fig, ax = plt.subplots() img = fill_spec(chroma_cqt_arr, axes=ax, x_coords=cqt_obj.x_coords(audio_len), x_axis='time', y_axis='chroma', title='Chroma-CQT') fig.colorbar(img, ax=ax) plt.show() ``` -------------------------------- ### macOS Build Configuration Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Configures the build for macOS, allowing for custom compiler paths, OpenMP support, and linking against the Accelerate framework. ```cmake elseif (${CMAKE_SYSTEM_NAME} MATCHES "darwin") set(CMAKE_C_COMPILER $ENV{C_COMPILER_PATH}) set(CMAKE_CXX_COMPILER $ENV{CXX_COMPILER_PATH}) if (DEFINED ENV{AF_BUILD_PY_BDIST}) message("Build py_bdist version") set(ompPath ../scripts/macOS/openmp) include_directories(${ompPath}) link_directories(${ompPath}) endif() # set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG") # set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-s") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -DHAVE_ACCELERATE -DHAVE_OMP -fopenmp ") add_library(audioflux SHARED ${SOURCES}) target_link_libraries(audioflux "-framework Accelerate" omp ) install(TARGETS audioflux DESTINATION lib) ``` -------------------------------- ### Set Android NDK environment variables Source: https://github.com/libaudioflux/audioflux/blob/master/docs/installation.rst Configure the NDK_ROOT and PATH environment variables for Android development. This is necessary for building audioFlux on Android. ```bash $ export NDK_ROOT=~/Android/android-ndk-r16b $ export PATH=$NDK_ROOT:$PATH ``` -------------------------------- ### PitchYIN Source: https://github.com/libaudioflux/audioflux/blob/master/docs/mir/pitch.rst Implements the YIN pitch detection algorithm. ```APIDOC ## PitchYIN ### Description Implements the YIN pitch detection algorithm. This method is known for its accuracy and robustness in estimating the fundamental frequency of audio signals. ### Class `audioflux.PitchYIN` ### Methods (Members of the class are documented in the source, but specific method signatures are not provided in this snippet.) ``` -------------------------------- ### Include and Link Directories Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Specifies the directories where CMake should look for header files and libraries, particularly for the FFTW dependency. ```cmake include_directories(${fftwPath}) link_directories(${fftwPath}) ``` -------------------------------- ### audioflux.write Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Writes audio data to a file. ```APIDOC ## audioflux.write ### Description Writes audio data to a file. ### Method N/A (Function) ### Parameters * **path** (str) - Path to save the audio file. * **audio** (np.ndarray) - The audio data to write. * **sample_rate** (int) - The sample rate of the audio. ### Response None. ``` -------------------------------- ### Display CQT and Chroma CQT Spectrograms Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/cqt_chroma.rst Visualize the extracted CQT and Chroma CQT using matplotlib. Requires the fill_spec function for plotting. ```python # Display import matplotlib.pyplot as plt from audioflux.display import fill_spec audio_len = audio_arr.shape[-1] # Display CQT fig, ax = plt.subplots() img = fill_spec(np.abs(cqt_arr), axes=ax, x_coords=cqt_obj.x_coords(audio_len), x_axis='time', y_coords=cqt_obj.y_coords(), y_axis='log', title='CQT') fig.colorbar(img, ax=ax) # Display Chroma_cqt fig, ax = plt.subplots() img = fill_spec(chroma_cqt_arr, axes=ax, x_coords=cqt_obj.x_coords(audio_len), x_axis='time', y_axis='chroma', title='Chroma-CQT') fig.colorbar(img, ax=ax) ``` -------------------------------- ### CWT and Synchrosqueezing Spectrograms Source: https://github.com/libaudioflux/audioflux/blob/master/docs/examples.md Generates and displays Continuous Wavelet Transform (CWT) spectrogram and its corresponding synchrosqueezing reassignment spectrogram. Requires audioflux, numpy, and matplotlib. ```python import numpy as np import audioflux as af from audioflux.type import SpectralFilterBankScaleType, WaveletContinueType from audioflux.utils import note_to_hz import matplotlib.pyplot as plt from audioflux.display import fill_spec # Get a 220Hz's audio file path sample_path = af.utils.sample_path('220') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) audio_arr = audio_arr[..., :4096] cwt_obj = af.CWT(num=84, radix2_exp=12, samplate=sr, low_fre=note_to_hz('C1'), bin_per_octave=12, wavelet_type=WaveletContinueType.MORSE, scale_type=SpectralFilterBankScaleType.OCTAVE) cwt_spec_arr = cwt_obj.cwt(audio_arr) synsq_obj = af.Synsq(num=cwt_obj.num, radix2_exp=cwt_obj.radix2_exp, samplate=cwt_obj.samplate) synsq_arr = synsq_obj.synsq(cwt_spec_arr, filter_bank_type=cwt_obj.scale_type, fre_arr=cwt_obj.get_fre_band_arr()) # Show CWT fig, ax = plt.subplots(figsize=(7, 4)) img = fill_spec(np.abs(cwt_spec_arr), axes=ax, x_coords=cwt_obj.x_coords(), y_coords=cwt_obj.y_coords(), x_axis='time', y_axis='log', title='CWT') fig.colorbar(img, ax=ax) # Show Synsq fig, ax = plt.subplots(figsize=(7, 4)) img = fill_spec(np.abs(synsq_arr), axes=ax, x_coords=cwt_obj.x_coords(), y_coords=cwt_obj.y_coords(), x_axis='time', y_axis='log', title='Synsq') fig.colorbar(img, ax=ax) plt.show() ``` -------------------------------- ### audioflux.WaveWriter Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst A class for writing wave files. ```APIDOC ## audioflux.WaveWriter ### Description A class for writing wave files. ### Methods * **__init__(self, path, sample_rate)**: Initializes the WaveWriter. * **path** (str) - Path to save the wave file. * **sample_rate** (int) - Sample rate of the audio. * **write(self, audio)**: Writes audio data to the file. * **audio** (np.ndarray) - The audio data to write. * **close(self)**: Closes the wave file. ``` -------------------------------- ### Link Target Library Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Links the audioflux library against the fftw3f library, ensuring all its symbols are available. ```cmake target_link_libraries(audioflux fftw3f) ``` -------------------------------- ### PitchFFP Source: https://github.com/libaudioflux/audioflux/blob/master/docs/mir/pitch.rst Implements the Frequency-domain Fundamental Frequency Prediction (FFP) algorithm. ```APIDOC ## PitchFFP ### Description Implements the Frequency-domain Fundamental Frequency Prediction (FFP) algorithm. This method predicts the fundamental frequency based on frequency-domain characteristics. ### Class `audioflux.PitchFFP` ### Methods (Members of the class are documented in the source, but specific method signatures are not provided in this snippet.) ``` -------------------------------- ### Advanced MFCC Extraction with BFT and XXCC Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/mfcc.rst This snippet demonstrates a more flexible MFCC extraction process using the BFT and XXCC classes. It involves creating BFT for mel spectrogram and then XXCC for MFCC, allowing for parameter tuning. Matplotlib is used for visualization. ```python import numpy as np import audioflux as af from audioflux.type import SpectralFilterBankScaleType, SpectralDataType # Get a 220Hz's audio file path sample_path = af.utils.sample_path('220') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) # Create BFT object and extract mel spectrogram bft_obj = af.BFT(num=128, radix2_exp=12, samplate=sr, scale_type=SpectralFilterBankScaleType.MEL, data_type=SpectralDataType.POWER) spec_arr = bft_obj.bft(audio_arr) spec_arr = np.abs(spec_arr) # Create XXCC object and extract mfcc xxcc_obj = af.XXCC(bft_obj.num) xxcc_obj.set_time_length(time_length=spec_arr.shape[-1]) mfcc_arr = xxcc_obj.xxcc(spec_arr) # Display MFCC import matplotlib.pyplot as plt from audioflux.display import fill_spec audio_len = audio_arr.shape[-1] fig, ax = plt.subplots() img = fill_spec(mfcc_arr, axes=ax, x_coords=bft_obj.x_coords(audio_len), x_axis='time', title='MFCC') fig.colorbar(img, ax=ax) ``` -------------------------------- ### Extract and Visualize CWT Spectrogram Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/cwt.rst This snippet demonstrates how to compute the Continuous Wavelet Transform (CWT) of an audio signal and visualize it as a spectrogram. It requires NumPy, AudioFlux, and Matplotlib. Ensure the audio data length matches the FFT length specified by radix2_exp. ```python import numpy as np import audioflux as af from audioflux.type import SpectralFilterBankScaleType, WaveletContinueType # Get a 880Hz's audio file path sample_path = af.utils.sample_path('880') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) # Create CWT object and extract cwt cwt_obj = af.CWT(num=84, radix2_exp=12, samplate=sr, wavelet_type=WaveletContinueType.MORSE, scale_type=SpectralFilterBankScaleType.OCTAVE) # The cwt() method can only extract data of fft_length=2**radix2_exp=4096 cwt_arr = cwt_obj.cwt(audio_arr[..., :4096]) cwt_arr = np.abs(cwt_arr) # Display spectrogram import matplotlib.pyplot as plt from audioflux.display import fill_spec audio_len = audio_arr.shape[-1] fig, ax = plt.subplots() img = fill_spec(cwt_arr, axes=ax, x_coords=cwt_obj.x_coords(), y_coords=cwt_obj.y_coords(), x_axis='time', y_axis='log', title='CWT Spectrogram') fig.colorbar(img, ax=ax) ``` -------------------------------- ### Comparison of Different Wavelet Types Source: https://github.com/libaudioflux/audioflux/blob/master/docs/examples.md Compares spectrograms generated using different continuous wavelet types (Morlet, Morse, Paul, Bump). Requires audioflux, numpy, matplotlib, and specific type imports. ```python import numpy as np import audioflux as af from audioflux.type import SpectralFilterBankScaleType, WaveletContinueType from audioflux.utils import note_to_hz import matplotlib.pyplot as plt from audioflux.display import fill_spec, fill_wave ``` -------------------------------- ### audioflux.utils.log10_compress Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Applies base-10 logarithmic compression to the input signal. ```APIDOC ## audioflux.utils.log10_compress ### Description Applies base-10 logarithmic compression to the input signal. ### Method N/A (Utility function) ### Parameters * **x** (numeric) - The input signal. * **c** (numeric, optional) - Compression factor. Defaults to 1. ### Response * **compressed_x** (numeric) - The base-10 logarithmically compressed signal. ``` -------------------------------- ### Pitch Estimation using YIN Source: https://github.com/libaudioflux/audioflux/blob/master/docs/examples.md Estimates the fundamental frequency (F0) of an audio signal using the YIN algorithm. Requires audio data and sample rate. Displays the waveform and the estimated fundamental frequency over time. ```python import numpy as np import audioflux as af from audioflux.type import PitchType import matplotlib.pyplot as plt from audioflux.display import fill_wave # Read audio data and sample rate audio_arr, sr = af.read(af.utils.sample_path('voice')) obj = af.Pitch(pitch_type=PitchType.YIN) fre_arr, value_arr1, value_arr2 = obj.pitch(audio_arr) fre_arr[fre_arr < 1] = np.nan # Display fig, ax = plt.subplots(nrows=2, figsize=(8, 6), sharex=True) times = np.arange(0, fre_arr.shape[-1]) * (obj.slide_length / obj.samplate) fill_wave(audio_arr, samplate=sr, axes=ax[0]) ax[1].xaxis.set_label_text("Time(s)") ax[1].yaxis.set_label_text("Frequency(Hz)") ax[1].plot(times, fre_arr, label='fre', linewidth=3) ``` -------------------------------- ### PitchCEP Source: https://github.com/libaudioflux/audioflux/blob/master/docs/mir/pitch.rst Implements the Cepstral Pitch Estimation (CEP) algorithm. ```APIDOC ## PitchCEP ### Description Implements the Cepstral Pitch Estimation (CEP) algorithm. This method utilizes the cepstrum to find the fundamental frequency. ### Class `audioflux.PitchCEP` ### Methods (Members of the class are documented in the source, but specific method signatures are not provided in this snippet.) ``` -------------------------------- ### Add Shared Library Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Defines the audioflux library as a shared library, including all specified source files. ```cmake add_library(audioflux SHARED ${SOURCES}) ``` -------------------------------- ### Flexible Mel Spectrogram Extraction with BFT Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/mel.rst This approach uses the BFT (Based Fourier Transform) class for more flexible and efficient mel spectrogram extraction. It allows for customization of parameters like the number of bands and radix-2 exponent, and requires additional imports for type and display utilities. ```python import numpy as np import audioflux as af from audioflux.type import SpectralFilterBankScaleType # Get a 220Hz's audio file path sample_path = af.utils.sample_path('220') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) # Create BFT object and extract mel spectrogram bft_obj = af.BFT(num=128, radix2_exp=12, samplate=sr, scale_type=SpectralFilterBankScaleType.MEL) spec_arr = bft_obj.bft(audio_arr) spec_arr = np.abs(spec_arr) # Display spectrogram import matplotlib.pyplot as plt from audioflux.display import fill_spec audio_len = audio_arr.shape[-1] fig, ax = plt.subplots() img = fill_spec(spec_arr, axes=ax, x_coords=bft_obj.x_coords(audio_len), y_coords=bft_obj.y_coords(), x_axis='time', y_axis='log', title='Mel Spectrogram') fig.colorbar(img, ax=ax) ``` -------------------------------- ### Simple MFCC Extraction Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/mfcc.rst This snippet shows the basic usage of the `af.mfcc` function for extracting MFCC from an audio file. It requires numpy and audioflux libraries. ```python import numpy as np import audioflux as af # Get a 220Hz's audio file path sample_path = af.utils.sample_path('220') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) # Extract mfcc mfcc_arr, _ = af.mfcc(audio_arr, samplate=sr) ``` -------------------------------- ### audioflux.utils.log_compress Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Applies logarithmic compression to the input signal. ```APIDOC ## audioflux.utils.log_compress ### Description Applies logarithmic compression to the input signal. ### Method N/A (Utility function) ### Parameters * **x** (numeric) - The input signal. * **c** (numeric, optional) - Compression factor. Defaults to 1. ### Response * **compressed_x** (numeric) - The logarithmically compressed signal. ``` -------------------------------- ### Source Directory Collection Source: https://github.com/libaudioflux/audioflux/blob/master/src/CMakeLists.txt Collects source files from various subdirectories into a single list for the build process. ```cmake aux_source_directory(vector vector) aux_source_directory(util util) aux_source_directory(dsp dsp) aux_source_directory(classic classic) aux_source_directory(filterbank filterbank) aux_source_directory(feature feature) aux_source_directory(mir mir) aux_source_directory(track track) aux_source_directory(. SOURCES) list(APPEND SOURCES ${vector} ${util} ${dsp} ${classic} ${filterbank} ${feature} ${mir} ${track}) ``` -------------------------------- ### audioflux.WaveReader Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst A class for reading wave files. ```APIDOC ## audioflux.WaveReader ### Description A class for reading wave files. ### Methods * **__init__(self, path, mono=False)**: Initializes the WaveReader. * **path** (str) - Path to the wave file. * **mono** (bool, optional) - Whether to convert to mono. Defaults to False. * **read(self)**: Reads the audio data. * **Returns**: (np.ndarray, int) - Audio data and sample rate. * **close(self)**: Closes the wave file. ``` -------------------------------- ### audioflux.read Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Reads an audio file. ```APIDOC ## audioflux.read ### Description Reads an audio file. ### Method N/A (Function) ### Parameters * **path** (str) - Path to the audio file. * **mono** (bool, optional) - Whether to convert to mono. Defaults to False. ### Response * **audio** (np.ndarray) - The audio data. * **sample_rate** (int) - The sample rate of the audio. ``` -------------------------------- ### audioflux.convert_mono Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Converts audio data to mono. ```APIDOC ## audioflux.convert_mono ### Description Converts audio data to mono. ### Method N/A (Function) ### Parameters * **audio** (np.ndarray) - The input audio data. ### Response * **mono_audio** (np.ndarray) - The mono audio data. ``` -------------------------------- ### PitchHPS Source: https://github.com/libaudioflux/audioflux/blob/master/docs/mir/pitch.rst Implements the Harmonic Product Spectrum (HPS) pitch detection algorithm. ```APIDOC ## PitchHPS ### Description Implements the Harmonic Product Spectrum (HPS) pitch detection algorithm. HPS is effective in identifying harmonic structures to determine the fundamental frequency. ### Class `audioflux.PitchHPS` ### Methods (Members of the class are documented in the source, but specific method signatures are not provided in this snippet.) ``` -------------------------------- ### Set Real Plot for Pitch Detection Source: https://github.com/libaudioflux/audioflux/blob/master/docs/examples.md This snippet visualizes detected frequencies over time, highlighting specific notes with different colors. It uses NumPy for array manipulation and Matplotlib for plotting. ```python import numpy as np import matplotlib.pyplot as plt # Assuming fre_arr and times are already defined # fre_arr = ... # times = ... real_fre_arr = np.zeros_like(fre_arr) real_fre_arr[25:48] = 261.6 real_fre_arr[56:78] = 293.7 real_fre_arr[87:107] = 329.6 real_fre_arr[118:135] = 349.2 real_fre_arr[150:169] = 392.0 real_fre_arr[179:200] = 440.0 real_fre_arr[212:243] = 493.9 real_fre_arr[real_fre_arr == 0] = np.nan # Assuming ax is a Matplotlib Axes object # ax = ... # ax[1].plot(times, real_fre_arr, color='red', label='fre', linewidth=2) # plt.show() ``` -------------------------------- ### audioflux.utils.midi_to_note Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Converts a MIDI number to its musical note representation. ```APIDOC ## audioflux.utils.midi_to_note ### Description Converts a MIDI number to its musical note representation. ### Method N/A (Utility function) ### Parameters * **midi_number** (int) - The MIDI number. ### Response * **note** (str) - The musical note (e.g., 'C4'). ``` -------------------------------- ### audioflux.utils.power_to_db Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Converts power to decibels (dB). ```APIDOC ## audioflux.utils.power_to_db ### Description Converts power to decibels (dB). ### Method N/A (Utility function) ### Parameters * **power** (numeric) - The input power value. * **ref_value** (numeric, optional) - The reference value for dB calculation. Defaults to 1. * **clip_min** (numeric, optional) - Minimum value to clip the result. Defaults to None. ### Response * **db** (numeric) - The converted decibel value. ``` -------------------------------- ### Simple Mel Spectrogram Extraction Source: https://github.com/libaudioflux/audioflux/blob/master/docs/quickStart/mel.rst Use this method for straightforward mel spectrogram extraction. It requires importing numpy and audioflux, reading audio data, and then calling the mel_spectrogram function. ```python import numpy as np import audioflux as af # Get a 220Hz's audio file path sample_path = af.utils.sample_path('220') # Read audio data and sample rate audio_arr, sr = af.read(sample_path) # Extract mel spectrogram spec_arr, _ = af.mel_spectrogram(audio_arr, samplate=sr) ``` -------------------------------- ### PitchPEF Source: https://github.com/libaudioflux/audioflux/blob/master/docs/mir/pitch.rst Implements the Pitch Estimation Filter (PEF) pitch detection algorithm. ```APIDOC ## PitchPEF ### Description Implements the Pitch Estimation Filter (PEF) pitch detection algorithm. This algorithm offers an alternative approach to fundamental frequency estimation. ### Class `audioflux.PitchPEF` ### Methods (Members of the class are documented in the source, but specific method signatures are not provided in this snippet.) ``` -------------------------------- ### PitchLHS Source: https://github.com/libaudioflux/audioflux/blob/master/docs/mir/pitch.rst Implements the Local Harmonic Sum (LHS) pitch detection algorithm. ```APIDOC ## PitchLHS ### Description Implements the Local Harmonic Sum (LHS) pitch detection algorithm. This method focuses on local harmonic relationships for pitch estimation. ### Class `audioflux.PitchLHS` ### Methods (Members of the class are documented in the source, but specific method signatures are not provided in this snippet.) ``` -------------------------------- ### audioflux.utils.auditory_weight_a Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Applies A-weighting to a signal. ```APIDOC ## audioflux.utils.auditory_weight_a ### Description Applies A-weighting to a signal. ### Method N/A (Utility function) ### Parameters * **x** (numeric) - The input signal. * **sample_rate** (int) - The sample rate of the signal. ### Response * **weighted_x** (numeric) - The A-weighted signal. ``` -------------------------------- ### audioflux.utils.auditory_weight_c Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Applies C-weighting to a signal. ```APIDOC ## audioflux.utils.auditory_weight_c ### Description Applies C-weighting to a signal. ### Method N/A (Utility function) ### Parameters * **x** (numeric) - The input signal. * **sample_rate** (int) - The sample rate of the signal. ### Response * **weighted_x** (numeric) - The C-weighted signal. ``` -------------------------------- ### audioflux.utils.hz_to_midi Source: https://github.com/libaudioflux/audioflux/blob/master/docs/utils.rst Converts a frequency in Hz to its closest MIDI number. ```APIDOC ## audioflux.utils.hz_to_midi ### Description Converts a frequency in Hz to its closest MIDI number. ### Method N/A (Utility function) ### Parameters * **frequency** (float) - The frequency in Hz. * **a4_freq** (float, optional) - The frequency of A4. Defaults to 440.0. ### Response * **midi_number** (int) - The closest MIDI number. ```