Skip to content

Instantly share code, notes, and snippets.

tomas garcia tgarc

Block or report user

Report or block tgarc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tgarc
tgarc / merge_load.py
Last active Apr 28, 2017
Load a yaml stream (src) and merge it with another yaml stream (dst) allowing *dst* to use aliases defined in *src*.
View merge_load.py
import sys
import yaml
def merge_load(src, dst, loadfunc=yaml.load, **kwargs):
'''\
Load a yaml stream (src) and merge it with another yaml stream
(dst) allowing *dst* to use aliases defined in *src*.
Other Parameters
----------------
@tgarc
tgarc / mask2runs.py
Last active Nov 6, 2018
find runs of constant value, returning their indices
View mask2runs.py
import numpy as np
def mask2runs(mask):
'''
mask2runs
Turns a boolean array into an array of indices indicating the start and end indices of each run of 1's.
'''
runflip = np.nonzero(mask[1:] ^ mask[:-1])[0]+1
runflip[1::2] -= 1 # Note that the prior step returns end indices as the end of a run plus 1
@tgarc
tgarc / findfile.py
Created Feb 2, 2017
python file finder
View findfile.py
import os
import glob
import errno
try:
from itertools import ifilter as filter
except ImportError:
pass
def findfile(filepath, find_all, search_path='', recursive=False, allowglob=False, rel_path='.', follow_links=False):
filelist = []
@tgarc
tgarc / .asoundrc
Last active Feb 5, 2017
portaudio/libsndfile for half and full duplex audio streaming
View .asoundrc
# sets up a full duplex alsa loopback device
pcm.loophw00 {
type hw
card Loopback
device 0
subdevice 0
format S32_LE
rate 48000
channels 8
}
@tgarc
tgarc / padaemon.py
Last active Dec 1, 2016
daemon for portaudio
View padaemon.py
#!/usr/bin/env python2
"""
Daemon for full duplex streaming with PyAudio
Note that recordings are always delayed by some amount and are therefore longer than the input file
Builds off of mpex.py: https://gist.github.com/tgarc/7120c00eb3eb5f736be93c70ade1d68a
"""
import multiprocessing, threading, Queue
import time
@tgarc
tgarc / ioproc.py
Last active Nov 28, 2016
Extension of mpex.py: Keep the io process alive so that multiple file may be sent
View ioproc.py
"""
Example of keeping a simulated IO callback thread fed using separate master and daemon (I/O) processes.
Builds off of mpex.py: https://gist.github.com/tgarc/7120c00eb3eb5f736be93c70ade1d68a
"""
import multiprocessing, threading, Queue
import time
import sys
import urllib2
@tgarc
tgarc / mpex.py
Last active Nov 18, 2016
Multiprocessing example: feeding a low rate I/O stream
View mpex.py
"""
Example of keeping a simulated IO callback thread fed using separate master and daemon (I/O) processes.
"""
import multiprocessing, threading, Queue
import time
import sys
import urllib2
IOBLOCKSZ = 4096 # made up IO block size
IPCBLOCKSZ = 8192 # a size that is guaranteed to be larger than BLOCK_SZ
@tgarc
tgarc / win.patch
Last active Sep 16, 2016
updated patch for compiling pyaudio for windows with msvc
View win.patch
diff --git a/setup.py b/setup.py
index cccebeb..1472d06 100755
--- a/setup.py
+++ b/setup.py
@@ -79,7 +79,9 @@ if not STATIC_LINKING:
else:
include_dirs = [os.path.join(portaudio_path, 'include/')]
extra_link_args = [
- os.path.join(portaudio_path, 'lib/.libs/libportaudio.a')
+ os.path.join(portaudio_path, 'portaudio_static_x64.lib')
@tgarc
tgarc / playrec.py
Last active Sep 13, 2018
Simultaneous record and play using pysoundfile and pyaudio libraries.
View playrec.py
#!/usr/bin/env python2
"""
Simultaneous record and play using libsndfile and portaudio libraries.
You should choose a stream rate that is compatible with your device HW,
or you could get unreliable results.
"""
import pyaudio as pa
import soundfile as sf
import wave
@tgarc
tgarc / parse_fspec.py
Last active Jul 21, 2016
Parse the format specification (https://docs.python.org/2.7/library/string.html#format-specification-mini-language) from a .format style python string
View parse_fspec.py
import re
from string import Formatter
_fspecre = ("((?P<fill>{fill})?(?P<align>{align}))?"
"(?P<sign>{sign})?"
"(?P<prefix>#)?"
"(?P<zeropad>0)?"
"(?P<width>{width})?"
"(?P<thousands>,)?"
"(?:\.(?P<precision>{precision}))?"
You can’t perform that action at this time.