@pytest.mark.parametrize('n_fft', [512])
@pytest.mark.parametrize('sr', [22050])
@pytest.mark.parametrize('hop_length', [None, 256])
@pytest.mark.parametrize('n_ch', [2])
@pytest.mark.parametrize('data_format', ['default', 'channels_first', 'channels_last'])
@pytest.mark.parametrize('amin', [1e-05, 0.001])
@pytest.mark.parametrize('dynamic_range', [120.0, 80.0])
@pytest.mark.parametrize('n_mels', [40])
@pytest.mark.parametrize('mel_f_min', [0.0])
@pytest.mark.parametrize('mel_f_max', [8000])
def test_melspectrogram_correctness(n_fft, sr, hop_length, n_ch, data_format, amin, dynamic_range, n_mels, mel_f_min, mel_f_max):
    'Test the correctness of melspectrogram.\n\n    Note that mel filterbank is tested separated\n\n    '

    def _get_melgram_model(return_decibel, amin, dynamic_range, input_shape=None):
        melgram_model = get_melspectrogram_layer(n_fft=n_fft, sample_rate=sr, n_mels=n_mels, mel_f_min=mel_f_min, mel_f_max=mel_f_max, win_length=win_length, hop_length=hop_length, input_data_format=data_format, output_data_format=data_format, return_decibel=return_decibel, input_shape=input_shape, db_amin=amin, db_dynamic_range=dynamic_range)
        return melgram_model
    (src_mono, batch_src, input_shape) = get_audio(data_format=data_format, n_ch=n_ch)
    win_length = n_fft
    S_ref = librosa.feature.melspectrogram(src_mono, sr=sr, n_fft=n_fft, hop_length=hop_length, win_length=win_length, center=False, power=1.0, n_mels=n_mels, fmin=mel_f_min, fmax=mel_f_max).T
    S_ref = np.expand_dims(S_ref, axis=2)
    S_ref = np.tile(S_ref, [1, 1, n_ch])
    if (data_format == 'channels_first'):
        S_ref = np.transpose(S_ref, (2, 0, 1))
    melgram_model = _get_melgram_model(return_decibel=False, input_shape=input_shape, amin=None, dynamic_range=120.0)
    S = melgram_model.predict(batch_src)[0]
    np.testing.assert_allclose(S_ref, S, atol=0.0001)
    melgram_model = _get_melgram_model(return_decibel=True, input_shape=input_shape, amin=amin, dynamic_range=dynamic_range)
    S = melgram_model.predict(batch_src)[0]
    S_ref_db = librosa.power_to_db(S_ref, ref=1.0, amin=amin, top_db=dynamic_range)
    np.testing.assert_allclose(S_ref_db, S, rtol=0.003)
Test the correctness of melspectrogram.

Note that mel filterbank is tested separated
@pytest.mark.parametrize('n_fft', [512])
@pytest.mark.parametrize('sr', [22050])
@pytest.mark.parametrize('hop_length', [None, 256])
@pytest.mark.parametrize('n_ch', [2])
@pytest.mark.parametrize('data_format', ['default', 'channels_first', 'channels_last'])
@pytest.mark.parametrize('amin', [1e-05, 0.001])
@pytest.mark.parametrize('dynamic_range', [120.0, 80.0])
@pytest.mark.parametrize('n_mels', [40])
@pytest.mark.parametrize('mel_f_min', [0.0])
@pytest.mark.parametrize('mel_f_max', [8000])
def test_melspectrogram_correctness(n_fft, sr, hop_length, n_ch, data_format, amin, dynamic_range, n_mels, mel_f_min, mel_f_max):
    'Test the correctness of melspectrogram.\n\n    Note that mel filterbank is tested separated\n\n    '

    def _get_melgram_model(return_decibel, amin, dynamic_range, input_shape=None):
        melgram_model = get_melspectrogram_layer(n_fft=n_fft, sample_rate=sr, n_mels=n_mels, mel_f_min=mel_f_min, mel_f_max=mel_f_max, win_length=win_length, hop_length=hop_length, input_data_format=data_format, output_data_format=data_format, return_decibel=return_decibel, input_shape=input_shape, db_amin=amin, db_dynamic_range=dynamic_range)
        return melgram_model
    (src_mono, batch_src, input_shape) = get_audio(data_format=data_format, n_ch=n_ch)
    win_length = n_fft
    S_ref = librosa.feature.melspectrogram(src_mono, sr=sr, n_fft=n_fft, hop_length=hop_length, win_length=win_length, center=False, power=1.0, n_mels=n_mels, fmin=mel_f_min, fmax=mel_f_max).T
    S_ref = np.expand_dims(S_ref, axis=2)
    S_ref = np.tile(S_ref, [1, 1, n_ch])
    if (data_format == 'channels_first'):
        S_ref = np.transpose(S_ref, (2, 0, 1))
    melgram_model = _get_melgram_model(return_decibel=False, input_shape=input_shape, amin=None, dynamic_range=120.0)
    S = melgram_model.predict(batch_src)[0]
    np.testing.assert_allclose(S_ref, S, atol=0.0001)
    melgram_model = _get_melgram_model(return_decibel=True, input_shape=input_shape, amin=amin, dynamic_range=dynamic_range)
    S = melgram_model.predict(batch_src)[0]
    S_ref_db = librosa.power_to_db(S_ref, ref=1.0, amin=amin, top_db=dynamic_range)
    np.testing.assert_allclose(S_ref_db, S, rtol=0.003)