diff --git a/.gitignore b/.gitignore index 4d1f49f..02a9887 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ *~ *.c *so -pyalsaaudio* \ No newline at end of file +pyalsaaudio* +venv/ \ No newline at end of file diff --git a/build.sh b/build.sh index e371694..282b6ff 100755 --- a/build.sh +++ b/build.sh @@ -6,33 +6,23 @@ log () { echo -e "${ORANGE}${*}${NC}" } +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd $DIR -if [ ! -d pyalsaaudio-0.8.4/ ]; then - log "\n→ Downloading pyalsaaudio..." - wget https://pypi.python.org/packages/52/b6/44871791929d9d7e11325af0b7be711388dfeeab17147988f044a41a6d83/pyalsaaudio-0.8.4.tar.gz#md5=b46f69561bc85fc52e698b2440ca251e - tar xzf pyalsaaudio-0.8.4.tar.gz -fi - -log "\n→ Building pyalsaaudio..." -pushd pyalsaaudio-0.8.4/ -python2 setup.py build -cp build/lib.*/*.so ../gum/alsaaudio.so -rm -rf pyalsaaudio* -popd - -log "\n→ Building scikits.samplerate..." -pushd gum/scikits/samplerate -make -popd +log "\n→ Creating virtualenv..." +rm -rf venv +virtualenv -p python2 --system-site-packages venv +source venv/bin/activate +pip install -r requirements.txt log "\n→ Building fast waveform display..." pushd gum/fast -make +make clean && make popd log "\n→ Building fast waveform display..." pushd gum/fx -make +make clean && make popd log "\n✓ Build completed with success" diff --git a/gum/lib/edit.py b/gum/lib/edit.py index 533568f..1ada02d 100644 --- a/gum/lib/edit.py +++ b/gum/lib/edit.py @@ -1,5 +1,5 @@ import numpy -from scikits import samplerate +import samplerate def resample(frames, ratio): diff --git a/gum/scikits/__init__.py b/gum/scikits/__init__.py deleted file mode 100644 index 69ce16f..0000000 --- a/gum/scikits/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -__import__('pkg_resources').declare_namespace(__name__) - -"""Patched version of https://pypi.python.org/pypi/scikits.samplerate - -""" diff --git a/gum/scikits/samplerate/Makefile b/gum/scikits/samplerate/Makefile deleted file mode 100644 index 0693fce..0000000 --- a/gum/scikits/samplerate/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -all: _samplerate.so - -_samplerate.so: _samplerate.c - gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing \ - -I/usr/include/python2.5 -I/usr/include/python2.6 \ - -I/usr/include/python2.7 \ - -lsamplerate -o _samplerate.so _samplerate.c - -_samplerate.c: _samplerate.pyx - cython2 _samplerate.pyx - -clean: - rm -f _samplerate.so _samplerate.c diff --git a/gum/scikits/samplerate/__init__.py b/gum/scikits/samplerate/__init__.py deleted file mode 100644 index 4ed2adb..0000000 --- a/gum/scikits/samplerate/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -#! /usr/bin/env python -# Last Change: Thu Mar 26 01:00 AM 2009 J - -from info import __doc__ - -from _samplerate import resample, available_convertors, src_version_str, \ - convertor_description -from version import version as _version -__version__ = _version - -__all__ = filter(lambda s:not s.startswith('_'),dir()) - -from numpy.testing import Tester - -test = Tester().test -bench = Tester().bench - diff --git a/gum/scikits/samplerate/_samplerate.pyx b/gum/scikits/samplerate/_samplerate.pyx deleted file mode 100644 index 6ad03ea..0000000 --- a/gum/scikits/samplerate/_samplerate.pyx +++ /dev/null @@ -1,174 +0,0 @@ -# cython: embedsignature=True -import numpy as np -import warnings -import copy - -cimport numpy as cnp -cimport libc.stdlib -cimport libc.string -from samplerate cimport * - -cdef extern from *: - ctypedef char* const_char_ptr "const char*" - -cdef extern from "samplerate.h": - cdef struct SRC_DATA: - float * data_in - float * data_out - long int input_frames - long int output_frames - long int input_frames_used - long int output_frames_gen - int end_of_input - double src_ratio - ctypedef SRC_DATA SRC_DATA - -cdef extern from "Python.h": - object PyString_FromStringAndSize(char *v, int len) - -_CONVERTOR_TYPE = { - 'sinc_best' : SRC_SINC_BEST_QUALITY, - 'sinc_medium' : SRC_SINC_MEDIUM_QUALITY, - 'sinc_fastest' : SRC_SINC_FASTEST, - 'zero_order_hold' : SRC_ZERO_ORDER_HOLD, - 'linear' : SRC_LINEAR -} - -def src_version_str(): - """ - Return version string of SRC. - """ - cdef int st - cdef const_char_ptr b - - b = src_get_version() - return PyString_FromStringAndSize(b, libc.string.strlen(b)) - -def available_convertors(): - """ - Return the list of available convertor. - """ - return _CONVERTOR_TYPE.keys() - -def convertor_description(type): - """ - Return a detailed description of the given convertor type. - - Parameters - ---------- - type : str - resample type (see Notes). - - Returns - ------- - descr : str - String describing the given convertor. - """ - cdef const_char_ptr b - - if not type in _CONVERTOR_TYPE.keys(): - raise ValueError("convert type %s unrecognized" % type) - - b = src_get_description(_CONVERTOR_TYPE[type]) - return PyString_FromStringAndSize(b, libc.string.strlen(b)) - -def resample(cnp.ndarray input, r, type, verbose=False): - """ - Resample the input array using the given converter type, with a ratio r - (ie the resulting array will have a length ~ r * input's length). - - Parameters - ---------- - input: array - input data - r: float - ratio - type: str - resample type (see Note) - - Returns - ------- - output: array - output data, whose size is approximately r * input.size - - Notes - ----- - If input has rank 1, than all data are used, and are assumed to be from a - mono signal. If rank is 2, the number columns will be assumed to be the - number of channels. - - The list of convertor types is available from the function - available_convertors. - - Only sinc_*-based interpolation provide good quality; linear and - zero_order_hold should be avoided as much as possible, and be used only - when speed is critical. - """ - cdef long osz, nframes, input_frames_used, output_frames_gen - cdef int nc, st - - if input.ndim == 2: - nframes = input.shape[0] - nc = input.shape[1] - elif input.ndim == 1: - nc = 1 - nframes = input.size - else: - raise ValueError("rank > 2 not supported yet") - - if not type in _CONVERTOR_TYPE.keys(): - raise ValueError("convert type %s unrecognized" % type) - - osz = (r * nframes - 1) - input = np.require(input, requirements='C', dtype=np.float32) - - if nc == 1: - st, ty, input_frames_used, output_frames_gen \ - = _resample_mono(input, nframes, osz, r, _CONVERTOR_TYPE[type]) - else: - st, ty, input_frames_used, output_frames_gen \ - = _resample_multi_channels(input, nframes, osz, r, _CONVERTOR_TYPE[type], nc) - if not st == 0: - raise RuntimeError('Error while calling wrapper, return status is %d (should be 0)' % st) - - if verbose: - info = "samplerate info: " - info += "\n\t%d frames used from input" % input_frames_used - info += "\n\t%d frames written in output" % output_frames_gen - - if not output_frames_gen == osz: - info += "\n\toutput has been resized from %ld to %ld" % \ - (osz, output_frames_gen) - print info - - return ty - -cdef _resample_mono(cnp.ndarray input, long niframes, long noframes, - double r, int type): - cdef cnp.ndarray[cnp.float32_t, ndim=1] ty - cdef SRC_DATA sr - - ty = np.empty(noframes, dtype=np.float32, order='C') - - sr.data_in = input.data - sr.data_out = ty.data - sr.input_frames = niframes - sr.output_frames = noframes - sr.src_ratio = r - - return src_simple(&sr, type, 1), ty, sr.input_frames_used, sr.output_frames_gen - -cdef _resample_multi_channels(cnp.ndarray input, long niframes, long noframes, - double r, int type, int nc): - cdef cnp.ndarray[cnp.float32_t, ndim=2] ty - cdef SRC_DATA sr - - ty = np.empty((noframes, nc), dtype=np.float32, order='C') - - sr.data_in = input.data - sr.data_out = ty.data - sr.input_frames = niframes - sr.output_frames = noframes - sr.src_ratio = r - - return src_simple(&sr, type, nc), ty, sr.input_frames_used, sr.output_frames_gen diff --git a/gum/scikits/samplerate/info.py b/gum/scikits/samplerate/info.py deleted file mode 100644 index c80511b..0000000 --- a/gum/scikits/samplerate/info.py +++ /dev/null @@ -1,13 +0,0 @@ -# THIS FILE IS GENERATED FROM THE SETUP.PY. DO NOT EDIT. -"""Samplerate is a small python package to do high quality audio resampling for -data in numpy arrays; IOW, it is a matlab resample replacement. - -Samplerate is a wrapper around the Secret Rabbit Code from Erik de Castro Lopo -(http://www.mega-nerd.com/SRC/), which has high quality converters based on the -work of J.O Smith from CCRMA (see -http://ccrma.stanford.edu/~jos/resample/optfir.pdf) -""" -# version of the python module (compatibility -> use -# scikits.samplerate.version.version instead, to be consistent with numpy) -from version import short_version as version -ignore = False \ No newline at end of file diff --git a/gum/scikits/samplerate/samplerate.pxd b/gum/scikits/samplerate/samplerate.pxd deleted file mode 100644 index c9c2cd8..0000000 --- a/gum/scikits/samplerate/samplerate.pxd +++ /dev/null @@ -1,41 +0,0 @@ -# This file was generated by cycodegenlib, DO NOT EDIT -# Generated by command /Users/david/local/bin/xml2cython.py -l samplerate -o samplerate.pxd /Users/david/local/include/samplerate.h samplerate.xml -# Codegenlib version 0.3dev -cdef extern from 'samplerate.h': - cdef enum: - SRC_LINEAR = 4 - SRC_SINC_BEST_QUALITY = 0 - SRC_SINC_FASTEST = 2 - SRC_SINC_MEDIUM_QUALITY = 1 - SRC_ZERO_ORDER_HOLD = 3 - char * src_strerror(int) - char * src_get_name(int) - int src_is_valid_ratio(double) - cdef struct SRC_STATE_tag: - pass - ctypedef SRC_STATE_tag SRC_STATE - int src_set_ratio(SRC_STATE *, double) - void src_float_to_short_array(float *, short int *, int) - cdef struct SRC_DATA: - float * data_in - float * data_out - long int input_frames - long int output_frames - long int input_frames_used - long int output_frames_gen - int end_of_input - double src_ratio - int src_simple(SRC_DATA *, int, int) - int src_process(SRC_STATE *, SRC_DATA *) - void src_int_to_float_array(int *, float *, int) - SRC_STATE * src_new(int, int, int *) - ctypedef long int(*src_callback_t)(void *, float * *) - SRC_STATE * src_callback_new(src_callback_t, int, int, int *, void *) - SRC_STATE * src_delete(SRC_STATE *) - char * src_get_description(int) - void src_short_to_float_array(short int *, float *, int) - int src_reset(SRC_STATE *) - int src_error(SRC_STATE *) - char * src_get_version() - long int src_callback_read(SRC_STATE *, double, long int, float *) - void src_float_to_int_array(float *, int *, int) diff --git a/gum/scikits/samplerate/setup.py b/gum/scikits/samplerate/setup.py deleted file mode 100644 index a86f8ba..0000000 --- a/gum/scikits/samplerate/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -import os -import sys - -from numpy.distutils.core import setup, Extension -from setuphelp import info_factory, NotFoundError - -def configuration(parent_package='',top_path=None): - from numpy.distutils.misc_util import Configuration - confgr = Configuration('samplerate', parent_package, top_path) - - # Check that sndfile can be found and get necessary informations - sf_info = info_factory('samplerate', ['samplerate'], ['samplerate.h'], - classname='SamplerateInfo')() - try: - sf_config = sf_info.get_info(2) - except NotFoundError: - raise NotFoundError("""\ -SRC (http://www.mega-nerd.com/SRC/) library not found. Directories to search -for the libraries can be specified in the site.cfg file, in section -[samplerate].""") - - confgr.add_extension('_samplerate', ['_samplerate.c'], extra_info=sf_config) - confgr.add_data_dir('tests') - - return confgr - -if __name__ == "__main__": - from numpy.distutils.core import setup - setup(configuration=configuration) diff --git a/gum/scikits/samplerate/setuphelp.py b/gum/scikits/samplerate/setuphelp.py deleted file mode 100644 index 068c392..0000000 --- a/gum/scikits/samplerate/setuphelp.py +++ /dev/null @@ -1,89 +0,0 @@ -import os -from distutils import log - -from numpy.distutils.system_info import system_info, NotFoundError, dict_append, so_ext - -def info_factory(name, libnames, headers, frameworks=None, - section=None, classname=None): - """Create a system_info class. - - Parameters - ---------- - name : str - name of the library - libnames: seq - list of libraries to look for - headers : seq - list of headers to look for - classname : str - name of the returned class - section : str - section name in the site.cfg - - Returns - ------- - a system_info-derived class with the given meta-parameters - """ - if not classname: - classname = '%s_info' % name - if not section: - section = name - if not frameworks: - framesworks = [] - - class _ret(system_info): - def __init__(self): - system_info.__init__(self) - - def library_extensions(self): - return system_info.library_extensions(self) - - def calc_info(self): - """ Compute the informations of the library """ - if libnames: - libs = self.get_libs('libraries', '') - if not libs: - libs = libnames - # Look for the shared library - lib_dirs = self.get_lib_dirs() - tmp = None - for d in lib_dirs: - tmp = self.check_libs(d, libs) - if tmp is not None: - info = tmp - break - if tmp is None: - return - - # Look for the header file - include_dirs = self.get_include_dirs() - inc_dir = None - for d in include_dirs: - p = self.combine_paths(d, headers) - if p: - inc_dir = os.path.dirname(p[0]) - dict_append(info, include_dirs=[d]) - break - - if inc_dir is None: - log.info(' %s not found' % name) - return - - self.set_info(**info) - else: - # Look for frameworks - if frameworks: - fargs = [] - for f in frameworks: - p = "/System/Library/Frameworks/%s.framework" % f - if os.path.exists(p): - fargs.append("-framework") - fargs.append(f) - if fargs: - self.set_info(extra_link_args=fargs) - return - - _ret.__name__ = classname - _ret.section = section - return _ret - diff --git a/gum/scikits/samplerate/tests/test_regression.py b/gum/scikits/samplerate/tests/test_regression.py deleted file mode 100644 index 78a09cb..0000000 --- a/gum/scikits/samplerate/tests/test_regression.py +++ /dev/null @@ -1,41 +0,0 @@ -import numpy as np -from numpy.testing import * -from scikits.samplerate import resample - -def test_mono(): - fs = 16000. - fr = 8000. - - f0 = 440. - - # Create a small stereo audio array with dephased channel - x = np.sin(2 * np.pi * f0/fs * np.arange(0, 2 * fs)) - - # Upsampled reference - z_r = np.sin(2 * np.pi * f0/fr * np.arange(0, 2 * fr)) - - z = resample(x, fr /fs, 'sinc_best') - - assert np.max(np.abs(z_r[10:-1] - z[10:])) < 1e-2 - -def test_multi_channel(): - fs = 16000. - fr = 8000. - - f0 = 440. - - # Create a small stereo audio array with dephased channel - xleft = np.sin(2 * np.pi * f0/fs * np.arange(0, 2 * fs)) - xright = np.cos(2 * np.pi * f0/fs * np.arange(0, 2 * fs)) - y = np.empty((xleft.size, 2), np.float) - y[:,0] = xleft - y[:,1] = xright - - # Upsampled reference - z_rleft = np.sin(2 * np.pi * f0/fr * np.arange(0, 2 * fr)) - z_rright = np.cos(2 * np.pi * f0/fr * np.arange(0, 2 * fr)) - z_r = np.vstack((z_rleft, z_rright)).T - - z = resample(y, fr /fs, 'sinc_best') - - assert np.max(np.abs(z_r[100:-100] - z[100:-99])) < 1e-2 diff --git a/gum/scikits/samplerate/version.py b/gum/scikits/samplerate/version.py deleted file mode 100644 index 1b564fc..0000000 --- a/gum/scikits/samplerate/version.py +++ /dev/null @@ -1,3 +0,0 @@ -short_version = '0.3.3' -dev =False -version = '0.3.3' diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2f5cd4f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +samplerate +pyalsaaudio +flufl.enum # enum is not included in python2 diff --git a/run b/run index e8d5f77..e108841 100755 --- a/run +++ b/run @@ -1,4 +1,9 @@ #!/bin/sh DIRECTORY=`dirname $0` + +if [ -d "$DIRECTORY/venv" ]; then + source venv/bin/activate +fi; + PYTHONPATH=$DIRECTORY python2 $DIRECTORY/gum/run.py "$@" diff --git a/setup.py b/setup.py index 0d08cd4..4e2bc85 100644 --- a/setup.py +++ b/setup.py @@ -41,6 +41,6 @@ Extension('gum.fx._svf', ['gum/fx/_svf.c'])], scripts = ['gum/scripts/gum'], requires = ['PyGTK', 'numpy', 'pyalsaaudio (>=0.6)', - 'scikits.samplerate'], - install_requires = ['pyalsaaudio>=0.6', 'scikits.samplerate', 'numpy'] + 'samplerate'], + install_requires = ['pyalsaaudio>=0.6', 'samplerate', 'numpy'] ) diff --git a/test b/test index 2305fbf..e68842b 100755 --- a/test +++ b/test @@ -3,6 +3,10 @@ DIRECTORY=`dirname $0` export PYTHONPATH=$DIRECTORY:$DIRECTORY/gum:$PYTHONPATH +if [ -d "$DIRECTORY/venv" ]; then + source venv/bin/activate +fi; + if test -z $@; then files=`find gum -name '*.py'`; else