wav

package
Version: v0.0.0-...-a7203c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2015 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Done = errors.New("no more json objects")

Done is returned as the error value when there are no more waveforms available in the stream.

Functions

func BufSize

func BufSize(o int) optSourceProc

BufSize sets a value for instances of type SourceProc.

func End

func End(o int) optSourceProc

End sets a value for instances of type SourceProc.

func FrameSize

func FrameSize(o int) optSourceProc

FrameSize sets a value for instances of type SourceProc.

func Fs

func Fs(o float64) optSourceProc

Fs sets a value for instances of type SourceProc.

func Start

func Start(o int) optSourceProc

Start sets a value for instances of type SourceProc.

func StepSize

func StepSize(o int) optSourceProc

StepSize sets a value for instances of type SourceProc.

func WinType

func WinType(o int) optSourceProc

WinType sets a value for instances of type SourceProc.

func Zm

func Zm(o bool) optSourceProc

Zm sets a value for instances of type SourceProc.

Types

type Iter

type Iter struct {
	// contains filtered or unexported fields
}

Iter is an iterator to access waveforms sequentially.

func NewIterator

func NewIterator(path string, fs float64, frameSize, stepSize int) (*Iter, error)

NewIterator creates an iterator to access all waveforms in path. The waveform is partitioned into frames that may overlap with each other. The length of each frame is frameSize. The distance between succesive frames is stepSize. To get a single frame form the entire waveform use frameSize=0. If frameSize equals the stepSize, the waveform is partitioned using disjoint segments. To specify path see ju.JSONStreamer. It is the caller's responsibility to call Close to release the underlying readers.

func (*Iter) Close

func (iter *Iter) Close() error

Close underlying readers.

func (*Iter) Frame

func (iter *Iter) Frame(idx int) (dsp.Value, error)

Frame returns a frame of samples for the given index. NOTE: the slice may be shared with other processors or may be cached. For these reason, the caller should not modify the slice in-place.

func (*Iter) Next

func (iter *Iter) Next() (*Waveform, error)

Next returns the next available waveform. When there are no more waveforms, Done is returned as the error.

func (*Iter) NextSegment

func (iter *Iter) NextSegment(start, end int) (*Waveform, error)

NextSegment returns a segment of the next available waveform. When there are no more waveforms, Done is returned as the error. Param start is the index of the start sample. (Must be less than len(wav) and end.) Param end is the max value of the index of the last sample to be included. (Must be less than len(wav).) To set end to the size of the waveform use end=-1.

func (*Iter) NumFrames

func (iter *Iter) NumFrames() int

NumFrames returns the maximum number of frames in the waveform.

type SourceProc

type SourceProc struct {
	*dsp.Proc `opt:"-"`
	// contains filtered or unexported fields
}

SourceProc is a source processor that provides access to waveform data.

func NewSourceProc

func NewSourceProc(path string, options ...optSourceProc) (*SourceProc, error)

NewSourceProc create a new source of waveforms. See also New() for more details. If zeroMean is true, the mean of the waveform samples is subtracetd from every sample. Note that calling Mean() will still return the original mean value. Think of Mean() as the original mean value.

Example (Spectrum)
app := dsp.NewApp("Example App")

// Read a waveform.
path := filepath.Join(dir, "wav1.json.gz")
wavSource, err := NewSourceProc(path, Fs(8000))
if err != nil {
	panic(err)
}

// Add the source processor responsible for reading and supplying waveform samples.
wav := app.Add("wav", wavSource)

// Use a windowing processor to segment the waveform into frames of 80 samples
// and apply a Hamming window of size 205. The last arg is to instruct the processor
// to center the frame in the middle of the window.
window := app.Add("window", proc.NewWindowProc(80, 205, proc.Hamming, true))

// Compute the FFT of the windowed frame. The FFT size is 2**8.
spectrum := app.Add("spectrum", proc.SpectralEnergy(8))

// Connect the processors.
// wav -> window -> spectrum
app.Connect(window, wav)
app.Connect(spectrum, window)

// Get features using this object.
out := spectrum

// Get the next waveform. (This processor is designed to read a list of
// files. The Next() method loads the next waveform in the list.)
wavSource.Next()

// Get the spectrum for frame #10.
v, e := out.Get(10)
if e != nil {
	panic(e)
}

// Print first element of the FFT for frame #10.
fmt.Println(v.(*narray.NArray).Data[0])
Output:

5.123420120893221e-05

func (*SourceProc) Get

func (src *SourceProc) Get(idx int) (dsp.Value, error)

Get implements the dsp.Processer interface. If window option is used, window size must be less or equal than frameSize. If smaller, remaining samples are zero padded.

func (*SourceProc) ID

func (src *SourceProc) ID() string

ID returns the id of the current waveform.

func (*SourceProc) Mean

func (src *SourceProc) Mean() float64

Mean returns the mean of the waveform samples as they were read from the source.

func (*SourceProc) Next

func (src *SourceProc) Next() error

Next loads a segment of the next available waveform into the source. Returns Done when all waveforms have been processed. See also Waveform.NextSegment() for details. func (src *SourceProc) NextSegment(start, end int) error {

func (*SourceProc) NumFrames

func (src *SourceProc) NumFrames() int

NumFrames returns the number of frames in the current waveform.

func (*SourceProc) NumSamples

func (src *SourceProc) NumSamples() int

NumSamples returns the number of samples in the current waveform.

func (*SourceProc) Option

func (t *SourceProc) Option(options ...optSourceProc) (previous optSourceProc)

Option method sets the options. Returns previous option for last arg.

func (*SourceProc) Rewind

func (src *SourceProc) Rewind(start, end, frameSize, stepSize int, winType int) error

Rewind makes the the current waveform available for processing with different parameters. This is useful when the a waveform source needs to be segmented in multiple ways.

func (*SourceProc) SD

func (src *SourceProc) SD() float64

SD returns the standard deviation of the waveform samples as they were read from the source.

type Waveform

type Waveform struct {
	// ID is a waveform identifier.
	ID string `json:"id"`
	// Samples are the digital samples read as a float64.
	Samples []float64 `samples:"id"`
	// FS is the sampling frequency in Hertz.
	FS float64 `json:"fs,omitempty"`
	// contains filtered or unexported fields
}

A Waveform format for reading json files.

func New

func New(id string, samples []float64, fs float64) *Waveform

New returns a waveform object. To specifiy a sampling rate, use option fs. Use fs=0 to ignore checks. (In the future the package will convert the sampling rate.)

func (*Waveform) Mean

func (w *Waveform) Mean() float64

Mean returns the mean of the waveform samples as they were read from the source.

func (*Waveform) Reset

func (w *Waveform) Reset()

Reset implements the dsp.Resetter interface. Sets frame index back to zero.

func (*Waveform) SD

func (w *Waveform) SD() float64

SD returns the standard deviation of the waveform samples as they were read from the source.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL