# 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)


import os
import time
import glob
import numpy as np
import matplotlib.pyplot as plt
import sys
from pyAudioAnalysis import utilities
from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import ShortTermFeatures
                                   np.ones((mid_feature_vector.shape[0], )))

    return mid_features, signal_idx, wav_file_list


"""
The following two feature extraction wrappers extract features for given audio
files, however  NO LONG-TERM AVERAGING is performed. Therefore, the output for
each audio file is NOT A SINGLE FEATURE VECTOR but a whole feature matrix.

Also, another difference between the following two wrappers and the previous
is that they NO LONG-TERM AVERAGING IS PERFORMED. In other words, the WAV
files in these functions are not used as uniform samples that need to be
averaged but as sequences
"""


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):
    """
    This function is used as a wrapper to:
    a) read the content of a WAV file
    b) perform mid-term feature extraction on that signal
    c) write the mid-term feature sequences to a np file
    d) optionally write contents to csv file as well
    e) optionally write short-term features in csv and np file
    """
    sampling_rate, signal = audioBasicIO.read_audio_file(file_path)

# 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
import os
import time
import glob
import numpy as np
import matplotlib.pyplot as plt
import sys
from pyAudioAnalysis import utilities
from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import ShortTermFeatures

                                   np.ones((mid_feature_vector.shape[0], )))

    return mid_features, signal_idx, wav_file_list


"""
The following two feature extraction wrappers extract features for given audio
files, however  NO LONG-TERM AVERAGING is performed. Therefore, the output for
each audio file is NOT A SINGLE FEATURE VECTOR but a whole feature matrix.

Also, another difference between the following two wrappers and the previous
is that they NO LONG-TERM AVERAGING IS PERFORMED. In other words, the WAV
files in these functions are not used as uniform samples that need to be
averaged but as sequences
"""


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):
    """
    This function is used as a wrapper to:
    a) read the content of a WAV file
    b) perform mid-term feature extraction on that signal
    c) write the mid-term feature sequences to a np file
    d) optionally write contents to csv file as well
    e) optionally write short-term features in csv and np file
    """
    sampling_rate, signal = audioBasicIO.read_audio_file(file_path)

    signal = audioBasicIO.stereo_to_mono(signal)