]> git.parisson.com Git - timeside.git/commitdiff
IRIT music detector and divergence segmentation added
authorMaxime LE COZ <lecoz@irit.fr>
Fri, 20 Dec 2013 09:41:07 +0000 (10:41 +0100)
committerMaxime LE COZ <lecoz@irit.fr>
Fri, 20 Dec 2013 09:41:07 +0000 (10:41 +0100)
timeside/analyzer/__init__.py
timeside/analyzer/irit_diverg.py
timeside/analyzer/irit_music_.py [new file with mode: 0644]
timeside/analyzer/irit_music_SLN.py [new file with mode: 0644]
timeside/analyzer/irit_music_SLN.pyc [new file with mode: 0644]
timeside/analyzer/irit_music_SNB.py [new file with mode: 0644]
timeside/analyzer/irit_music_SNB.pyc [new file with mode: 0644]

index e7a01502e948d2617797fd06f333800427dbef54..6c8a2fc005cc4bab99b2c88cfe58b1c69f038254 100644 (file)
@@ -2,18 +2,19 @@
 
 from level import *
 from dc import *
-from aubio_temporal import *
-from aubio_pitch import *
-from aubio_mfcc import *
-from aubio_melenergy import *
-from aubio_specdesc import *
+#~ from aubio_temporal import *
+#~ from aubio_pitch import *
+#~ from aubio_mfcc import *
+#~ from aubio_melenergy import *
+#~ from aubio_specdesc import *
 from yaafe import * # TF : add Yaafe analyzer
 from spectrogram import Spectrogram
 from waveform import Waveform
 from vamp_plugin import VampSimpleHost
 from irit_speech_entropy import IRITSpeechEntropy
 from irit_speech_4hz import IRITSpeech4Hz
-from irit_monopoly import IRITMonopoly
 from irit_diverg import IRITDiverg
-
+from irit_music_SLN import IRITMusicSLN
+from irit_music_SNB import IRITMusicSNB
+#~ from irit_monopoly import IRITMonopoly
 from odf import OnsetDetectionFunction
index c52ff22e73dba39eaf6ecf4e9b6580c72889446d..e15d2fe42869b67dcc387d6158a95adbe71f7d75 100644 (file)
@@ -237,7 +237,7 @@ def calculDistance(modeleLong,modeleCourt):
     return (2*modeleCourt.erreur_residuelle*modeleLong.erreur_residuelle/modeleLong.variance_erreur_residuelle-(1.0+QV)*modeleLong.erreur_residuelle**2/modeleLong.variance_erreur_residuelle+QV-1.0)/(2.0*QV)
 
 
-def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True,seuil_vois=None,withTrace = False):
+def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True):
     '''
     Fonction principale de segmentation.
     
@@ -249,9 +249,6 @@ def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True,se
         - lamb (float) : valeur de lambda pour la détection de chute de Wn. Par défaut = 40.0
         - biais (float) : valeur du bias à appliquer (en négatif). Par défaut = -0.2
         - with_backward (Bool) : Interrupteur du calcul ou non en backward. Par défaut = True
-        - seuil_vois (float) : Si fixé, défini les valeurs de lambda et du biais en fonction du voisement ou non du buffer initial du model court terme.
-                               (voisement_yin >  seuil_vois ==> Non voisé). Par défaut = None
-        - withTrace (Bool) : Enregistre ou non la trace de tous les calculs pour un affichage à postériori. Par défaut = False 
     
     '''
     # Initialisation
@@ -306,10 +303,6 @@ def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True,se
                 # Recherche de nouveau maximum
                 if Wn > maxi[0] :
                     maxi = (Wn,t)
-                
-                if withTrace :
-                    dynaWn += [Wn]
-                    tWn += [t]
                     
                 # Recherche de rupture par chute superieure à lambda
                 if (maxi[0] - Wn) > lamb :
@@ -325,30 +318,25 @@ def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True,se
         # Si une rupture à été detecté avec un modèle stable (Wn à croit)   
         if t_rupt > -1 :
             
-            m = 'forward'                
+            m = 1                
             if with_backward :
                 
                 bdata = data[t_rupt:rupt_last:-1]
                 
                 if len(bdata) > 0 :
                 
-                    front = segment(bdata,fe,ordre,float(Lmin)/fe,lamb,biais,with_backward=False,seuil_vois=seuil_vois,withTrace=withTrace)
+                    front = segment(bdata,fe,ordre,float(Lmin)/fe,lamb,biais,with_backward=False)
                     t_bs = [ t_rupt-tr for tr,_ in front]
                     
                     if len(t_bs) > 0 :
                         t_rupt = t_bs[-1]
-                        m ='backward'
+                        m =-1
                     
         # Sinon on crée un segment de longueur minimale
         else :
             t_rupt = rupt_last+Lmin
-            m = 'instable'
+            m = 0
             
-        if withTrace :
-            evnt['selected'] = t_rupt
-            evnt['comment'] = m
-            trace+=[evnt]
-
         # Mise à jour des frontières
         t = t_rupt 
         rupt_last = t_rupt
@@ -363,7 +351,10 @@ def segment(data,fe,ordre=2,Lmin=0.02,lamb=40.0,biais=-0.2,with_backward=True,se
 class IRITDiverg(Analyzer):
     implements(IAnalyzer)
     '''
+    
+    
     '''
+    
     def __init__(self, blocksize=1024, stepsize=None) :
         super(IRITDiverg, self).__init__();
         self.parents.append(Waveform())
@@ -372,11 +363,8 @@ class IRITDiverg(Analyzer):
 
     @interfacedoc
     def setup(self, channels=None, samplerate=None,blocksize=None, totalframes=None):
-        super(IRITDiverg, self).setup(channels,
-                                      samplerate,
-                                      blocksize,
-                                      totalframes)
-        self.parents.append(Waveform())
+        super(IRITDiverg, self).setup(channels,samplerate,blocksize,totalframes)
+    
     @staticmethod
     @interfacedoc
     def id():
@@ -402,10 +390,18 @@ class IRITDiverg(Analyzer):
         return frames, eod
 
     def post_process(self):
-        data = self.process_pipe.results['waveform_analyzer'].data       
+        data = list(self.process_pipe.results['waveform_analyzer'].data)
         frontieres = segment(data,self.samplerate(),self.ordre)
-        f = open('front.lab','w')
-        for t,m in frontieres :
-            f.write('%f\t%s\n'%(float(t)/self.samplerate(),m));
-        f.close()
-        print frontieres
+        
+
+        segs = self.new_result(data_mode='label', time_mode='event')
+        segs.id_metadata.id += '.' + 'segments'
+        segs.id_metadata.name += ' ' + 'Segments'
+        
+        label = {0: 'Instable', 1: 'Forward', -1: 'Backward'}
+        segs.label_metadata.label = label
+
+        segs.data_object.label    = [s[1] for s in frontieres]
+        segs.data_object.time     = [(float(s[0]) / self.samplerate()) for s in frontieres]
+        self.process_pipe.results.add(segs)
+        return 
diff --git a/timeside/analyzer/irit_music_.py b/timeside/analyzer/irit_music_.py
new file mode 100644 (file)
index 0000000..0c20b16
--- /dev/null
@@ -0,0 +1,116 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013 Maxime Le Coz <lecoz@irit.fr>
+
+# This file is part of TimeSide.
+
+# TimeSide 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.
+
+# TimeSide 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 TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Maxime Le Coz <lecoz@irit.fr>
+
+from timeside.core import implements, interfacedoc
+from timeside.analyzer.core import Analyzer
+from timeside.analyzer.utils import melFilterBank, computeModulation
+from timeside.analyzer.utils import segmentFromValues
+from timeside.analyzer import IRITDiverg
+from timeside.api import IAnalyzer
+from numpy import logical_and,array, hamming, dot, mean, float, arange, nonzero
+from numpy.fft import rfft
+from scipy.signal import firwin, lfilter
+from pylab import plot,show
+class IRITMusicLDN(Analyzer):
+    implements(IAnalyzer)
+
+    def __init__(self, blocksize=1024, stepsize=None) :
+        super(IRITMusicLDN, self).__init__();
+        self.parents.append(IRITDiverg())
+        self.wLen      = 1.0
+        self.wStep     = 0.1
+        self.threshold = 20
+        
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "irit_music_sln"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "IRIT Music Detector - Segment Length"
+
+    @staticmethod
+    @interfacedoc
+    def unit():
+        return ""
+
+    def __str__(self):
+        return "Music confidence indexes"
+
+    def process(self, frames, eod=False):
+               
+               return frames,eod
+               
+               
+    def post_process(self):
+        '''
+
+        '''
+        
+        segList = self.process_pipe.results['irit_diverg.segments'].time  
+        w = self.wLen/ 2;
+        end = segList[-1]
+        tLine =  arange(0,end,self.wStep)
+        
+        segLen = array([0]*len(tLine))
+        
+        for i,t in enumerate(tLine):
+            idx = nonzero(logical_and(segList>(t-w) ,segList<(t+w)))[0]
+            segLen[i]= len(idx)
+        
+        
+        plot(tLine,segLen)
+        show()
+               # Confidence Index
+        conf = array(segLen - self.threshold) / self.threshold
+        conf[conf > 1] = 1
+
+        segLenRes = self.new_result(data_mode='value', time_mode='framewise')
+        segLenRes.id_metadata.id += '.' + 'energy_confidence'
+        segLenRes.id_metadata.name += ' ' + 'Energy Confidence'
+
+        segLenRes.data_object.value = segLen
+
+        self.process_pipe.results.add(segLenRes)
+
+        # Segment
+        convert = {False: 0, True: 1}
+        label = {0: 'nonMusic', 1: 'Music'}
+
+        segList = segmentFromValues(segLen > self.threshold)
+        # Hint : Median filtering could imrove smoothness of the result
+        # from scipy.signal import medfilt
+        # segList = segmentFromValues(medfilt(modEnergyValue > self.threshold, 31))
+
+        segs = self.new_result(data_mode='label', time_mode='segment')
+        segs.id_metadata.id += '.' + 'segments'
+        segs.id_metadata.name += ' ' + 'Segments'
+
+        segs.label_metadata.label = label
+
+        segs.data_object.label = [convert[s[2]] for s in segList]
+        segs.data_object.time = [tLine[s[0]] for s in segList]
+        segs.data_object.duration = [tLine[s[1]]-tLine[s[0]] for s in segList]
+
+        self.process_pipe.results.add(segs)
+        return
diff --git a/timeside/analyzer/irit_music_SLN.py b/timeside/analyzer/irit_music_SLN.py
new file mode 100644 (file)
index 0000000..3a7a638
--- /dev/null
@@ -0,0 +1,117 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013 Maxime Le Coz <lecoz@irit.fr>
+
+# This file is part of TimeSide.
+
+# TimeSide 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.
+
+# TimeSide 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 TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Maxime Le Coz <lecoz@irit.fr>
+
+from timeside.core import implements, interfacedoc
+from timeside.analyzer.core import Analyzer
+from timeside.analyzer.utils import melFilterBank, computeModulation
+from timeside.analyzer.utils import segmentFromValues
+from timeside.analyzer import IRITDiverg
+from timeside.api import IAnalyzer
+from numpy import logical_and,array, hamming, dot, mean, float, arange, nonzero
+from numpy.fft import rfft
+from scipy.signal import firwin, lfilter
+from pylab import plot,show
+
+class IRITMusicSLN(Analyzer):
+    implements(IAnalyzer)
+
+    def __init__(self, blocksize=1024, stepsize=None) :
+        super(IRITMusicSLN, self).__init__();
+        self.parents.append(IRITDiverg())
+        self.wLen      = 1.0
+        self.wStep     = 0.1
+        self.threshold = 20
+        
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "irit_music_sln"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "IRIT Music Detector - Segment Length"
+
+    @staticmethod
+    @interfacedoc
+    def unit():
+        return ""
+
+    def __str__(self):
+        return "Music confidence indexes"
+
+    def process(self, frames, eod=False):
+               
+               return frames,eod
+               
+               
+    def post_process(self):
+        '''
+
+        '''
+        
+        segList = self.process_pipe.results['irit_diverg.segments'].time  
+        w = self.wLen/ 2;
+        end = segList[-1]
+        tLine =  arange(0,end,self.wStep)
+        
+        segLen = array([0]*len(tLine))
+        
+        for i,t in enumerate(tLine):
+            idx = nonzero(logical_and(segList>(t-w) ,segList<(t+w)))[0]
+            segLen[i]= len(idx)
+        
+        
+        plot(tLine,segLen)
+        show()
+               # Confidence Index
+        conf = array(segLen - self.threshold) / self.threshold
+        conf[conf > 1] = 1
+
+        segLenRes = self.new_result(data_mode='value', time_mode='framewise')
+        segLenRes.id_metadata.id += '.' + 'energy_confidence'
+        segLenRes.id_metadata.name += ' ' + 'Energy Confidence'
+
+        segLenRes.data_object.value = segLen
+
+        self.process_pipe.results.add(segLenRes)
+
+        # Segment
+        convert = {False: 0, True: 1}
+        label = {0: 'nonMusic', 1: 'Music'}
+
+        segList = segmentFromValues(segLen > self.threshold)
+        # Hint : Median filtering could imrove smoothness of the result
+        # from scipy.signal import medfilt
+        # segList = segmentFromValues(medfilt(modEnergyValue > self.threshold, 31))
+
+        segs = self.new_result(data_mode='label', time_mode='segment')
+        segs.id_metadata.id += '.' + 'segments'
+        segs.id_metadata.name += ' ' + 'Segments'
+
+        segs.label_metadata.label = label
+
+        segs.data_object.label = [convert[s[2]] for s in segList]
+        segs.data_object.time = [tLine[s[0]] for s in segList]
+        segs.data_object.duration = [tLine[s[1]]-tLine[s[0]] for s in segList]
+
+        self.process_pipe.results.add(segs)
+        return
diff --git a/timeside/analyzer/irit_music_SLN.pyc b/timeside/analyzer/irit_music_SLN.pyc
new file mode 100644 (file)
index 0000000..e54b8d0
Binary files /dev/null and b/timeside/analyzer/irit_music_SLN.pyc differ
diff --git a/timeside/analyzer/irit_music_SNB.py b/timeside/analyzer/irit_music_SNB.py
new file mode 100644 (file)
index 0000000..15dce01
--- /dev/null
@@ -0,0 +1,118 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2013 Maxime Le Coz <lecoz@irit.fr>
+
+# This file is part of TimeSide.
+
+# TimeSide 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.
+
+# TimeSide 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 TimeSide.  If not, see <http://www.gnu.org/licenses/>.
+
+# Author: Maxime Le Coz <lecoz@irit.fr>
+
+from timeside.core import implements, interfacedoc
+from timeside.analyzer.core import Analyzer
+from timeside.analyzer.utils import melFilterBank, computeModulation
+from timeside.analyzer.utils import segmentFromValues
+from timeside.analyzer import IRITDiverg
+from timeside.api import IAnalyzer
+from numpy import logical_and,array, hamming, dot, mean, float, arange, nonzero
+from numpy.fft import rfft
+from scipy.signal import firwin, lfilter
+from pylab import plot,show
+
+class IRITMusicSNB(Analyzer):
+    implements(IAnalyzer)
+
+    def __init__(self, blocksize=1024, stepsize=None) :
+        super(IRITMusicSNB, self).__init__();
+        self.parents.append(IRITDiverg())
+        self.wLen      = 1.0
+        self.wStep     = 0.1
+        self.threshold = 20
+        
+    @staticmethod
+    @interfacedoc
+    def id():
+        return "irit_music_snb"
+
+    @staticmethod
+    @interfacedoc
+    def name():
+        return "IRIT Music Detector - Segment Number"
+
+    @staticmethod
+    @interfacedoc
+    def unit():
+        return ""
+
+    def __str__(self):
+        return "Music confidence indexes"
+
+    def process(self, frames, eod=False):
+               
+               return frames,eod
+               
+               
+    def post_process(self):
+        '''
+
+        '''
+        
+        segList = self.process_pipe.results['irit_diverg.segments'].time  
+        w = self.wLen/ 2;
+        end = segList[-1]
+        tLine =  arange(0,end,self.wStep)
+        
+        segLen = array([0]*len(tLine))
+        
+        for i,t in enumerate(tLine):
+            idx = nonzero(logical_and(segList>(t-w) ,segList<(t+w)))[0]
+            l = [tLine[t1]-tLine[t2] for t1,t2 in zip()]
+            segLen[i]= len(idx)
+        
+        
+        plot(tLine,segLen)
+        show()
+               # Confidence Index
+        conf = array(segLen - self.threshold) / self.threshold
+        conf[conf > 1] = 1
+
+        segLenRes = self.new_result(data_mode='value', time_mode='framewise')
+        segLenRes.id_metadata.id += '.' + 'energy_confidence'
+        segLenRes.id_metadata.name += ' ' + 'Energy Confidence'
+
+        segLenRes.data_object.value = segLen
+
+        self.process_pipe.results.add(segLenRes)
+
+        # Segment
+        convert = {False: 0, True: 1}
+        label = {0: 'nonMusic', 1: 'Music'}
+
+        segList = segmentFromValues(segLen > self.threshold)
+        # Hint : Median filtering could imrove smoothness of the result
+        # from scipy.signal import medfilt
+        # segList = segmentFromValues(medfilt(modEnergyValue > self.threshold, 31))
+
+        segs = self.new_result(data_mode='label', time_mode='segment')
+        segs.id_metadata.id += '.' + 'segments'
+        segs.id_metadata.name += ' ' + 'Segments'
+
+        segs.label_metadata.label = label
+
+        segs.data_object.label = [convert[s[2]] for s in segList]
+        segs.data_object.time = [tLine[s[0]] for s in segList]
+        segs.data_object.duration = [tLine[s[1]]-tLine[s[0]] for s in segList]
+
+        self.process_pipe.results.add(segs)
+        return
diff --git a/timeside/analyzer/irit_music_SNB.pyc b/timeside/analyzer/irit_music_SNB.pyc
new file mode 100644 (file)
index 0000000..49f4935
Binary files /dev/null and b/timeside/analyzer/irit_music_SNB.pyc differ