コード例 #1
0
def compute_feature_map(input_file, annotations_file, delimiter,
                        downbeat_label, n_tatums):
    '''Accentuation feature map computation

    :parameters:
      - input_file : str
          path to input audio file (wav, mp3, m4a, flac, etc.)
      - annotations_file : str
          path to the annotations file (txt, csv, etc)
      - delimiter: str
          delimiter string to process the annotations file
      - downbeat_label: str
          string to look for in the label data to select downbeats
      - n_tatums: int
          number of tatums (subdivisions) per tactus beat
      - n_clusters: int
          number of clusters for rhythmic patterns clustering
    '''

    # 1. load the wav file
    print('Loading audio file ...', input_file)
    y, sr = audio.load(input_file, sr=None)

    # 2. load beat and downbeat annotations
    print('Loading beat and downbeat annotations ...', annotations_file)
    beats, _ = annotations.load_beats(annotations_file, delimiter=delimiter)
    downbeats, _ = annotations.load_downbeats(annotations_file,
                                              delimiter=delimiter,
                                              downbeat_label=downbeat_label)
    # number of beats per bar
    n_beats = int(round(beats.size / downbeats.size))

    # 3. compute accentuation feature
    print('Computing accentuation feature ...')
    acce, times, _ = features.accentuation_feature(y,
                                                   sr,
                                                   minfreq=20,
                                                   maxfreq=200)

    # 4. compute feature map
    print('Computing feature map ...')
    map_acce, _, _, _ = features.feature_map(acce,
                                             times,
                                             beats,
                                             downbeats,
                                             n_beats=n_beats,
                                             n_tatums=n_tatums)

    # 5. plot feature map
    plt.figure()
    ax1 = plt.subplot(211)
    display.map_show(map_acce, ax=ax1, n_tatums=n_tatums)

    plt.show()
コード例 #2
0
# We compute the feature map of rhythmic patterns and we
# learn a manifold in a low--dimensional space.
# The patterns are they shown in the low--dimensional space
# before and after being grouped into clusters.
#
# First, we'll load one of the audio files included in `carat`.
audio_path = util.example("ansina_audio")

y, sr = audio.load(audio_path)

##############################################
# Next, we'll load the annotations provided for the example audio file.
annotations_path = util.example("ansina_beats")

beats, beat_labs = annotations.load_beats(annotations_path)
downbeats, downbeat_labs = annotations.load_downbeats(annotations_path)

##############################################
# Then, we'll compute the accentuation feature.
#
# **Note:** This example is tailored towards the rhythmic patterns of the lowest
# sounding of the three drum types taking part in the recording, so the analysis
# focuses on the low frequencies (20 to 200 Hz).
acce, times, _ = features.accentuation_feature(y, sr, minfreq=20, maxfreq=200)

##############################################
# Next, we'll compute the feature map.
n_beats = int(round(beats.size / downbeats.size))
n_tatums = 4

map_acce, _, _, _ = features.feature_map(acce,
コード例 #3
0
def rhythmic_patterns_analysis(input_file, annotations_file, delimiter,
                               downbeat_label, n_tatums, n_clusters):
    '''Rhythmic patterns analysis

    :parameters:
      - input_file : str
          path to input audio file (wav, mp3, m4a, flac, etc.)
      - annotations_file : str
          path to the annotations file (txt, csv, etc)
      - delimiter: str
          delimiter string to process the annotations file
      - downbeat_label: str
          string to look for in the label data to select downbeats
      - n_tatums: int
          number of tatums (subdivisions) per tactus beat
      - n_clusters: int
          number of clusters for rhythmic patterns clustering
    '''

    # 1. load the wav file
    print('Loading audio file ...', input_file)
    y, sr = audio.load(input_file, sr=None)

    # 2. load beat and downbeat annotations
    print('Loading beat and downbeat annotations ...', annotations_file)
    beats, _ = annotations.load_beats(annotations_file, delimiter=delimiter)
    downbeats, _ = annotations.load_downbeats(annotations_file,
                                              delimiter=delimiter,
                                              downbeat_label=downbeat_label)
    # number of beats per bar
    n_beats = int(round(beats.size / downbeats.size))

    # 3. compute accentuation feature
    print('Computing accentuation feature ...')
    acce, times, _ = features.accentuation_feature(y,
                                                   sr,
                                                   minfreq=20,
                                                   maxfreq=200)

    # 4. compute feature map
    print('Computing feature map ...')
    map_acce, _, _, _ = features.feature_map(acce,
                                             times,
                                             beats,
                                             downbeats,
                                             n_beats=n_beats,
                                             n_tatums=n_tatums)

    # 5. cluster rhythmic patterns
    print('Clustering rhythmic patterns ...')
    cluster_labs, centroids, _ = clustering.rhythmic_patterns(
        map_acce, n_clusters=n_clusters)

    # 6. manifold learning
    print('Dimensionality reduction ...')
    map_emb = clustering.manifold_learning(map_acce)

    # 7. plot everything
    plt.figure()

    ax1 = plt.subplot(211)
    # plot feature map
    display.map_show(map_acce, ax=ax1, n_tatums=n_tatums)

    ax2 = plt.subplot(212)
    # plot feature map with clusters in colors
    display.map_show(map_acce,
                     ax=ax2,
                     n_tatums=n_tatums,
                     clusters=cluster_labs)

    fig = plt.figure()
    ax3 = fig.add_subplot(111, projection='3d')
    # plot low-dimensional embedding of feature data
    display.embedding_plot(map_emb, ax=ax3, clusters=cluster_labs)

    fig = plt.figure()
    display.centroids_plot(centroids, n_tatums=n_tatums)

    plt.show()