Module pippi.soundbuffer
Functions
rebuild_buffer
def rebuild_buffer(
frames,
channels,
samplerate
)
Classes
SoundBuffer
class SoundBuffer(
/,
*args,
**kwargs
)
A sequence of audio frames representing a buffer of sound.
Data may be loaded into the SoundBuffer from these sources as keyword arguments, in decending order of precedence:
filename
: a unicode string relative path or a full path to load from a soundfilebuf
: a memoryview compatible 2D buffer of doublesframes
: a 1D or 2D python iterable (eg a list) or a 1D numpy array/buffer
Data loaded via the filename
keyword can load any soundfile type supported by libsndfile,
including old favorites like WAV, AIFF, FLAC, and OGG. But no, not MP3. (At least not yet: https://github.com/erikd/libsndfile/issues/258)
If the length
param is given, only that amount will be read from the soundfile.
Use the start
param to specify a position (seconds) in the soundfile to begin reading from.
No samplerate conversion is done (yet) so be careful to match the samplerate of the start param with that
of the soundfile being read. (Or don't!)
Overflows (reading beyond the boundries of the file) are filled with silence so the length
param is always respected and will return a SoundBuffer of the requested length. This is
just a wrapper around the soundfile
libsndfile wrapper's read method.
Data loaded via the buf
keyword must be interpretable by cython as a memoryview on a 2D array
of doubles. (A numpy ndarray for example.)
Single channel (1D) data loaded via the frames
keyword will be copied into the given number of channels
specified by the channels
param. (And if no value is given, a mono SoundBuffer will be created.)
Handy for doing synthesis prototyping with python lists.
Multichannel (2D) data loaded via the frames
keyword will ignore the channels
param and adapt to what was given by attempting to read the data into a numpy array
and take the number of channels from its shape.
The remaining sources (filename
, buf
) will use the number of channels found in the
data and ignore the value passed to the SoundBuffer initializer.
If none of those sources are present, but a length
param has been given,
the SoundBuffer will be initialized with silence to the given length in seconds.
Otherwise an empty SoundBuffer is created with a length of zero.
Supported formats for soundfile reading & writing via libsndfile: AIFF - AIFF (Apple/SGI) AU - AU (Sun/NeXT) AVR - AVR (Audio Visual Research) CAF - CAF (Apple Core Audio File) FLAC - FLAC (Free Lossless Audio Codec) HTK - HTK (HMM Tool Kit) SVX - IFF (Amiga IFF/SVX8/SV16) MAT4 - MAT4 (GNU Octave 2.0 / Matlab 4.2) MAT5 - MAT5 (GNU Octave 2.1 / Matlab 5.0) MPC2K - MPC (Akai MPC 2k) OGG - OGG (OGG Container format) PAF - PAF (Ensoniq PARIS) PVF - PVF (Portable Voice Format) RAW - RAW (header-less) RF64 - RF64 (RIFF 64) SD2 - SD2 (Sound Designer II) SDS - SDS (Midi Sample Dump Standard) IRCAM - SF (Berkeley/IRCAM/CARL) VOC - VOC (Creative Labs) W64 - W64 (SoundFoundry WAVE 64) WAV - WAV (Microsoft) NIST - WAV (NIST Sphere) WAVEX - WAVEX (Microsoft) WVE - WVE (Psion Series 3) XI - XI (FastTracker 2)
Class variables
avg
channels
dur
frames
mag
samplerate
Methods
adsr
def adsr(
self,
a=0.0,
d=0.0,
s=1.0,
r=0.0
)
blocks
def blocks(
self,
blocksize=2048
)
clear
def clear(
self,
length=-1
)
Writes zeros into the buffer, adjusting the
size if length > 0.
clip
def clip(
self,
minval=-1,
maxval=1
)
cloud
def cloud(
self,
length=-1.0,
*args,
**kwargs
)
Create a new Cloud from this SoundBuffer
convolve
def convolve(
self,
impulse,
norm=True
)
copy
def copy(
self
)
Return a new copy of this SoundBuffer.
cut
def cut(
self,
start=0.0,
length=1.0
)
Copy a portion of this soundbuffer, returning
a new soundbuffer with the selected slice.
This is called cut
for historical reasons, but it
might be better understood if renamed to slice
as it
doesn't modify the source SoundBuffer in any way.
The start
param is a position in seconds to begin
cutting, and the length
param is the cut length in seconds.
Overflowing values that exceed the boundries of the source SoundBuffer
will return a SoundBuffer padded with silence so that the length
param
is always respected.
dub
def dub(
self,
sounds,
pos=-1.0,
framepos=0
)
Dub a sound or iterable of sounds into this soundbuffer
starting at the given position in fractional seconds.
>>> snd.dub(snd2, 3.2)
To dub starting at a specific frame position use:
>>> snd.dub(snd3, framepos=111)
env
def env(
self,
window=None
)
Apply an amplitude envelope
to the sound of the given type.
To modulate a sound with an arbitrary iterable, simply do:
>>> snd * iterable
Where iterable is a list, array, or SoundBuffer with the same # of channels and of any length
fadein
def fadein(
self,
amount
)
fadeout
def fadeout(
self,
amount
)
fcut
def fcut(
self,
start=0,
length=1
)
Copy a portion of this soundbuffer, returning
a new soundbuffer with the selected slice.
Identical to cut
except start
and length
should be given in frames instead of seconds.
fill
def fill(
self,
length
)
Truncate the buffer to the given length or
loop the contents of the buffer up to the given length in frames.
grains
def grains(
self,
minlength,
maxlength=-1.0
)
Iterate over the buffer in fixed-size grains.
If a second length is given, iterate in randomly-sized grains, given the minimum and maximum sizes.
graph
def graph(
self,
*args,
**kwargs
)
max
def max(
self
)
mix
def mix(
self,
sounds
)
Mix this sound in place with a sound or iterable of sounds
pad
def pad(
self,
start=0.0,
end=0.0,
samples=False
)
Pad this sound with silence at start or end
pan
def pan(
self,
pos=0.5,
method=None
)
Pan a stereo sound from pos=0
(hard left) to pos=1
(hard right)
Different panning strategies can be chosen by passing a value to the method
param.
method='constant'
Constant (square) power panning. This is the default.method='linear'
Simple linear panning.method='sine'
Variation on constant power panning using sin() and cos() to shape the pan. Taken from the floss manuals csound manual.method='gogins'
Michael Gogins' variation on the above which uses a different part of the sinewave. Also taken from the floss csound manual!
rcut
def rcut(
self,
length=1.0
)
Copy a portion of this SoundBuffer of the
given length in seconds starting from a random position within it.
This will always return a complete SoundBuffer without overflows or added silence, and the entire sound will be returned without added silence if a length that exceeds the length of the source SoundBuffer is given -- unlike SoundBuffer.cut() which will pad results with silence to preserve the length param if an invalid or overflowing offset position is given.
remix
def remix(
self,
channels
)
repeat
def repeat(
self,
reps=2
)
reverse
def reverse(
self
)
reversed
def reversed(
self
)
softclip
def softclip(
self
)
softclip2
def softclip2(
self
)
speed
def speed(
self,
speed,
scheme=0
)
Change the speed of the sound
stretch
def stretch(
self,
length,
position=None,
amp=1.0
)
Change the length of the sound without changing the pitch.
Uses the csound mincer
phase vocoder implementation from soundpipe.
taper
def taper(
self,
length
)
toenv
def toenv(
self,
window=0.015
)
towavetable
def towavetable(
self,
*args,
**kwargs
)
transpose
def transpose(
self,
speed,
length=None,
position=None,
amp=1.0
)
Change the pitch of the sound without changing the length.
Uses the csound mincer
phase vocoder implementation from soundpipe.
trim
def trim(
self,
start=False,
end=True,
threshold=0.0,
window=4
)
Trim silence below a given threshold from the end (and/or start) of the buffer
vspeed
def vspeed(
self,
speed
)
write
def write(
self,
filename=None
)
Write the contents of this buffer to disk
in the given audio file format.
Supported formats via libsndfile: AIFF - AIFF (Apple/SGI) AU - AU (Sun/NeXT) AVR - AVR (Audio Visual Research) CAF - CAF (Apple Core Audio File) FLAC - FLAC (Free Lossless Audio Codec) HTK - HTK (HMM Tool Kit) SVX - IFF (Amiga IFF/SVX8/SV16) MAT4 - MAT4 (GNU Octave 2.0 / Matlab 4.2) MAT5 - MAT5 (GNU Octave 2.1 / Matlab 5.0) MPC2K - MPC (Akai MPC 2k) OGG - OGG (OGG Container format) PAF - PAF (Ensoniq PARIS) PVF - PVF (Portable Voice Format) RAW - RAW (header-less) RF64 - RF64 (RIFF 64) SD2 - SD2 (Sound Designer II) SDS - SDS (Midi Sample Dump Standard) IRCAM - SF (Berkeley/IRCAM/CARL) VOC - VOC (Creative Labs) W64 - W64 (SoundFoundry WAVE 64) WAV - WAV (Microsoft) NIST - WAV (NIST Sphere) WAVEX - WAVEX (Microsoft) WVE - WVE (Psion Series 3) XI - XI (FastTracker 2)