view pyspark/timeside_vamp.py @ 0:e34cf1b6fe09 tip

commit
author Daniel Wolff
date Sat, 20 Feb 2016 18:14:24 +0100
parents
children
line wrap: on
line source
# Part of DML (Digital Music Laboratory)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 11 13:22:37 2013

@author: thomas
"""

from __future__ import division

import matplotlib.pyplot as plt
import numpy as np
import sys
import os

# NOTE: this is only for debugging purposes, we can 
# now use a regular timeside and sonic annotator installation,
#sudo ln -s ../../sonic_annotator/sonic-annotator-0.7-linux-amd64/sonic-annotator /usr/sbin/
#sys.path.append(os.getcwd() + '../../sonic_annotator/sonic-annotator-0.7-linux-amd64/')

import timeside
from timeside.analyzer.core import AnalyzerResult, AnalyzerResultContainer
from timeside import __version__
from vamp_plugin_dml import *

def transform(wav_file = 'sweep.wav'):


    # normal
    d = timeside.decoder.file.FileDecoder(wav_file)
    
    # Get available Vamp plugins list
    from timeside.analyzer.vamp_plugin import VampSimpleHost
    plugins_list = VampSimpleHostDML.get_plugins_list()

    # Display avalaible plugins
    print 'index \t soname \t \t identifier \t output '
    print '------ \t \t ---------- \t ------ '
    for index, line in zip(xrange(len(plugins_list)),plugins_list):
        print '%d : %s \t %s \t %s' % (index,line[0],line[1],line[2])

    # Let's choose #7
    my_plugin = plugins_list[0]#11
    print my_plugin

    #
    # Vamp plugin Analyzer
    #vamp = timeside.analyzer.vamp_plugin.VampSimpleHostDML([my_plugin])
    vamp = VampSimpleHostDML([my_plugin])
    #vamp = timeside.analyzer.VampSimpleHostDML()
    
    myPipe = (d | vamp ).run()

    # Get the vamp plugin result and plot it
    for key in vamp.results.keys():
        print vamp.results[key].data
        res_vamp = vamp.results[key]
        
        
    # test storage as HDF5
    #vamp.results.to_hdf5(wav_file + '.h5')
    #res_hdf5 = vamp.results.from_hdf5(wav_file + '.h5')
    #print '%15s' % 'from hdf5:',
    #print res_hdf5
        
    return res_vamp

    # res_vamp = vamp.results['vamp_simple_host.percussiononsets.detectionfunction']

if __name__ == "__main__":
    if len(sys.argv) >= 2:
        transform(sys.argv[1])
    else:
        transform()