RDF-ize your algorithm

Using VamPy and Sonic Annotator

Requirements

You need to have the following stuff installed

Optional:

Getting Started

Download and install all required software for your platform.

Note: You can use any directory if you export VAMPY_PATH="/your/vampy/diractory"

More info on installation

Test Vamp Plugins

Sonic Annotator should find any Vamp/VamPy plugins correctly installed


	$ sonic-annotator -l
This should return at least:

	vamp:vampy:vampy-unique-ID:vampy-unique-outputID

This is a unique identifier of the only output of the example plugin.
You should replace 'vampy-unique-ID' and 'vampy-unique-outputID' with an ID of your choice in the plugin code.

Writing your first Vamp plugin

Using your favourite text editor, open the file VamPyTemplatePlug.py and replace the string in the following functions with an ID of your choice:


	def getIdentifier(self):
		return 'vampy-unique-ID'

	def getOutputDescriptors(self):
		Generic.identifier = 'vampy-unique-outputID'

If you run Sonic Annotator again, you should be able to see the newly created plugin IDs in the output. You may also want to change your name etc...

Writing your first Vamp plugin

The example plugin returns the energy computed from the normalised magnitude spectrum for each processing block. This computation is performed in the process() function.


	def process(self,inputbuffers,timestamp):
		length = self.m_blockSize * 0.5 + 1
		sampleRate = self.m_inputSampleRate
		complexSpectrum =  inputbuffers[0]
		magnitudeSpectrum = abs(complexSpectrum) / length

		tpower = sum(magnitudeSpectrum)

Modify this function using an algorithm of your choice, or use the example provided next.

Writing a simple onset detector

We will create a very simple onset detector using High Frequency Content.

Create a weighting function in process()


	def process(self,inputbuffers,timestamp):

		length = self.m_blockSize * 0.5 + 1
		sampleRate = self.m_inputSampleRate

		#weighting function
		w = array(xrange(length)) / length

Writing a simple onset detector

Detection function and peak picking:


	def process(self,inputbuffers,timestamp):
		...
		complexSpectrum =  inputbuffers[0]
		weightedSpectrum = w * (abs(complexSpectrum) / length)
		tpower = sum(weightedSpectrum)
		peak = False
		greater = False
		if tpower > self.prev :
			greater = True
		if tpower > self.threshold : 
			if self.wasGreater and not greater :
				peak = True

Writing a simple onset detector

Return the onset times and store previous values


	def process(self,inputbuffers,timestamp):
		...
		output_featureSet = FeatureSet()
		if peak :
			output_featureSet[0] = Feature()
			output_featureSet[0].timestamp = self.prevTime
			output_featureSet[0].hasTimestamp = True
		# store previous values for the next process	
		self.prev = tpower
		self.wasGreater = greater
		self.prevTime = timestamp
		return output_featureSet

Writing a simple onset detector

Do some house-keeping:

in the __init__() function add:


self.prev = 0.0
self.wasGreater = False
self.prevTime = 0

Writing a simple onset detector

Do some house-keeping:

in getOutputDescriptors() modify:


Generic.hasFixedBinCount=True
Generic.binCount=0
Generic.sampleType = VariableSampleRate

Using Sonic Annotator

That's All!



Now Create some RDF!



Could not follow? Cheat!

Using Sonic Annotator

Grab an audio file and type


$ sonic-annotator -d vamp:vampy:yourID:yourOutputID audio_file.wav \

-w rdf --rdf-stdout > onsets.n3

where yourID and yourOutputID are the IDs you used for your plugin.

if you haven't changed the IDs you may try:


./sonic-annotator -d vamp:vampy:vampy-unique-ID:vampy-unique-outputID \
/audio-file.wav -w rdf --rdf-stdout > onsets.n3

Sonic Visualiser

Now load the RDF into Sonic Visualiser:

You should see the onsets! Press Play!

and now publishing Linked Data