Documentation ¶
Index ¶
- Variables
- func BufSize(o int) optSourceProc
- func End(o int) optSourceProc
- func FrameSize(o int) optSourceProc
- func Fs(o float64) optSourceProc
- func Start(o int) optSourceProc
- func StepSize(o int) optSourceProc
- func WinType(o int) optSourceProc
- func Zm(o bool) optSourceProc
- type Iter
- type SourceProc
- func (src *SourceProc) Get(idx int) (dsp.Value, error)
- func (src *SourceProc) ID() string
- func (src *SourceProc) Mean() float64
- func (src *SourceProc) Next() error
- func (src *SourceProc) NumFrames() int
- func (src *SourceProc) NumSamples() int
- func (t *SourceProc) Option(options ...optSourceProc) (previous optSourceProc)
- func (src *SourceProc) Rewind(start, end, frameSize, stepSize int, winType int) error
- func (src *SourceProc) SD() float64
- type Waveform
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 FrameSize ¶
func FrameSize(o int) optSourceProc
FrameSize sets a value for instances of type SourceProc.
func StepSize ¶
func StepSize(o int) optSourceProc
StepSize 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 ¶
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) Frame ¶
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 ¶
Next returns the next available waveform. When there are no more waveforms, Done is returned as the error.
func (*Iter) NextSegment ¶
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.
type SourceProc ¶
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 ¶
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 ¶
Mean returns the mean of the waveform samples as they were read from the source.