コード例 #1
0
	def dimensional_scale_data(self):
		self.ops.parseDescriptors()
		dimscaling.buildarray_all_timevarying_descriptors(self.tgt.segs + self.cps.postLimitSegmentNormList, self.ops._normalizeDescriptors, self.AnalInterface)
		from userclasses import SearchPassOptionsEntry as spass
		from userclasses import SingleDescriptor as d
		self.ops.SEARCH = [
spass('closest_percent', d('effDur-seg', norm=1), d('power-seg', norm=1), percent=25),
spass('closest', d('X', norm=1), d('Y', norm=1))
]
コード例 #2
0
def descriptListPackageExpansion(initialListOfDescriptorObjs, numbMfccs):
	from userclasses import SingleDescriptor as d
	newListOfDescriptorObjs = []
	
	for dobj in initialListOfDescriptorObjs:
		metricsToWrite = []
		if dobj.name.find('mfccs') != -1:
			mfccWeightMask = np.power(np.linspace(1., 0.05, num=numbMfccs-1), 0.5)
			for i in range(numbMfccs-1): metricsToWrite.append(('mfcc'+str(i+1)+dobj.name[5:], dobj.weight*(mfccWeightMask[i]/sum(mfccWeightMask)) ))
		elif dobj.name.find('chromas') != -1:
			for i in range(12): metricsToWrite.append( ( 'chroma'+str(i)+dobj.name[9:], dobj.weight/12. ) )
		elif dobj.name.find('autocorrs') != -1:
			for i in range(12): metricsToWrite.append( ( 'autocorr'+str(i)+dobj.name[9:], dobj.weight/12. ) )
		elif dobj.name.find('crests') != -1:
			for i in range(4):
				metricsToWrite.append( [ 'crest'+str(i)+dobj.name[6:], dobj.weight/4. ] )
		elif dobj.name.find('flatnesses') != -1:
			for i in range(4):
				metricsToWrite.append( [ 'flatness'+str(i)+dobj.name[10:], dobj.weight/4. ] )
		elif dobj.name.find('harmonictristimuluses') != -1:
			for i in range(3):
				metricsToWrite.append( [ 'harmonictristimulus'+str(i)+dobj.name[21:], dobj.weight/3. ] )
		elif dobj.name.find('perceptualtristimuluses') != -1:
			for i in range(3):
				metricsToWrite.append( [ 'perceptualtristimulus'+str(i)+dobj.name[23:], dobj.weight/3. ] )
		
		# add original if not a package, add package elements otherwise
		if len(metricsToWrite) == 0:
			newListOfDescriptorObjs.append(dobj)
		else:
			for name, weight in metricsToWrite:
				newdobj = d(name, weight=weight, norm=dobj.norm, normmethod=dobj.normmethod, distance=dobj.distance, limit=dobj.limit, energyWeight=dobj.energyWeight, origin=dobj.origin, neededBy=dobj.neededBy, packagename=dobj.name)
				#print "ADDING", newdobj, newdobj.weight
				newListOfDescriptorObjs.append(newdobj)
	return newListOfDescriptorObjs
コード例 #3
0
	def addDescriptorIfNeeded(self, dobjToCheck, ops, addParents=False):
		from userclasses import SingleDescriptor as d
		if dobjToCheck.name not in [dn.name for dn in self.requiredDescriptors]:
			self.requiredDescriptors.append(dobjToCheck)
		if addParents:
			for pname in dobjToCheck.parents:
				self.addDescriptorIfNeeded(d(pname, origin=dobjToCheck.origin+'_PARENT'), ops)
コード例 #4
0
 def setupConcate(self, AnalInterface):
     from userclasses import SingleDescriptor as d
     self.powerStats = getDescriptorStatistics(self.segs, d('power'))
     # initalise mixture and add norm coeffs to mixables...
     for seg in self.segs:
         seg.seek = 0
         seg.selectiondone = False
         seg.initMixture(AnalInterface)
         for dobj in AnalInterface.mixtureDescriptors:
             # copy the normalization paramaters from the target segments onto the mix descriptors
             seg.mixdesc[dobj.name].setNorm(seg.desc[dobj.name].normdict)
コード例 #5
0
ファイル: sfsegment.py プロジェクト: arnaubrichs/audioguide
 def setupConcate(self, mixturelist):
     from userclasses import SingleDescriptor as d
     self.powerStats = getDescriptorStatistics(self.segs, d('power'))
     # initalise mixture and add norm coeffs to mixables...
     for seg in self.segs:
         seg.seek = 0
         seg.selectiondone = False
         seg.classification = 0
         seg.numberSelectedUnits = 0
         seg.desc.rewind()
         seg.desc.init_mixture(mixturelist)
         seg.has_been_mixed = False
         seg.originalPeak = seg.desc.get(
             'peakTime-seg')  # keep original, unsubtacted peak
コード例 #6
0
	def __init__(self, pm2_bin=None, supervp_bin=None, userWinLengthSec=0.12, userHopLengthSec=0.02, userEnergyHopLengthSec=0.005, resampleRate=12500, windowType='blackman', F0MaxAnalysisFreq=3000, F0MinFrequency=200, F0MaxFrequency=1000, F0AmpThreshold=30, numbMfccs=13, forceAnal=False, p=None, searchPaths=[], dataDirectoryLocation=None):
		global descriptToFiles

		# establish data directory
		if dataDirectoryLocation == None:
			self.dataDirectory = os.path.dirname(__file__)
		else:
			self.dataDirectory = os.path.abspath(dataDirectoryLocation)
			if not os.path.exists(self.dataDirectory): os.makedirs(self.dataDirectory)

		self.rawData = {} # file, descriptdict
		self.p = p
		self.ircamdescriptor_bin = os.path.join( os.path.dirname(__file__), 'ircamdescriptor-2.8.6', 'ircamdescriptor-2.8.6' )
		assert os.path.exists(self.ircamdescriptor_bin)
		# check for other bin files #
		self.pm2_bin = findbin(pm2_bin, 'AudioSculpt3.0b7/Kernels/pm2')
		self.supervp_bin = findbin(supervp_bin, 'AudioSculpt3.0b7/Kernels/supervp')
		# anal
		self.resampleRate = resampleRate
		#############################################################################
		## ensure that window and hop sizes are powers of two of the resample rate ##
		#############################################################################
		powersOfTwo = np.array([2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288])
		closestWinSize = powersOfTwo[np.argmin(np.abs(powersOfTwo-(userWinLengthSec*float(self.resampleRate))))]
		closestHopSize = powersOfTwo[np.argmin(np.abs(powersOfTwo-(userHopLengthSec*float(self.resampleRate))))]
		#self.winLengthSec = closestWinSize/float(self.resampleRate) # adjusted value to esure its a power of two in the resample rate!
		#self.hopLengthSec = closestHopSize/float(self.resampleRate) # adjusted value to esure its a power of two in the resample rate!
		self.winLengthSec = userWinLengthSec
		self.hopLengthSec = userHopLengthSec

		self.userEnergyWinLengthSec = userEnergyHopLengthSec*2
		self.userEnergyHopLengthSec = userEnergyHopLengthSec
		self.IOBufferSize = min(4096, closestWinSize*4, self.userEnergyWinLengthSec*float(self.resampleRate)*4)
		self.windowType = windowType
		self.F0MaxAnalysisFreq = F0MaxAnalysisFreq
		self.F0MinFrequency = F0MinFrequency
		self.F0MaxFrequency = F0MaxFrequency
		self.F0AmpThreshold = F0AmpThreshold
		# set up mfccs
		self.numbMfccs = numbMfccs
		for i in range(self.numbMfccs):
			descriptToFiles.append(("mfcc%i"%i,                  'ircamd', False, True,  'MFCC', self.numbMfccs, i))
		# other stuff
		self.forceAnal = forceAnal
		self.searchPaths = searchPaths

		### setup ircam binary config text file	
		self.analdir = os.path.join(self.dataDirectory, 'data')
		self.ircamd_infofile = os.path.join(self.analdir, 'ircamd-info.json')
		self.ircamd_info = {}

		if not os.path.exists(self.analdir): os.makedirs(self.analdir)
		### setup anal registry
		self.dataRegistryPath = os.path.join(self.analdir, 'data_registry.json')
		if os.path.exists(self.dataRegistryPath):
			fh = open(self.dataRegistryPath)
			self.dataRegistry = json.load(fh)
			fh.close()
		else:
			self.dataRegistry = {}

		self.internalDescriptorNames = ['power', 'peakTime-seg', 'power-seg', 'power-mean-seg', 'effDurFrames-seg', 'effDur-seg','f0-seg', 'MIDIPitch-seg']
		self.config_loc = os.path.join(self.analdir, 'ircamdescriptor.config.txt')
		self.config_text = '''; DO NOT EDIT - AUTOMATICALLY GENERATED BY anallinkage.py
[Parameters]
ResampleTo = %i
NormalizeSignal = 0
SubtractMean = 1
IOBufferSize = %i
SaveShortTermTMFeatures = 1
WindowType = %s
OutputFormat = raw

F0MaxAnalysisFreq = %i
F0MinFrequency = %i
F0MaxFrequency = %i
F0AmpThreshold = %i

MFCCs = %i

[StandardDescriptors]
WindowSize = %f
HopSize = %f
TextureWindowsFrames = -1
TextureWindowsHopFrames = -1		
Harmonics = 20
DeviationStopBand = 10
RolloffThreshold = 0.95
DecreaseThreshold = 0.4
NoiseThreshold = 0.15

;~~~~~~~~~~~~~~~~~~~descriptors~~~~~~~~~~~~~~~~~~~~~
SignalZeroCrossingRate  = ShortTime
;AutoCorrelation  = ShortTime
TotalEnergy  = ShortTime
SpectralCentroid  = ShortTime
SpectralSpread  = ShortTime
SpectralSkewness  = ShortTime
SpectralKurtosis  = ShortTime
SpectralSlope  = ShortTime
SpectralDecrease  = ShortTime
SpectralRolloff  = ShortTime
SpectralVariation  = ShortTime
Loudness  = ShortTime
Spread  = ShortTime
Sharpness  = ShortTime
PerceptualSpectralCentroid  = ShortTime
PerceptualSpectralSpread  = ShortTime
PerceptualSpectralSkewness  = ShortTime
PerceptualSpectralKurtosis  = ShortTime
PerceptualSpectralSlope  = ShortTime
PerceptualSpectralDecrease  = ShortTime
PerceptualSpectralRolloff  = ShortTime
PerceptualSpectralVariation  = ShortTime
PerceptualSpectralDeviation  = ShortTime
PerceptualOddToEvenRatio  = ShortTime
PerceptualTristimulus  = ShortTime
MFCC  = ShortTime
SpectralFlatness  = ShortTime
SpectralCrest  = ShortTime
FundamentalFrequency  = ShortTime
NoiseEnergy  = ShortTime
Noisiness  = ShortTime
Inharmonicity  = ShortTime
HarmonicEnergy  = ShortTime
HarmonicSpectralCentroid  = ShortTime
HarmonicSpectralSpread  = ShortTime
HarmonicSpectralSkewness  = ShortTime
HarmonicSpectralKurtosis  = ShortTime
HarmonicSpectralSlope  = ShortTime
HarmonicSpectralDecrease  = ShortTime
HarmonicSpectralRolloff  = ShortTime
HarmonicSpectralVariation  = ShortTime
HarmonicSpectralDeviation  = ShortTime
HarmonicOddToEvenRatio  = ShortTime
HarmonicTristimulus  = ShortTime
Chroma  = ShortTime


[EnergyDescriptors]
WindowSize = %f
HopSize = %f
TextureWindowsFrames = -1
TextureWindowsHopFrames = -1
;~~~~~~~~~~~~~~~~energy descriptors~~~~~~~~~~~~~~~~
EnergyEnvelope  = 1
'''%(self.resampleRate, self.IOBufferSize, self.windowType, self.F0MaxAnalysisFreq, self.F0MinFrequency, self.F0MaxFrequency, self.F0AmpThreshold, self.numbMfccs, self.winLengthSec, self.hopLengthSec, self.userEnergyWinLengthSec, self.userEnergyHopLengthSec)
		# make a list of all possible descriptor objects
		self.allDescriptors = []
		from userclasses import SingleDescriptor as d
		for desc in descriptToFiles:
			dobj = d(desc[0])
			self.allDescriptors.append( dobj )
			if not dobj.seg: self.allDescriptors.append( d(desc[0]+'-seg') )
		
		for desc in self.internalDescriptorNames:
			self.allDescriptors.append( d(desc) )
		# print all descriptors
		#print (', '.join(["d('%s')"%d.name for d in self.allDescriptors if d.seg]))
		# write log
		if self.p != None: 
			self.p.log("ANALYSIS CONFIG: using analysis window of %.3f (%i samples)"%(self.winLengthSec, closestWinSize))
			self.p.log("ANALYSIS CONFIG: using analysis overlap of %.3f (%i samples)"%(self.hopLengthSec, closestHopSize))
コード例 #7
0
	def getDescriptorLists(self, ops):
		self.expandDescriptorPackages(ops)
		from userclasses import SingleDescriptor as d
		from audioguide.userclasses import SearchPassOptionsEntry as spassObj
		self.requiredDescriptors = []
		# add SEARCH descriptors
		for spass in ops.SEARCH:
			for dobj in spass.descriptor_list:
				#dobj.origin = 'SEARCH'
				self.addDescriptorIfNeeded(dobj, ops, addParents=True)
		# add target onset descriptors
		for dname, weight in self.tgtOnsetDescriptors.items():
			self.addDescriptorIfNeeded(d(dname, weight=weight, origin='TARGET_ONSET'), ops)
		# add limiting descriptors
		if 'limit' in ops.CORPUS_GLOBAL_ATTRIBUTES:
			for stringy in ops.CORPUS_GLOBAL_ATTRIBUTES['limit']:
				print(stringy.split()[0], 'GLOBAL_LIMIT')
				self.addDescriptorIfNeeded(d(stringy.split()[0], origin='GLOBAL_LIMIT'), ops, addParents=True)
		if hasattr(ops, 'CORPUS'):
			for csfObj in ops.CORPUS:
				for stringy in csfObj.limit:
					self.addDescriptorIfNeeded(d(stringy.split()[0], origin='LOCAL_LIMIT'), ops, addParents=True)

		# add EXPERIMENTAL spass entries 
		for k, v in ops.EXPERIMENTAL.items():
			if isinstance(v, spassObj):
				for dobj in v.descriptor_list:
					dobj.origin = 'EXPERIMENTAL'
					self.addDescriptorIfNeeded(dobj, ops, addParents=True)

		# add CLUSTER descriptors
		if 'descriptors' in ops.CLUSTER_MAPPING:
			for s in ops.CLUSTER_MAPPING['descriptors']:
				self.addDescriptorIfNeeded(d(s+'-seg', origin='CLUSTER_MAPPING'), ops, addParents=True)
		# add classification descriptors
		if 'descriptors' in ops.OUTPUTEVENT_CLASSIFY:
			for s in ops.OUTPUTEVENT_CLASSIFY['descriptors']:
				self.addDescriptorIfNeeded(d(s, origin='CLASSIFICATION'), ops, addParents=True)
		# add segmentation data descriptor
		if ops.SEGMENTATION_FILE_INFO != 'logic':
			self.addDescriptorIfNeeded(d(ops.SEGMENTATION_FILE_INFO, weight=0, origin='SEGMENTATION_DATA'), ops, addParents=True)
		# add ordering by descriptor
		if None not in [ops.ORDER_CORPUS_BY_DESCRIPTOR]:
			self.addDescriptorIfNeeded(d(ops.ORDER_CORPUS_BY_DESCRIPTOR, weight=0, origin='ORDER_CORPUS_BY_DESCRIPTOR'), ops, addParents=True)
		for dname, weight in self.tgtOnsetDescriptors.items():
			self.addDescriptorIfNeeded(d(dname, weight=weight, origin='TARGET_ONSET'), ops)
		# add internal mectrics if not already used
		for dname in self.internalDescriptorNames:
			self.addDescriptorIfNeeded(d(dname, origin='INTERNAL'), ops, addParents=True)
		#
		#
		# make normalisation list!
		self.normalizeDescriptors = []
		for dobj in self.requiredDescriptors:
			if dobj.origin in ['SEARCH', 'EXPERIMENTAL']: self.normalizeDescriptors.append(dobj)
		# make mixture list!
		self.mixtureDescriptors = []
		tmpmix = ['power']
		for dobj in self.requiredDescriptors:
			if dobj.origin == 'SEARCH' and dobj.is_mixable:
				if dobj.seg: tmpmix.append(dobj.name) # make sure segs are at the end
				else: tmpmix.insert(0, dobj.name)
				for pobjname in dobj.parents: tmpmix.insert(0, pobjname)
		for dname in tmpmix:
			for dobj in self.requiredDescriptors:
				if dobj.name == dname:
					self.mixtureDescriptors.append(dobj)
					break