# Path: pyAudioAnalysis/audioBasicIO.py
# def convert_dir_mp3_to_wav(audio_folder, sampling_rate, num_channels,
#                            use_tags=False):
# def convert_dir_fs_wav_to_wav(audio_folder, sampling_rate, num_channels):
# def read_audio_file(input_file):
# def read_aif(path):
# def read_audio_generic(input_file):
# def stereo_to_mono(signal):
# 
# Path: pyAudioAnalysis/ShortTermFeatures.py
# def dc_normalize(sig_array):
# def zero_crossing_rate(frame):
# def energy(frame):
# def energy_entropy(frame, n_short_blocks=10):
# def spectral_centroid_spread(fft_magnitude, sampling_rate):
# def spectral_entropy(signal, n_short_blocks=10):
# def spectral_flux(fft_magnitude, previous_fft_magnitude):
# def spectral_rolloff(signal, c):
# def harmonic(frame, sampling_rate):
# def mfcc_filter_banks(sampling_rate, num_fft, lowfreq=133.33, linc=200 / 3,
#                       logsc=1.0711703, num_lin_filt=13, num_log_filt=27):
# def mfcc(fft_magnitude, fbank, num_mfcc_feats):
# def chroma_features_init(num_fft, sampling_rate):
# def chroma_features(signal, sampling_rate, num_fft):
# def chromagram(signal, sampling_rate, window, step, plot=False,
#                show_progress=False):
# def spectrogram(signal, sampling_rate, window, step, plot=False,
#                 show_progress=False):
# def speed_feature(signal, sampling_rate, window, step):
# def phormants(x, sampling_rate):
# def feature_extraction(signal, sampling_rate, window, step, deltas=True):
#     NUM = np.sum(ind * Xt)
#     DEN = np.sum(Xt) + eps
#         C = np.zeros((num_chroma.shape[0],))
#         I = np.nonzero(num_chroma > num_chroma.shape[0])[0][0]
#         C = np.zeros((num_chroma.shape[0],))
#     C2 = np.zeros((newD,))
#     C2 = C2.reshape(int(C2.shape[0] / 12), 12)
#         X = abs(fft(x))
#         X = X[0:num_fft]
#         X = X / len(X)
#         X = abs(fft(x))
#         X = X[0:num_fft]
#         X = X / len(X)
#     N = len(x)
# 
# Path: pyAudioAnalysis/MidTermFeatures.py
# def beat_extraction(short_features, window_size, plot=False):
# def mid_feature_extraction(signal, sampling_rate, mid_window, mid_step,
#                            short_window, short_step):
# def directory_feature_extraction(folder_path, mid_window, mid_step,
#                                  short_window, short_step,
#                                  compute_beat=True):
# def multiple_directory_feature_extraction(path_list, mid_window, mid_step,
#                                           short_window, short_step,
#                                           compute_beat=False):
# def directory_feature_extraction_no_avg(folder_path, mid_window, mid_step,
#                                         short_window, short_step):
# def mid_feature_extraction_to_file(file_path, mid_window, mid_step,
#                                    short_window, short_step, output_file,
#                                    store_short_features=False, store_csv=False,
#                                    plot=False):
# def mid_feature_extraction_file_dir(folder_path, mid_window, mid_step,
#                                     short_window, short_step,
#                                     store_short_features=False, store_csv=False,
#                                     plot=False):


import sys
import os
from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import ShortTermFeatures
from pyAudioAnalysis import MidTermFeatures
sys.path.insert(0, os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "../"))


def test_feature_extraction_short():
    [fs, x] = audioBasicIO.read_audio_file("test_data/1_sec_wav.wav")
    F, f_names = ShortTermFeatures.feature_extraction(x, fs, 
                                                      0.050 * fs, 0.050 * fs)
    assert F.shape[1] == 20, "Wrong number of mid-term windows"
    assert F.shape[0] == len(f_names), "Number of features and feature " \
                                       "names are not the same"


def test_feature_extraction_segment():
    print("Short-term feature extraction")

# Path: pyAudioAnalysis/audioBasicIO.py
# def convert_dir_mp3_to_wav(audio_folder, sampling_rate, num_channels,
#                            use_tags=False):
# def convert_dir_fs_wav_to_wav(audio_folder, sampling_rate, num_channels):
# def read_audio_file(input_file):
# def read_aif(path):
# def read_audio_generic(input_file):
# def stereo_to_mono(signal):
# 
# Path: pyAudioAnalysis/ShortTermFeatures.py
# def dc_normalize(sig_array):
# def zero_crossing_rate(frame):
# def energy(frame):
# def energy_entropy(frame, n_short_blocks=10):
# def spectral_centroid_spread(fft_magnitude, sampling_rate):
# def spectral_entropy(signal, n_short_blocks=10):
# def spectral_flux(fft_magnitude, previous_fft_magnitude):
# def spectral_rolloff(signal, c):
# def harmonic(frame, sampling_rate):
# def mfcc_filter_banks(sampling_rate, num_fft, lowfreq=133.33, linc=200 / 3,
#                       logsc=1.0711703, num_lin_filt=13, num_log_filt=27):
# def mfcc(fft_magnitude, fbank, num_mfcc_feats):
# def chroma_features_init(num_fft, sampling_rate):
# def chroma_features(signal, sampling_rate, num_fft):
# def chromagram(signal, sampling_rate, window, step, plot=False,
#                show_progress=False):
# def spectrogram(signal, sampling_rate, window, step, plot=False,
#                 show_progress=False):
# def speed_feature(signal, sampling_rate, window, step):
# def phormants(x, sampling_rate):
# def feature_extraction(signal, sampling_rate, window, step, deltas=True):
#     NUM = np.sum(ind * Xt)
#     DEN = np.sum(Xt) + eps
#         C = np.zeros((num_chroma.shape[0],))
#         I = np.nonzero(num_chroma > num_chroma.shape[0])[0][0]
#         C = np.zeros((num_chroma.shape[0],))
#     C2 = np.zeros((newD,))
#     C2 = C2.reshape(int(C2.shape[0] / 12), 12)
#         X = abs(fft(x))
#         X = X[0:num_fft]
#         X = X / len(X)
#         X = abs(fft(x))
#         X = X[0:num_fft]
#         X = X / len(X)
#     N = len(x)
# 
# Path: pyAudioAnalysis/MidTermFeatures.py
# def beat_extraction(short_features, window_size, plot=False):
# def mid_feature_extraction(signal, sampling_rate, mid_window, mid_step,
#                            short_window, short_step):
# def directory_feature_extraction(folder_path, mid_window, mid_step,
#                                  short_window, short_step,
#                                  compute_beat=True):
# def multiple_directory_feature_extraction(path_list, mid_window, mid_step,
#                                           short_window, short_step,
#                                           compute_beat=False):
# def directory_feature_extraction_no_avg(folder_path, mid_window, mid_step,
#                                         short_window, short_step):
# def mid_feature_extraction_to_file(file_path, mid_window, mid_step,
#                                    short_window, short_step, output_file,
#                                    store_short_features=False, store_csv=False,
#                                    plot=False):
# def mid_feature_extraction_file_dir(folder_path, mid_window, mid_step,
#                                     short_window, short_step,
#                                     store_short_features=False, store_csv=False,
#                                     plot=False):


# Path: pytests/test_feature_extraction.py
import sys
import os
from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import ShortTermFeatures
from pyAudioAnalysis import MidTermFeatures

sys.path.insert(0, os.path.join(os.path.dirname(
    os.path.realpath(__file__)), "../"))


def test_feature_extraction_short():
    [fs, x] = audioBasicIO.read_audio_file("test_data/1_sec_wav.wav")
    F, f_names = ShortTermFeatures.feature_extraction(x, fs, 
                                                      0.050 * fs, 0.050 * fs)
    assert F.shape[1] == 20, "Wrong number of mid-term windows"
    assert F.shape[0] == len(f_names), "Number of features and feature " \
                                       "names are not the same"


def test_feature_extraction_segment():
    print("Short-term feature extraction")

    [fs, x] = audioBasicIO.read_audio_file("test_data/5_sec_wav.wav")