freq

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: BSD-3-Clause Imports: 4 Imported by: 5

Documentation

Overview

Package freq gives frequency types and operations.

Package freq supports various scale related representations, including intervals and Mels.

Index

Constants

View Source
const (
	Octave   = I(2)
	Semitone = I(1.059463094359)
	Cent     = I(1.000577789507)
)
View Source
const (
	NanoHertz  T = 1
	MicroHertz   = 1000 * NanoHertz
	MilliHertz   = 1000 * MicroHertz
	Hertz        = 1000 * MilliHertz
	KiloHertz    = 1000 * Hertz
	MegaHertz    = 1000 * KiloHertz
	GigaHertz    = 1000 * MegaHertz
)

Different levels of "ouch".

Variables

This section is empty.

Functions

This section is empty.

Types

type I

type I float64

Type I represents a frequency interval.

func Diff

func Diff(ref, off T) I

Diff gives the (signed) interval from ref to off.

func Temper

func Temper(n int) I

Temper gives an I for octaves divided eually into n components.

func (I) Cents

func (i I) Cents() int

func (I) From

func (i I) From(f T) T

From applies the interval i to f returning the result.

func (I) N

func (i I) N(n int) I

N returns the interval n times larger than i.

func (I) NFrom

func (i I) NFrom(f T, n int) T

NFrom applies the interval i to f n times returning the result.

func (I) Octaves

func (i I) Octaves() int

func (I) Semitones

func (i I) Semitones() int

func (I) String

func (i I) String() string

func (I) Within

func (i I) Within(a, b T) bool

Within returns whether or not the frequencies a,b are withing i of each other.

type Mel

type Mel int64

Mel is a unit of frequency in which a difference less than MelAudible is generally imperceivable (melodically). See https://en.wikipedia.org/wiki/Mel_scale

const MelAudible Mel = Mel(1000000000)

MelAudible is the smallest difference in frequency in Mels which is melodically audible. Smaller harmonic differences are audible due to beating.

func ToMel

func ToMel(f T) Mel

ToMel gives f in Mels.

func (Mel) Freq

func (m Mel) Freq() T

Freq gives m as frequency.

func (Mel) String

func (m Mel) String() string

String returns a string representation of m.

type T

type T int64

T represents a frequency.

func FromMel

func FromMel(m Mel) T

FromMel gives m as frequency.

func FromPeriod

func FromPeriod(p time.Duration) T

FromPeriod gives the frequency whose period is p.

func (T) Cycles

func (f T) Cycles(d time.Duration) (int, time.Duration)

Cycles gives the number of times a signal at frequency f cycles during d time and a remainder duration.

For example if f = 3 Hz and t=.5sec then f.Cycles() returns (1, .5sec - .33333 sec).

func (T) Float64

func (f T) Float64() float64

Float64 give f in Hertz.

func (T) FreqOf

func (s T) FreqOf(rps float64) T

FreqOf gives the frequency f' such that f' has r radians per sample at sample freq f.

func (T) FromSamplesPerCycle

func (f T) FromSamplesPerCycle(spc float64) T

FromSamplesPerCycle returns the frequency g which has

f.SamplesCyclesPerCycle(g) ~= spc

where "~=" accounts for floating point rounding to the smallest frequency quantum (NanoHertz).

func (T) MarshalJSON

func (f T) MarshalJSON() ([]byte, error)

func (T) Period

func (f T) Period() time.Duration

Period gives the period of time of 1 cycle at frequency f.

func (T) Phase

func (f T) Phase(d time.Duration) float64

Phase gives the offet or phase in radians at time d, assuming a signal at frequency f starts at 0.

func (T) RadsPer

func (f T) RadsPer(g T) float64

RadsPer gives the radians per sample of g at sampling frequency f.

func (T) RadsPerAt

func (f T) RadsPerAt(s T) float64

RadsPerAt gives the radians per sample of a signal at frequency f sampled at frequency r.

func (T) SamplesPerCycle

func (f T) SamplesPerCycle(g T) float64

SamplesPerCycle returns the number of samples, as a float, at sample rate f which constitute one cycle of the frequency g.

func (T) String

func (f T) String() string

String implements Stringer.

func (*T) UnmarshalJSON

func (f *T) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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