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 ¶
- func DB(vol float64) float64
- func Encode(w io.Writer, sampleBytes uint8, sampleRate uint32, length x, ss ...Signal) (err error)
- func EncodeLike(w io.Writer, s PeriodicSignal, p LimitedSignal)
- func LoadPCM(pathTo string, p *PCM) (err error)
- func MultiplyX(m interface{}, d x) x
- func MultiplyY(m interface{}, d y) y
- func ReadGOB(p io.Reader, s *Signal) error
- func SaveGOB(pathTo string, s Signal) error
- func SavePCM(path string, pcm PCM) error
- func Vol(DB float64) float64
- func WriteGOB(p io.Writer, s Signal) error
- func X(d interface{}) x
- func Y(d interface{}) y
- type ADSREnvelope
- type Cached
- type Composite
- type Compressed
- type Constant
- type Depiction
- type Depictor
- type Gauss
- type GrayImage
- type Heavyside
- type Inverted
- type LimitedSignal
- type Looped
- type Modulated
- type Noise
- type Offset
- type PCM
- type PCM16bit
- type PCM24bit
- type PCM32bit
- type PCM48bit
- type PCM64bit
- type PCM8bit
- type PeriodicLimitedSignal
- type PeriodicSignal
- type Plan9PalettedImage
- type Pulse
- type PulsePattern
- type RGBAImage
- type RampDown
- type RampUp
- type RateModulated
- type Reflected
- type Repeated
- type Reversed
- type Segmented
- type Sequenced
- type Shifted
- type Sigmoid
- type Signal
- type Sinc
- type Sine
- type Square
- type Stacked
- type Triggered
- type Wave
- type WebSafePalettedImage
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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".
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 */
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 ¶
helper to enable generation from another slice. will in general need to use a slice interface promoter function.
type Compressed ¶
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 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.
type Depictor ¶
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 ¶
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.
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 ¶
helper to enable generation from another slice. will in general need to use a slice interface promoter function.
type Noise ¶
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 */
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
type Offset ¶
type Offset struct { LimitedSignal Offset x }
a LimitedSignal whose values are moved, in x, by 'Offset'.
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 (PCM) SaveTo ¶
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".
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.
type PulsePattern ¶
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 */
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 ¶
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 ¶
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.
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 ¶
type Sequenced ¶
type Sequenced []LimitedSignal
Sequenced is a LimitedSignal, generated by appending together LimitedSignal(s).
func NewSequence ¶
func NewSequence(c ...LimitedSignal) Sequenced
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.
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.
type Square ¶
type Square struct {
Cycle x
}
a PeriodicSignal that produces equal regions of +unitY then -unitY, repeating with Cycle width.
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 ¶
helper to enable generation from another slice. will in general need to use a slice interface promoter function.
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 ¶
type Wave ¶
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)
type WebSafePalettedImage ¶
type WebSafePalettedImage struct {
Depictor
}
WebSafe paletted, depiction wrapper.
func (WebSafePalettedImage) ColorModel ¶
func (i WebSafePalettedImage) ColorModel() color.Model
Source Files ¶
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. |