signals

package module
v0.0.0-...-2b9299c Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2020 License: MIT Imports: 22 Imported by: 2

README

Signals

Status: (Beta :- stabilising API)

see "examples" folder for some uses.

Overview/docs: GoDoc

Installation:

 go get github.com/splace/signals   

Example:

package main

import . "github.com/splace/signals"
import (
	"fmt"
	"os"
)

var OneSecond = X(1)

func main() {
	signal := Modulated{Sine{OneSecond/100},NewConstant(-6)}
	// save file named after the go code of the signal
	file, err := os.Create(fmt.Sprintf("%+v.wav", signal)) 
	if err != nil {
		panic(err)
	}
	defer file.Close()
	Encode(file, 2, 8000, OneSecond, signal)
}

Produces file: Sine wave, 100hz, 50% volume (-6dB), 1 sec, @8k samples/sec, 2byte signed PCM (s16), WAV file

Features:

  • sources:- Sine, Square, Pulse, Heavyside, Bittrain, RampUp, RampDown, Sigmoid, PCM{8|16|24|32|48}bit (PCM sources can be stored in wav files)

  • modifiers:- Delayed, Spedup, Looped, Inverted, Reversed, Cached, RateModulated, Triggered, Segmented

  • combiners:- Sequenced, Modulated, Stacked, Composite

  • extras(non-core):- Depiction, ADSR, Noise, Wave (stream)

Extras examples: Depiction of "Stack{Sine{unitX/100}, Sine{unitX/50}}", red/black,(3200px.600px) for 4 * unitX.

(see image tests )

speech saved as wav

Documentation

Overview

This Package generates, stores, downloads and manipulates abstract signals, when imported it can then be used with specific real-world quantities.

Definition of a 'signal'

A varying value of some property, as it depends, uniquely, on some parameter.
The controlling parameter is generally unbounded, and the property bounded.

see; https://en.wikibooks.org/wiki/Signals_and_Systems/Definition_of_Signals_and_Systems.

Main Types

x - integer

the 'parameter' designed to be used as if it were unbounded (+ve and -ve), with unitX near the centre of its precision range.

y - integer

the 'property', a value between limits, +unitY and -unitY.

(the underlying types of x and y are kept hidden to enable simple generation of optimised packages with different ranges/precisions.)

Signal - Interface

has one method, property(x)y, which returns a 'y' value from an 'x' value parameter.

fundamentally procedural, calculated as needed, so that any 'x' value returns a 'y' value.

changes to parameters effect returned values from any other Signals composed from them.

saved/loaded, lossily, as PCM data. (PCM data can be Waveform Audio File Format ,.wav file.)

saved/loaded from a go code binary (.gob) file, (and signals can stream data, including gob files.) making for a basic interpreted signal language.

LimitedSignal - Interface

a Signal with an additional method; MaxX(), that returns the 'x' value above which the Signal can be assumed to return zero, effectively the Signals end.

when required, an 'x' value of zero is regarded as a Signals start.

PeriodicSignal - Interface

a Signal with an additional method; Period(), returning the 'x' length over which it repeats.

or when required any fundamental wavelength

or the sample spacing for one of the PCM Signal types.

PeriodicLimitedSignal - Interface

both above, and is implemented by the PCM Signal types.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DB

func DB(vol float64) float64

func Encode

func Encode(w io.Writer, sampleBytes uint8, sampleRate uint32, length x, ss ...Signal) (err error)

Encode Signals as PCM data, in a Riff wave container.

func EncodeLike

func EncodeLike(w io.Writer, s PeriodicSignal, p LimitedSignal)

encode a LimitedSignal with a sampleRate equal to the Period() of a given PeriodicSignal, and its precision if its a PCM type, otherwise defaults to 16bit.

func LoadPCM

func LoadPCM(pathTo string, p *PCM) (err error)

loads, in advanced way, a PCM from provided path. if the path has a numerical name, that is taken as the loaded sampleRate, and the PCM is set to it. if it isn't, the subfolder with a name equal to the provided PCM's sample rate is loaded. (PCM sample rate unchanged.) actual data is taken from files with extension ".pcm".

func MultiplyX

func MultiplyX(m interface{}, d x) x

multiply anything by an x quantity

func MultiplyY

func MultiplyY(m interface{}, d y) y

multiply anything by an y quantity

func ReadGOB

func ReadGOB(p io.Reader, s *Signal) error

read Gob encoding

func SaveGOB

func SaveGOB(pathTo string, s Signal) error

save Gob encoding

func SavePCM

func SavePCM(path string, pcm PCM) error

save PCM into a given path's sub-folder depending on its sample rate. (see LoadPCM)

func Vol

func Vol(DB float64) float64

func WriteGOB

func WriteGOB(p io.Writer, s Signal) error

write Gob encoding

func X

func X(d interface{}) x

convert to internal x representation, 1 -> UnitX

func Y

func Y(d interface{}) y

convert to internal y representation, 1 -> unitY

Types

type ADSREnvelope

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

Attack Decay Sustain Release (ADSR) envelope. see https://en.wikipedia.org/wiki/Synthesizer#Attack_Decay_Sustain_Release_.28ADSR.29_envelope

Example
s := NewADSREnvelope(unitX, unitX, unitX, unitY/2, unitX)
for t := x(0); t < 5*unitX; t += unitX / 10 {
	fmt.Println(s.property(t), strings.Repeat(" ", int(s.property(t)/(unitY/33))+33)+"X")
}
fmt.Println()
/* Output:
  0.00%                                  X
 10.00%                                     X
 20.00%                                        X
 30.00%                                           X
 40.00%                                               X
 50.00%                                                  X
 60.00%                                                     X
 70.00%                                                         X
 80.00%                                                            X
 90.00%                                                               X
100.00%                                                                  X
 95.00%                                                                 X
 90.00%                                                               X
 85.00%                                                              X
 80.00%                                                            X
 75.00%                                                          X
 70.00%                                                         X
 65.00%                                                       X
 60.00%                                                     X
 55.00%                                                    X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 50.00%                                                  X
 45.00%                                                X
 40.00%                                               X
 35.00%                                             X
 30.00%                                           X
 25.00%                                          X
 20.00%                                        X
 15.00%                                      X
 10.00%                                     X
  5.00%                                   X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
  0.00%                                  X
*/  X
  0.00%                                  X
*/
Output:

   0.00%                                  X
  10.00%                                     X
  20.00%                                        X
  30.00%                                           X
  40.00%                                               X
  50.00%                                                  X
  60.00%                                                     X
  70.00%                                                         X
  80.00%                                                            X
  90.00%                                                               X
 100.00%                                                                  X
  95.00%                                                                 X
  90.00%                                                               X
  85.00%                                                              X
  80.00%                                                            X
  75.00%                                                          X
  70.00%                                                         X
  65.00%                                                       X
  60.00%                                                     X
  55.00%                                                    X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  50.00%                                                  X
  45.00%                                                X
  40.00%                                               X
  35.00%                                             X
  30.00%                                           X
  25.00%                                          X
  20.00%                                        X
  15.00%                                      X
  10.00%                                     X
   5.00%                                   X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X
   0.00%                                  X

func NewADSREnvelope

func NewADSREnvelope(attack, decay, sustain x, sustainy y, release x) ADSREnvelope

func (ADSREnvelope) MaxX

func (s ADSREnvelope) MaxX() x

type Cached

type Cached struct {
	Signal
	// contains filtered or unexported fields
}

a Signal that stores and reuses, some, recent property values, rather than always getting them from the embedded Signal.

type Composite

type Composite []Signal

Composite is a PeriodicLimitedSignal, generated by adding together Signal(s). (PeriodicLimitedSignal's are Signal's so this can be hierarchical.) Composite's MaxX() comes from the largest contstituent MaxX(), (0 if none of the contained Signals are LimitedSignals.) Composite's Period() comes from its first member. As with 'OR' logic, all sources have to be zero (at a particular x) for Composite to be zero.

func NewComposite

func NewComposite(c ...Signal) Composite

helper to enable generation from another slice. will in general need to use a slice interface promoter function.

func (Composite) MaxX

func (c Composite) MaxX() (max x)

the largest Max X of the constituents.

func (Composite) Period

func (c Composite) Period() (period x)

type Compressed

type Compressed struct {
	Signal
	Factor float32
}

a Signal that scales the x of another Signal

func (Compressed) MaxX

func (s Compressed) MaxX() x

func (Compressed) Period

func (s Compressed) Period() x

type Constant

type Constant struct {
	Constant y
}

a Signal with constant value

func NewConstant

func NewConstant(DB float64) Constant

type Depiction

type Depiction struct {
	Signal
	// contains filtered or unexported fields
}

simple visual Depiction of a Signal, implements Depictor

func NewDepiction

func NewDepiction(s LimitedSignal, pxMaxX, pxMaxY int, below, above color.Color) Depiction

makes a Depiction of a LimitedSignal, scaled to pxMaxx by pxMaxy pixels and sets the colours for above and below the value.

func (Depiction) At

func (i Depiction) At(xp, yp int) color.Color

func (Depiction) Bounds

func (i Depiction) Bounds() image.Rectangle

type Depictor

type Depictor interface {
	Bounds() image.Rectangle
	At(x, y int) color.Color
}

a Depictor is an image.Image without a colormodel, so is more general. embedded in one of the helper wrappers gets you an image.Image. (this and the wrappers might be moved, in a later version of this package, to their own package.)

type Gauss

type Gauss struct {
	Q22 float64 // 2 * q squared
}

a Signal that peaks, centred on zero, as a Gaussian distribution, width q.

type GrayImage

type GrayImage struct {
	Depictor
}

gray depiction wrapper.

func (GrayImage) ColorModel

func (i GrayImage) ColorModel() color.Model

type Heavyside

type Heavyside struct {
}

a Signal that returns +unitY for positive x and zero for negative x.

type Inverted

type Inverted struct {
	Signal
}

a Signal that produces y values that are the negative of another Signals y values

type LimitedSignal

type LimitedSignal interface {
	Signal
	MaxX() x
}

a LimitedSignal is a Signal modified to give property values of zero with parameter values above the values returned by MaxX().

func PromoteToLimitedSignals

func PromoteToLimitedSignals(s interface{}) []LimitedSignal

converts to []LimitedSignal

type Looped

type Looped struct {
	Signal
	Loop x
}

a PeriodicSignal that is a Signal repeated with Loop length x.

func (Looped) Period

func (s Looped) Period() x

type Modulated

type Modulated []Signal

Modulated is a PeriodicLimitedSignal, generated by multiplying together Signal(s).(Signal's can be PeriodicLimitedSignal's, so this can be hierarchical.) Multiplication scales so that, unitY*unitY=unitY. Modulated's MaxX() comes from the smallest contstituent MaxX(), (0 if none of the contained Signals are LimitedSignals.) Modulated's Period() comes from its first member. As with 'AND' logic, all sources have to be unitY (at a particular x) for Modulated to be unitY, whereas, ANY Signal at zero will generate a Modulated of zero.

func NewModulated

func NewModulated(c ...Signal) Modulated

helper to enable generation from another slice. will in general need to use a slice interface promoter function.

func (Modulated) MaxX

func (c Modulated) MaxX() (min x)

the smallest Max X of the constituents.

func (Modulated) Period

func (c Modulated) Period() (period x)

type Noise

type Noise struct {
	rand.Rand
	sync.Mutex
}

Noise is a deterministic random Signal, white noise. it always produces the same y value for the same x value, (for the same Noise) but random otherwise. determinism allows caching even for this type

Example
s := NewNoise()
for t := x(0); t < 40*unitX; t += unitX {
	fmt.Println(s.property(t), strings.Repeat(" ", int(s.property(t)/(unitY/33))+33)+"X")
}
fmt.Println()
/* Output:
 23.94%                                         X
-52.49%                 X
  8.21%                                    X
 -9.87%                               X
-74.46%          X
-68.54%            X
-31.13%                        X
-28.89%                         X
 11.03%                                     X
 43.01%                                                X
-71.97%           X
-35.88%                       X
-58.86%               X
 47.80%                                                 X
 21.68%                                         X
-34.58%                       X
-66.41%             X
 10.38%                                     X
  4.28%                                   X
-14.14%                              X
-17.82%                             X
-31.24%                        X
 22.84%                                         X
-21.90%                           X
 17.72%                                       X
 23.27%                                         X
 38.15%                                              X
 65.67%                                                       X
-72.58%           X
-66.54%             X
-33.93%                       X
  4.60%                                   X
-42.08%                     X
-36.43%                      X
-48.60%                  X
-10.65%                               X
-17.75%                             X
 25.50%                                          X
 23.76%                                         X
-87.69%      X
*/                    X
-87.69%      X
*/
Output:

  23.94%                                         X
 -52.49%                 X
   8.21%                                    X
  -9.87%                               X
 -74.46%          X
 -68.54%            X
 -31.13%                        X
 -28.89%                         X
  11.03%                                     X
  43.01%                                                X
 -71.97%           X
 -35.88%                       X
 -58.86%               X
  47.80%                                                 X
  21.68%                                         X
 -34.58%                       X
 -66.41%             X
  10.38%                                     X
   4.28%                                   X
 -14.14%                              X
 -17.82%                             X
 -31.24%                        X
  22.84%                                         X
 -21.90%                           X
  17.72%                                       X
  23.27%                                         X
  38.15%                                              X
  65.67%                                                       X
 -72.58%           X
 -66.54%             X
 -33.93%                       X
   4.60%                                   X
 -42.08%                     X
 -36.43%                      X
 -48.60%                  X
 -10.65%                               X
 -17.75%                             X
  25.50%                                          X
  23.76%                                         X
 -87.69%      X

func NewNoise

func NewNoise() Noise

type Offset

type Offset struct {
	LimitedSignal
	Offset x
}

a LimitedSignal whose values are moved, in x, by 'Offset'.

func (Offset) MaxX

func (s Offset) MaxX() x

type PCM

type PCM struct {
	Data []byte
	// contains filtered or unexported fields
}

PCM is the common state embedded in all the different precisions of PCM signals, it doesn't itself include encoding information, so cannot return a property and so is not a Signal. PCM Signals return continuous property values that step from one PCM value to the next, Segmented could be used to get interpolated property values.

func NewPCM

func NewPCM(sampleRate uint32, Data []byte) PCM

make a PCM type, from raw bytes.

func (PCM) Period

func (s PCM) Period() x

func (PCM) SaveTo

func (p PCM) SaveTo(pathTo string) error

save the PCM to a given path, which if not ending in a folder with the PCM's Sample Rate as its name, will add it as a sub-folder. This means the file won't then actually simply be at the 'path' address, separate folders for each saved Sample Rate will be generated. using LoadPCM will automatically find it. Also adds extension ".pcm".

func (PCM) Split

func (s PCM) Split(sample uint32, sampleBytes uint8) (head PCM, tail PCM)

from a PCM return two new PCM's (with the same underlying data) from either side of a sample.

type PCM16bit

type PCM16bit struct {
	PCM
}

16 bit PCM Signal

func NewPCM16bit

func NewPCM16bit(sampleRate uint32, Data []byte) PCM16bit

func (PCM16bit) Encode

func (s PCM16bit) Encode(w io.Writer)

func (PCM16bit) MaxX

func (s PCM16bit) MaxX() x

func (PCM16bit) Split

func (s PCM16bit) Split(p x) (PCM16bit, PCM16bit)

type PCM24bit

type PCM24bit struct {
	PCM
}

24 bit PCM Signal

func NewPCM24bit

func NewPCM24bit(sampleRate uint32, Data []byte) PCM24bit

func (PCM24bit) Encode

func (s PCM24bit) Encode(w io.Writer)

func (PCM24bit) MaxX

func (s PCM24bit) MaxX() x

func (PCM24bit) Split

func (s PCM24bit) Split(p x) (PCM24bit, PCM24bit)

type PCM32bit

type PCM32bit struct {
	PCM
}

32 bit PCM Signal

func NewPCM32bit

func NewPCM32bit(sampleRate uint32, Data []byte) PCM32bit

func (PCM32bit) Encode

func (s PCM32bit) Encode(w io.Writer)

func (PCM32bit) MaxX

func (s PCM32bit) MaxX() x

func (PCM32bit) Split

func (s PCM32bit) Split(p x) (PCM32bit, PCM32bit)

type PCM48bit

type PCM48bit struct {
	PCM
}

48 bit PCM Signal

func NewPCM48bit

func NewPCM48bit(sampleRate uint32, Data []byte) PCM48bit

func (PCM48bit) Encode

func (s PCM48bit) Encode(w io.Writer)

func (PCM48bit) MaxX

func (s PCM48bit) MaxX() x

func (PCM48bit) Split

func (s PCM48bit) Split(p x) (PCM48bit, PCM48bit)

type PCM64bit

type PCM64bit struct {
	PCM
}

64 bit PCM Signal

func NewPCM64bit

func NewPCM64bit(sampleRate uint32, Data []byte) PCM64bit

func (PCM64bit) Encode

func (s PCM64bit) Encode(w io.Writer)

func (PCM64bit) MaxX

func (s PCM64bit) MaxX() x

func (PCM64bit) Split

func (s PCM64bit) Split(p x) (PCM64bit, PCM64bit)

type PCM8bit

type PCM8bit struct {
	PCM
}

8 bit PCM Signal.

func NewPCM8bit

func NewPCM8bit(sampleRate uint32, Data []byte) PCM8bit

func (PCM8bit) Encode

func (s PCM8bit) Encode(w io.Writer)

func (PCM8bit) MaxX

func (s PCM8bit) MaxX() x

func (PCM8bit) Split

func (s PCM8bit) Split(p x) (PCM8bit, PCM8bit)

type PeriodicLimitedSignal

type PeriodicLimitedSignal interface {
	Signal
	MaxX() x
	Period() x
}

a PeriodicLimitedSignal is a Signal that repeats over Period() and is zero above MaxX().

func Decode

func Decode(wav io.Reader) ([]PeriodicLimitedSignal, error)

Read a wave format stream into an array of PeriodicLimitedSignals. one for each channel in the encoding.

func NewPCMSignal

func NewPCMSignal(s Signal, length x, sampleRate uint32, sampleBytes uint8) PeriodicLimitedSignal

make a PeriodicLimitedSignal by sampling from a Signal, using provided parameters.

type PeriodicSignal

type PeriodicSignal interface {
	Signal
	Period() x
}

a PeriodicSignal is a Signal that repeats, that is, gives the same value of its property, for parameter values offset by the value returned by Period().

func PromoteToPeriodicSignals

func PromoteToPeriodicSignals(s interface{}) []PeriodicSignal

converts to []PeriodicSignal

type Plan9PalettedImage

type Plan9PalettedImage struct {
	Depictor
}

plan9 paletted, depiction wrapper.

func (Plan9PalettedImage) ColorModel

func (i Plan9PalettedImage) ColorModel() color.Model

type Pulse

type Pulse struct {
	Width x
}

a LimitedSignal that produces unitY for a Width, zero otherwise.

func (Pulse) MaxX

func (s Pulse) MaxX() x

type PulsePattern

type PulsePattern struct {
	BitPattern big.Int
	PulseWidth x
}

pulse train specified by the bits of a big int. littleendian, ignores high zero bits for MaxX().

Example
i := new(big.Int)
_, err := fmt.Sscanf("010111011101110111011101110111", "%b", i)
if err != nil {
	panic(i)
}
s := PulsePattern{*i, unitX}
for t := x(0); t < s.MaxX(); t += s.Period() {
	fmt.Println(s.property(t), strings.Repeat(" ", int(s.property(t)/(unitY/33))+33)+"X")
}
fmt.Println()
/* Output:
100.00%                                                                   X
100.00%                                                                   X
100.00%                                                                   X
  0.00%                                  X
100.00%                                                                   X
100.00%                                                                   X
100.00%                                                                   X
  0.00%                                  X
100.00%                                                                   X
100.00%                                                                   X
100.00%                                                                   X
  0.00%                                  X
100.00%                                                                   X
100.00%                                                                   X
100.00%                                                                   X
  0.00%                                  X
100.00%                                                                   X
100.00%                                                                   X
100.00%                                                                   X
  0.00%                                  X
100.00%                                                                   X
100.00%                                                                   X
100.00%                                                                   X
  0.00%                                  X
100.00%                                                                   X
100.00%                                                                   X
100.00%                                                                   X
  0.00%                                  X
100.00%                                                                   X
*/                         X
*/
Output:

 100.00%                                                                   X
 100.00%                                                                   X
 100.00%                                                                   X
   0.00%                                  X
 100.00%                                                                   X
 100.00%                                                                   X
 100.00%                                                                   X
   0.00%                                  X
 100.00%                                                                   X
 100.00%                                                                   X
 100.00%                                                                   X
   0.00%                                  X
 100.00%                                                                   X
 100.00%                                                                   X
 100.00%                                                                   X
   0.00%                                  X
 100.00%                                                                   X
 100.00%                                                                   X
 100.00%                                                                   X
   0.00%                                  X
 100.00%                                                                   X
 100.00%                                                                   X
 100.00%                                                                   X
   0.00%                                  X
 100.00%                                                                   X
 100.00%                                                                   X
 100.00%                                                                   X
   0.00%                                  X
 100.00%                                                                   X

func (PulsePattern) MaxX

func (s PulsePattern) MaxX() x

func (PulsePattern) Period

func (s PulsePattern) Period() x

type RGBAImage

type RGBAImage struct {
	Depictor
}

RGBA depiction wrapper

func (RGBAImage) ColorModel

func (i RGBAImage) ColorModel() color.Model

type RampDown

type RampDown struct {
	Period x
}

a Signal which ramps from unitY to zero, over a Period width.

type RampUp

type RampUp struct {
	Period x
}

a Signal which ramps from zero to unitY over a Period width.

type RateModulated

type RateModulated struct {
	Signal
	Modulation Signal
	Factor     x
}

a Signal that stretches the x values of another Signal, in proportion to the value of a modulation Signal

func (RateModulated) Period

func (s RateModulated) Period() x

type Reflected

type Reflected struct {
	Signal
}

a Signal that produces values that are flipped over, (Maxy<->zero) of another Signal

type Repeated

type Repeated struct {
	PeriodicSignal
	Cycles float32
}

a PeriodicSignal that is repeating loop of Cycles number of repeats of another PeriodicSignal. if the PeriodicSignal is actually precisely repeating, then an integer value of Cycles, results in no change.

func (Repeated) Period

func (s Repeated) Period() x

type Reversed

type Reversed struct {
	Signal
}

a Signal that returns y's that are for the -ve x of another Signal

type Segmented

type Segmented struct {
	Signal
	Width x
	// contains filtered or unexported fields
}

Segmented is a Signal that is a sequence of equal width segments each with a uniform gradient, that approximate another Signal. Repeated calls within the same segment, are generated from interpolating cached segment end values, so avoiding calls to the embedded Signal. thread safe but threads sampling from different segments will incure a high cost. (in that case just duplicate )

func NewSegmented

func NewSegmented(s Signal, w x) Segmented

func (Segmented) Period

func (s Segmented) Period() x

type Sequenced

type Sequenced []LimitedSignal

Sequenced is a LimitedSignal, generated by appending together LimitedSignal(s).

func NewSequence

func NewSequence(c ...LimitedSignal) Sequenced

func (Sequenced) MaxX

func (c Sequenced) MaxX() (max x)

sum of all MaxX's in slice.

type Shifted

type Shifted struct {
	Signal
	Shift x
}

a Signal whose values are moved, in x, by 'Shift'.

type Sigmoid

type Sigmoid struct {
	Steepness x
}

a Signal that smoothly transitions from 0 to +unitY. with a maximum gradient (first derivative) at x=0, of Steepness.

type Signal

type Signal interface {
	// contains filtered or unexported methods
}

satisfying the Signal interface means a type represents an analogue signal, where property of type y, varies with a parameter of type x.

func LoadGOB

func LoadGOB(pathTo string) (s Signal, err error)

load Gob encoding

func PromoteToSignals

func PromoteToSignals(s interface{}) []Signal

converts to []Signal

type Sinc

type Sinc struct {
	Cycle x
}

a Signal that is a wave 'packet', with fundamental (central) wavelength of Cycle.

type Sine

type Sine struct {
	Cycle x
}

a PeriodicSignal that varies sinusoidally, repeating with Cycle width.

func (Sine) Period

func (s Sine) Period() x

type Square

type Square struct {
	Cycle x
}

a PeriodicSignal that produces equal regions of +unitY then -unitY, repeating with Cycle width.

func (Square) Period

func (s Square) Period() x

type Stacked

type Stacked []Signal

Same as Composite except that Stacked scales down by the number of signals, making it impossible to exceed unitY.

func NewStacked

func NewStacked(c ...Signal) Stacked

helper to enable generation from another slice. will in general need to use a slice interface promoter function.

func (Stacked) MaxX

func (c Stacked) MaxX() (max x)

the largest Max X of the constituents.

func (Stacked) Period

func (c Stacked) Period() (period x)

type Triggered

type Triggered struct {
	Signal
	Trigger    y
	Rising     bool
	Resolution x
	MaxShift   x
	Found      *searchInfo // by being a pointer this is mutable in methods, without needing a pointer receiver.
}

Triggered shifts a Signal's x so the Signal crosses a trigger y at zero x. it searches with a Resolution, from Shift+Resolution to MaxShift, then from 0 to Shift. Shift can be set initially, then is set to the last found trigger, so subsequent uses find new crossings, and wraps round. Rising can be alternated to find either way crossing

func NewTriggered

func NewTriggered(s Signal, trigger y, rising bool, res, max x) Triggered

type Wave

type Wave struct {
	Offset
	URL string
	// contains filtered or unexported fields
}

an offset PCM Signal, (so single channel) that streams values from a URL source as required. Supported URL schemes, "file:", "data:", "http(s):". Encodings for Http(s); MIME: "audio/l?;rate=?","sound/wav"(mono),"audio/x-wav" (mono) Encoding for File: ".wav"(mono),".pcm",".gob" Encodings for Data: MIME: "base64" or none. (and MIME as for Http.) Buffers at least 32 samples, but if queried for a property value that needs a sample prior to that, might return zero. ( really only used for filtering/smoothing)

func NewWave

func NewWave(URL string) (*Wave, error)

type WebSafePalettedImage

type WebSafePalettedImage struct {
	Depictor
}

WebSafe paletted, depiction wrapper.

func (WebSafePalettedImage) ColorModel

func (i WebSafePalettedImage) ColorModel() color.Model

Directories

Path Synopsis
DTMFplayer
pipe command for converting characters into DTMF tone PCM data.
pipe command for converting characters into DTMF tone PCM data.
GobPlayer
to specifiy sample precision: ./player\[SYSV64\].elf -bytes=1 < 1kSine.gob | aplay (bytes can be one of: 1,2,3,4.)
to specifiy sample precision: ./player\[SYSV64\].elf -bytes=1 < 1kSine.gob | aplay (bytes can be one of: 1,2,3,4.)
StereoToMono
convert a stereo wav file into a mono by adding sounds together.
convert a stereo wav file into a mono by adding sounds together.
player
play (needed aplay) telephone ringing tone, one cycle.
play (needed aplay) telephone ringing tone, one cycle.
stereotojpeg
make a jpeg image from a stereo wav file.
make a jpeg image from a stereo wav file.
telephones
generate a few standard telephone notification tones into wav and GOB files.
generate a few standard telephone notification tones into wav and GOB files.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL