Package sage :: Package media :: Module wav :: Class Wave
[hide private]
[frames] | no frames]

Class Wave

source code

                      object --+    
                               |    
structure.sage_object.SageObject --+
                                   |
                                  Wave


A class wrapping a wave audio file.

INPUT:
    You must call Wave() with either data = filename, where
    filename is the name of a wave file, or with each of the
    following options:

        channels  -- the number of channels in the wave file (1 for
                    mono, 2 for stereo, etc...
        width     -- the number of bytes per sample
        framerate -- the number of frames per second
        nframes   -- the number of frames in the data stream
        bytes     -- a string object containing the bytes of the
                     data stream

Slicing:
    Slicing a Wave object returns a new wave object that has been
    trimmed to the bytes that you have given it.

Indexing:
    Getting the $n$th item in a Wave object will give you the value
    of the $n$th frame.



Instance Methods [hide private]
 
__init__(self, data=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., **kwds)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
save(self, filename='sage.wav')
Save this wave file to disk, either as a SAGE sobj or as a .wav file.
source code
 
listen(self)
Listen to (or download) this wave file.
source code
 
channel_data(self, n)
Get the data from a given channel.
source code
 
getnchannels(self)
Returns the number of channels in this wave object.
source code
 
getsampwidth(self)
Returns the number of bytes per sample in this wave object.
source code
 
getframerate(self)
Returns the number of frames per second in this wave object.
source code
 
getnframes(self)
The total number of frames in this wave object.
source code
 
readframes(self, n)
Reads out the raw data for the first $n$ frames of this wave object.
source code
 
getlength(self)
Returns the length of this file (in seconds).
source code
 
_repr_(self) source code
 
_normalize_npoints(self, npoints)
Used internally while plotting to normalize the number of
source code
 
domain(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Used internally for plotting.
source code
 
values(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., channel=0)
Used internally for plotting.
source code
 
set_values(self, values, channel=0)
Used internally for plotting.
source code
 
vector(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., channel=0) source code
 
plot(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., channel=0, plotjoined=True, **kwds)
Plots the audio data.
source code
 
plot_fft(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., channel=0, half=True, **kwds) source code
 
plot_raw(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., channel=0, plotjoined=True, **kwds) source code
 
__getitem__(self, i) source code
 
slice_seconds(self, start, stop)
Slices the wave from start to stop.
source code
 
__getslice__(self, start, stop) source code
 
_copy(self, start, stop) source code
 
__copy__(self) source code
 
convolve(self, right, channel=0)
NOT DONE! Convolution of self and other, i.e., add their fft's, then inverse fft back.
source code

Inherited from structure.sage_object.SageObject: __hash__, __new__, __repr__, _axiom_, _axiom_init_, _gap_, _gap_init_, _gp_, _gp_init_, _interface_, _interface_init_, _interface_is_cached_, _kash_, _kash_init_, _macaulay2_, _macaulay2_init_, _magma_, _magma_init_, _maple_, _maple_init_, _mathematica_, _mathematica_init_, _maxima_, _maxima_init_, _octave_, _octave_init_, _pari_, _pari_init_, _r_init_, _sage_, _singular_, _singular_init_, category, db, dump, dumps, rename, reset_name, version

Inherited from object: __delattr__, __getattribute__, __reduce__, __reduce_ex__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, data=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., **kwds)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

save(self, filename='sage.wav')

source code 

Save this wave file to disk, either as a SAGE sobj or as a .wav file.

INPUT:
    filename -- the path of the file to save. If filename ends
                with 'wav', then save as a wave file,
                otherwise, save a SAGE object.

    If no input is given, save the file as 'sage.wav'.
    

Overrides: structure.sage_object.SageObject.save

listen(self)

source code 

Listen to (or download) this wave file.

Creates a link to this wave file in the notebook.

channel_data(self, n)

source code 

Get the data from a given channel.

INPUT:
    n -- the channel number to get

OUTPUT:
    A list of signed ints, each containing the value of a frame.

getnchannels(self)

source code 

Returns the number of channels in this wave object.

OUTPUT:
    The number of channels in this wave file.

getsampwidth(self)

source code 

Returns the number of bytes per sample in this wave object.

OUTPUT:
    The number of bytes in each sample.

getframerate(self)

source code 

Returns the number of frames per second in this wave object.

OUTPUT:
    The frame rate of this sound file.

getnframes(self)

source code 

The total number of frames in this wave object.

OUTPUT:
    The number of frames in this WAV.

readframes(self, n)

source code 

Reads out the raw data for the first $n$ frames of this wave
object.

INPUT:
    n -- the number of frames to return

OUTPUT:
    A list of bytes (in string form) representing the raw wav data.

getlength(self)

source code 

Returns the length of this file (in seconds).

OUTPUT:
    The running time of the entire WAV object.

domain(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Used internally for plotting. Get the x-values for the various points to plot.

values(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., channel=0)

source code 

Used internally for plotting. Get the y-values for the various points to plot.

set_values(self, values, channel=0)

source code 

Used internally for plotting. Get the y-values for the various points to plot.

plot(self, npoints=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., channel=0, plotjoined=True, **kwds)

source code 

Plots the audio data.

INPUT:
    npoints -- number of sample points to take; if not given, draws
               all known points.
    channel -- 0 or 1 (if stereo).  default: 0
    plotjoined -- whether to just draw dots or draw lines between sample points

OUTPUT:
    a plot object that can be shown.

Overrides: structure.sage_object.SageObject.plot

slice_seconds(self, start, stop)

source code 

Slices the wave from start to stop.

INPUT:
    start -- the time index from which to begin the slice (in seconds)
    stop -- the time index from which to end the slice (in seconds)

OUTPUT:
    A Wave object whose data is this objects's data,
    sliced between the given time idices