boodle.sample
index
boodle/sample.py

sample: A module containing the Sample class; also the SampleLoader
classes, which know how to load data from various sound files (AIFF,
WAV, etc).
 
Public functions:
 
get() -- load a sample object, given a filename or File object
get_info() -- measure the expected running time and looping params of a sound

 
Modules
       
aifc
bisect
boodle
boopak
fileinput
os
boodle.stereo
struct
sunau
wave

 
Classes
       
boodle.BoodlerError(exceptions.Exception)
SampleError
MixIn
Sample
MixinSample
SampleLoader
AifcLoader
MixinLoader
SunAuLoader
WavLoader

 
class AifcLoader(SampleLoader)
     Methods defined here:
raw_load(self, filename, csamp)

Data and other attributes defined here:
suffixlist = ['.aifc', '.aiff', '.aif']

Methods inherited from SampleLoader:
__init__(self)
load(self, filename, suffix)
register_suffixes(self)
reload(self, samp)

Data and other attributes inherited from SampleLoader:
suffixmap = {'.aif': <boodle.sample.AifcLoader instance>, '.aifc': <boodle.sample.AifcLoader instance>, '.aiff': <boodle.sample.AifcLoader instance>, '.au': <boodle.sample.SunAuLoader instance>, '.mixin': <boodle.sample.MixinLoader instance>, '.wav': <boodle.sample.WavLoader instance>}

 
class MixIn
    MixIn: base class for statically declared mix-in samples.
 
To use this, declare a construct:
 
class your_sample_name(MixIn):
    ranges = [
        MixIn.range(...),
        MixIn.range(...),
        MixIn.range(...),
    ]
    default = MixIn.default(...)
 
A range declaration looks like
 
    MixIn.range(maxval, sample)
or
    MixIn.range(minval, maxval, sample)
or
    MixIn.range(minval, maxval, sample, pitch=1.0, volume=1.0)
 
If you don't give a minval, the maxval of the previous range is used.
You may use the constants MixIn.MIN and MixIn.MAX to represent the
limits of the range. The pitch and volume arguments are optional.
 
A default declaration looks like
 
    MixIn.default(sample)
or
    MixIn.default(sample, pitch=1.0, volume=1.0)
 
The default declaration is option. (As are, again, the pitch and
volume arguments.)
 
When your declaration is complete, your_sample_name will magically
be a MixinSample instance (not a class).
 
  Static methods defined here:
__class__(name, bases, dic)
default(samp, pitch=None, volume=None)
sort_mixin_ranges(ranges)

Data and other attributes defined here:
MAX = 1000000.0
MIN = 0.0
range = <class boodle.sample.range>

 
class MixinLoader(SampleLoader)
     Methods defined here:
load(self, filename, suffix)
parseparam(self, filename, dirname, tok)
reload(self, samp)

Data and other attributes defined here:
suffixlist = ['.mixin']

Methods inherited from SampleLoader:
__init__(self)
register_suffixes(self)

Data and other attributes inherited from SampleLoader:
suffixmap = {'.aif': <boodle.sample.AifcLoader instance>, '.aifc': <boodle.sample.AifcLoader instance>, '.aiff': <boodle.sample.AifcLoader instance>, '.au': <boodle.sample.SunAuLoader instance>, '.mixin': <boodle.sample.MixinLoader instance>, '.wav': <boodle.sample.WavLoader instance>}

 
class MixinSample(Sample)
     Methods defined here:
__init__(self, filename, ranges, default, modname=None)
find(self, pitch)
get_info(self, pitch=1.0)
queue_note(self, pitch, volume, pan, starttime, chan)
queue_note_duration(self, pitch, volume, pan, starttime, duration, chan)

Methods inherited from Sample:
__repr__(self)

Data and other attributes inherited from Sample:
reloader = None

 
class Sample
    Sample: represents a sound file, held in memory.
 
This is really just a container for a native object (csamp), which
is used by the cboodle native module. Samples may only be created
by the SampleLoader classes in this module.
 
  Methods defined here:
__init__(self, filename, csamp)
__repr__(self)
get_info(self, pitch=1.0)
queue_note(self, pitch, volume, pan, starttime, chan)
queue_note_duration(self, pitch, volume, pan, starttime, duration, chan)

Data and other attributes defined here:
reloader = None

 
class SampleError(boodle.BoodlerError)
    SampleError: Represents problems encountered while finding or
loading sound files.
 
 
Method resolution order:
SampleError
boodle.BoodlerError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Data descriptors inherited from boodle.BoodlerError:
__weakref__
list of weak references to the object (if defined)

Methods inherited from exceptions.Exception:
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message
exception message

 
class SampleLoader
    SampleLoader: Base class for the facility to load a particular
form of sound sample from a file.
 
Subclasses of this are defined and instantiated later in the module.
 
  Methods defined here:
__init__(self)
load(self, filename, suffix)
register_suffixes(self)
reload(self, samp)

Data and other attributes defined here:
suffixmap = {'.aif': <boodle.sample.AifcLoader instance>, '.aifc': <boodle.sample.AifcLoader instance>, '.aiff': <boodle.sample.AifcLoader instance>, '.au': <boodle.sample.SunAuLoader instance>, '.mixin': <boodle.sample.MixinLoader instance>, '.wav': <boodle.sample.WavLoader instance>}

 
class SunAuLoader(SampleLoader)
     Methods defined here:
raw_load(self, filename, csamp)

Data and other attributes defined here:
suffixlist = ['.au']

Methods inherited from SampleLoader:
__init__(self)
load(self, filename, suffix)
register_suffixes(self)
reload(self, samp)

Data and other attributes inherited from SampleLoader:
suffixmap = {'.aif': <boodle.sample.AifcLoader instance>, '.aifc': <boodle.sample.AifcLoader instance>, '.aiff': <boodle.sample.AifcLoader instance>, '.au': <boodle.sample.SunAuLoader instance>, '.mixin': <boodle.sample.MixinLoader instance>, '.wav': <boodle.sample.WavLoader instance>}

 
class WavLoader(SampleLoader)
     Methods defined here:
raw_load(self, filename, csamp)

Data and other attributes defined here:
suffixlist = ['.wav']

Methods inherited from SampleLoader:
__init__(self)
load(self, filename, suffix)
register_suffixes(self)
reload(self, samp)

Data and other attributes inherited from SampleLoader:
suffixmap = {'.aif': <boodle.sample.AifcLoader instance>, '.aifc': <boodle.sample.AifcLoader instance>, '.aiff': <boodle.sample.AifcLoader instance>, '.au': <boodle.sample.SunAuLoader instance>, '.mixin': <boodle.sample.MixinLoader instance>, '.wav': <boodle.sample.WavLoader instance>}

 
Functions
       
adjust_timebase(trimoffset, maxage)
find_loader(suffix)
find_loader(suffix) -> SampleLoader
 
Locate the SampleLoader instance which handles the given file
suffix. (The suffix should be given as a dot followed by lower-case
characters.)
get(sname)
get(sample) -> Sample
 
Load a sample object, given a filename or File object. (You can also
pass a Sample object; it will be returned back to you.)
 
(If the filename is relative, $BOODLER_SOUND_PATH is searched.)
 
The module maintains a cache of sample objects, so if you load the
same filename twice, the second get() call will be fast.
 
This function is not useful, since agent.sched_note() and such methods
call it for you -- they accept filenames as well as sample objects. 
This function is available nevertheless.
get_info(samp, pitch=1)
get_info(sample, pitch=1) -> tuple
 
Measure the expected running time and looping parameters of a sound.
The argument can be either a filename, or a sample object (as 
returned by get()).
 
The result is a 2-tuple. The first member is the duration of the
sound (in seconds, if played with the given pitch -- by default,
the sound's original pitch). The second member is None, if the
sound has no looping parameters, or a 2-tuple (loopstart, loopend).
 
The result of this function may not be precisely accurate, due
to rounding annoyances. In particular, the duration may not be
exactly equal to the value returned by agent.sched_note(), when
the note is actually played.
unload_unused(deathtime)

 
Data
        aifc_loader = <boodle.sample.AifcLoader instance>
big_endian = 1
cache = {}
cboodle = <boodle.DummyDriver>
mixin_loader = <boodle.sample.MixinLoader instance>
sound_dirs = ['.']
sunau_loader = <boodle.sample.SunAuLoader instance>
wav_loader = <boodle.sample.WavLoader instance>