Package gmisclib :: Module wavio
[frames] | no frames]

Module wavio

source code

When run as a script: python ~/lib/wavio.py [-g gain] -wavin|-wavout infile outfile Reads or writes .wav files from any format supported by gpkimgclass.py .

As a library, allows reading of class gpk_img data from a .WAV file, and writing class gpk_img to a .WAV file.

Classes
  Overflow
  BadFileFormatError
Functions
dict(str: str or float or int)
read_hdr(fn)
Read header information for a .WAV file.
source code
gpkimgclass instance
read(fn, tstart=None, t_end=None, t_error=0)
Reads in a .WAV file and returns a gpkimgclass.gpk_img instance that contains the header and data information.
source code
 
write(data, fname, scalefac=1, allow_overflow=0) source code
Variables
  OV_ERROR = 0
Cause write to raise an error on overflow.
  OV_LIMIT = 1
Cause write to truncate overflows.
  OV_IGNORE = 2
Cause write to silently ignore overflows.
  T_ERROR = 0
Cause read to raise an error when timing is out of range.
  T_LIMIT = 1
Cause read to quietly supply as much of the requested data as possible.
  __package__ = 'gmisclib'

Imports: wave, gpkimgclass, numpy


Function Details

read_hdr(fn)

source code 

Read header information for a .WAV file. The header contains information formatted as per gpkimgclass.gpk_img, i.e. FITS standard information.

Parameters:
  • fn (str) - filename
Returns: dict(str: str or float or int)

read(fn, tstart=None, t_end=None, t_error=0)

source code 

Reads in a .WAV file and returns a gpkimgclass.gpk_img instance that contains the header and data information. If tstart and/or t_end are specified, it seeks and only reads in the necessary data between tstart and t_end.

Parameters:
  • fn (str) - filename
  • tstart (float) - time at which to start reading audio data
  • t_end (float) - time at which to stop reading audio data
  • t_error (int, either T_ERROR or T_LIMIT.) - What to do if the requested t_start or t_end are out of range? Either raise a ValueError (T_ERROR) or adjust the limits (T_LIMIT).
Returns: gpkimgclass instance
audio data

write(data, fname, scalefac=1, allow_overflow=0)

source code 
Parameters:
  • data - is a class gpk_img object containing data to be written (note that the header information is ignored except for the sampling rate (CDELT2) and bits per pixel (BITPIX)). The length and number of channels is taken from data.d.shape.
  • fname (str or file,) - is the name of a file to write it to (or a file object),
  • scalefac - is a factor to multiply the data
  • allow_overflow - can be either
    • OV_ERROR (default, means raise a ValueError exception if the data*scalefac overflows),
    • OV_LIMIT (means limit the data*scalefac to prevent overflows -- this clips the audio), or
    • OV_IGNORE (means let the overflows happen and don't worry.)
Raises:
  • ValueError - Missing information in data.
  • Overflow - The output format is clipping the data. Strictly speaking, on 16-bit data, 32767 is considered clipping even though it possibly might be OK. However such extreme values are very likely to be generated by clipping at an earlier stage of the processing, so it's probably an error even if the error is not being made here.