Skip to content

Instantly share code, notes, and snippets.

View nicolamontecchio's full-sized avatar

Nicola Montecchio nicolamontecchio

View GitHub Profile
@nicolamontecchio
nicolamontecchio / wav2mono.cpp
Created October 12, 2010 14:42
convert a wav file to mono, using libsndfile
#include <iostream>
#include <sndfile.h>
using namespace std;
/**
* Convert an audio file to mono format (input in first arg, output in second)
*/
int main(int argc, char** argv)
{
if (argc != 3)
@nicolamontecchio
nicolamontecchio / mp3towav
Created January 19, 2011 18:28
convert an mp3 to wav using lame -- useful for converting whole directories
#!/usr/bin/env python
import os
import optparse
def processfile(fi, fo) :
print 'lame --decode --quiet %s %s' % (fi,fo)
if __name__ == '__main__':
# parse options
parser = optparse.OptionParser()
@nicolamontecchio
nicolamontecchio / clVectorPrintout.cpp
Created February 11, 2011 16:33
OPENCL - print a cl_mem vector to stdout; vector type is passed as template
// print out a vector of type T on stdout
template <typename T>
void printClVector(cl_mem &clVector, int length, cl_command_queue &commands, int printrowlen = -1)
{
T *tmp = new T[length];
int err = clEnqueueReadBuffer(commands, clVector, CL_TRUE, 0, sizeof(T) * length, tmp, 0, NULL, NULL );
if (err != CL_SUCCESS)
{
printf("Error: Failed to read output array! %d\n", err);
exit(1);
@nicolamontecchio
nicolamontecchio / lastm_tags.py
Created March 25, 2011 18:16
simple method to get tags for a given artist/track
#!/usr/bin/env python
import urllib, urllib2, StringIO
from lxml import etree
apikey = 'YOUR APY KEY'
def getTags(artist,track) :
params = urllib.urlencode([('method','track.gettoptags'), ('artist',artist),('track',track),('api_key',apikey)])
url = 'http://ws.audioscrobbler.com/2.0/?' + params
root = etree.parse(urllib2.urlopen(url))
@nicolamontecchio
nicolamontecchio / rplot.R
Created August 18, 2011 13:23
plot from STDIN with R
#!/usr/bin/Rscript
d <- as.matrix(read.csv2(file("stdin"), header=FALSE, sep=","))
ca <- commandArgs(trailingOnly=TRUE)
pdf(file=ca[1], width=12, height=6)
plot(d[,1:2], type='n')
lines(d)
dev.off()
@nicolamontecchio
nicolamontecchio / linearfilter.py
Created November 7, 2011 15:32
quick (almost-untested) hack - linear filter in python (uses numpy)
class Filter(object):
""" Linear Filter, notation is similar to matlab's filter function """
def __init__(self, b, a, xinit, yinit):
self.b = np.array(b)
self.a = np.array(a)
self.x = np.array(xinit)[::-1]
self.y = np.array(yinit)[::-1]
def tick(self, x) :
@nicolamontecchio
nicolamontecchio / gist:1611295
Created January 14, 2012 12:42
r common plotting stuff
# subplots:
layout(matrix(c(1,2), 2, 1, byrow = TRUE)) # first matrix defines "occupancy"
# then do all the plot() commands, one per figure
dev.new(width,height)
# FONT STUFF
par(family="serif")
plot(x,y, log="x", type='l', xlab='blabla', ylab='blabla', axes=FALSE)
@nicolamontecchio
nicolamontecchio / useful_python_stuff.py
Last active April 22, 2020 00:56
useful stuff in python
# list of lists:
import itertools
list(itertools.chain.from_iterable(a))
# logging stuff
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
@nicolamontecchio
nicolamontecchio / ctypes_stuff.py
Created August 6, 2012 19:34
python ctypes - array conversion
#let's say f_TI is something like
#void blabla(int *data, int data_length);
#then
f_TI.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.c_int]
lll = [4,7,2,8]
lll_c = (ctypes.c_int * len(lll))(*lll)
f_TI(lll_c, len(lll))
@nicolamontecchio
nicolamontecchio / gist:3831176
Created October 4, 2012 02:44
mac universal binary stuff
merge two libs:
lipo -create libfftw3f-i386.a libfftw3f-ppc.a -output libfftw3f.a