Package: wavemap
Manipulate huge WAVE or RAW files as numpy matrices - even if they are too
large to fit into memory.Memory mapping is a technique where files on disk are directly mapped to
locations in memory and use the same logic as swap space does.Samples from a WAVE or RAW audio file are directly memory mapped to entries in
anumpyarray, letting you manipulate very large audio files as if they
all fit into memory at one time, and even directly change samples on disk.Typical usage:importwavemapwm=wavemap('test.wav','r+')# r+ means read/write# Now you have a numpy matrix that you can use like any otherwm/=2# Each sample in the file is scaled by half.APIwavemap()wavemap(filename:str,mode:str='r',order:Union[str,NoneType]=None,always_2d:bool=False,dtype:Union[numpy.dtype,NoneType]=None,shape:Union[NoneType,int,tuple]=None,sample_rate:int=0,roffset:int=0,warn:Union[Callable,NoneType]='<function warn:  print to stderr>',)(wavemap/__init__.py, 56-121)Memory map a WAVE file to anumpyarrayReturn an instance ofReadMaporWriteMap, depending onmode.ARGUMENTSfilenameThe name of the file being mappedmodeThe file is opened in this mode.
Must be one of'r','r+','c','w+'In mode'r', the default, the file is opened read-only and
thenumpy.darrayis immutable.In mode'r+', the file is opened read-write and changes to thenumpy.darrayare automatically applied to the file.In mode'c', “copy-on-write”, the file is opened read-only, but
thenumpy.darrayisnotimmutable: changes to the array are
instead stored in memory.In mode'w+', “write”, the file is opened for write, and overwrites
whatever else is there.orderSamples usually get laid out in into anumpy.darraywith``
shape=(N, C)`` whereNis the number of audio frames, andCis
the number of channels.This is called column major order, but this can be toggled by
setting theorderparameter toFfor Fortan or row-major row.Seehttps://stackoverflow.com/questions/27266338/always_2dIfFalse, the default, mono WAVE files with only one channel
get special treatment and are mapped to a one-dimensional vector
withsize=(N,).IfTrue, mono WAVE files are treated the same as any other file
and are mapped to a two-dimensional matrix withsize=(N,1).dtypeThe numpy datatype of the samples in the file.shapeThe shape of the resulting numpy.darray. Can be a tuple, or a positive
integer, orNone.sample_rateThe sample rate in Hz (cycles per second)roffsetHow many bytes in the file after the WAV datawarnProgrammers are sloppy so quite a lot of real-world WAVE files have
recoverable errors in their format.warnis the function used to
report those recoverable errors.  By default, it’s set to print tosys.stderrbut setting it toNonedisables errors entirely, or
you can pass your own callback inClasswavemap.RawMap(wavemap/raw.py, 14-67)“Memory map raw audio data from a disk file into a numpy matrixwavemap.RawMap.__new__()wavemap.RawMap.__new__(cls,filename:str,dtype:numpy.dtype,shape:Union[tuple,int,NoneType]=None,mode:str='r',offset:int=0,roffset:int=0,order:Union[str,NoneType]=None,always_2d:bool=False,warn:Union[Callable,NoneType]='<function warn:  print to stderr>',)(wavemap/raw.py, 17-67)Memory map raw audio data from a disk file into a numpy matrixARGUMENTSclsThink of this asself.  (This is because you need to implement__new__and not__init__when deriving fromnp.darray.)filenameThe name of the file being mappeddtypeThe numpy datatype of the samples in the file.shapeThe shape of the resulting numpy.darray. Can be a tuple, or a positive
integer, orNone.modeThe file is opened in this mode.
Must be one of'r','r+','c','w+'In mode'r', the default, the file is opened read-only and
thenumpy.darrayis immutable.In mode'r+', the file is opened read-write and changes to thenumpy.darrayare automatically applied to the file.In mode'c', “copy-on-write”, the file is opened read-only, but
thenumpy.darrayisnotimmutable: changes to the array are
instead stored in memory.In mode'w+', “write”, the file is opened for write, and overwrites
whatever else is there.offsetHow many bytes in the file before the WAV dataroffsetHow many bytes in the file after the WAV dataorderSamples usually get laid out in into anumpy.darraywith``
shape=(N, C)`` whereNis the number of audio frames, andCis
the number of channels.This is called column major order, but this can be toggled by
setting theorderparameter toFfor Fortan or row-major row.Seehttps://stackoverflow.com/questions/27266338/always_2dIfFalse, the default, mono WAVE files with only one channel
get special treatment and are mapped to a one-dimensional vector
withsize=(N,).IfTrue, mono WAVE files are treated the same as any other file
and are mapped to a two-dimensional matrix withsize=(N,1).warnProgrammers are sloppy so quite a lot of real-world WAVE files have
recoverable errors in their format.warnis the function used to
report those recoverable errors.  By default, it’s set to print tosys.stderrbut setting it toNonedisables errors entirely, or
you can pass your own callback inClasswavemap.ReadMap(wavemap/read.py, 18-84)Memory-map an existing WAVE file into a numpy vector or matrixwavemap.ReadMap.__new__()wavemap.ReadMap.__new__(cls:Type,filename:str,mode:str='r',order:Union[str,NoneType]=None,always_2d:bool=False,warn:Union[Callable,NoneType]='<function warn:  print to stderr>',)(wavemap/read.py, 21-84)Memory-map an existing WAVE file into a numpy matrix.ARGUMENTSclsThink of this asself.  (This is because you need to implement__new__and not__init__when deriving fromnp.darray.)filenameThe name of the file being mappedmodeThe file is opened in this mode.
Must be one of'r','r+'and'c'.In mode'r', the default, the file is opened read-only and
thenumpy.darrayis immutable.In mode'r+', the file is opened read-write and changes to thenumpy.darrayare automatically applied to the file.In mode'c', “copy-on-write”, the file is opened read-only, but
thenumpy.darrayisnotimmutable: changes to the array are
instead stored in memory.orderSamples usually get laid out in into anumpy.darraywith``
shape=(N, C)`` whereNis the number of audio frames, andCis
the number of channels.This is called column major order, but this can be toggled by
setting theorderparameter toFfor Fortan or row-major row.Seehttps://stackoverflow.com/questions/27266338/always_2dIfFalse, the default, mono WAVE files with only one channel
get special treatment and are mapped to a one-dimensional vector
withsize=(N,).IfTrue, mono WAVE files are treated the same as any other file
and are mapped to a two-dimensional matrix withsize=(N,1).warnProgrammers are sloppy so quite a lot of real-world WAVE files have
recoverable errors in their format.warnis the function used to
report those recoverable errors.  By default, it’s set to print tosys.stderrbut setting it toNonedisables errors entirely, or
you can pass your own callback inClasswavemap.WriteMap(wavemap/write.py, 12-115)“Memory-map a new wave file into a new numpy vector or matrixwavemap.WriteMap.__new__()wavemap.WriteMap.__new__(cls:Type,filename:str,dtype:numpy.dtype,shape:Union[NoneType,int,tuple],sample_rate:int,roffset:int=0,warn:Union[Callable,NoneType]='<function warn:  print to stderr>',)(wavemap/write.py, 15-85)Open a memory-mapped WAVE file in write mode and overwrite any existing
file.ARGUMENTSclsThink of this asself.  (This is because you need to implement__new__and not__init__when deriving fromnp.darray.)filenameThe name of the file being mappeddtypeThe numpy datatype of the samples in the file.shapeThe shape of the resulting numpy.darray. Can be a tuple, or a positive
integer, orNone.sample_rateThe sample rate in Hz (cycles per second)roffsetHow many bytes in the file after the WAV datawarnProgrammers are sloppy so quite a lot of real-world WAVE files have
recoverable errors in their format.warnis the function used to
report those recoverable errors.  By default, it’s set to print tosys.stderrbut setting it toNonedisables errors entirely, or
you can pass your own callback inwavemap.convert()wavemap.convert(arr:numpy.ndarray,dtype:Union[numpy.dtype,NoneType],must_copy:bool=False,)(wavemap/convert.py, 6-77)Returns a copy of a numpy array or matrix that represents audio data in
another type, scaling and shifting as necessary.ARGUMENTSarrA numpy darray representing an audio signaldtypeThe numpy dtype to convert to - none means “no conversion”must_copyIf true,arris copied even if it is already the requested type(automatically generated bydokson 2021-02-23T14:37:02.652534)