jlsampler

package module
v0.0.0-...-8aef797 Latest Latest
Warning

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

Go to latest
Published: May 17, 2014 License: GPL-2.0 Imports: 18 Imported by: 0

README

JLSampler

See http://www.johnnylee.org/jlsampler for details.

A sampler for real-time use written in go. JLSampler uses alsa's midi sequencer API for capturing midi events, and uses jack for output.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InterpLinear16

func InterpLinear16(y1, y2, mu float64) int16

See http://paulbourke.net/miscellaneous/interpolation/. Using nearest neighbor instead of linear interpolation sounds aweful. After trying several interpolation methods, inclusing cubic, cosine, and hermite polynomials, I've found linear interpolation to sound the best for the small rate changes we're making.

Of course it's always possible that I had an error somewhere.

func Println

func Println(a ...interface{})

----------------------------------------------------------------------------

func RunApp

func RunApp()

Types

type Config

type Config struct {
	MidiIn string // Controller midi port (keyboard).
}

func LoadConfig

func LoadConfig() (*Config, error)

type Controls

type Controls struct {
	NFadeIn float32 // Fade-in length in samples. Computed from TauFadeIn.

	Transpose    int8 // Added to midi note on input.
	PitchBendMax int8 // Maximum pitch bend in semitones.
	RRBorrow     int8 // Distance to borrow round-robbin samples.

	Tau       float64 // Key-up decay time constant.
	TauCut    float64 // Key-repeat or cut decay time constant.
	TauFadeIn float64 // Sample fade in time.

	Amp        float64 // Amplification multiplier.
	CropThresh float64 // Cut beginning of samples below this threshold.
	RmsTime    float64 // Time period to use to compute sample RMS.
	RmsLow     float64 // RMS for key 21 (Low A).
	RmsHigh    float64 // RMS for key 108 (High C).
	PanLow     float64 // Panning for key 21. -1 is left, 1 is right.
	PanHigh    float64 // Panning for key 108.
	GammaAmp   float64 // Amplitude scaling x^gamma.
	GammaLayer float64 // Layer scaling.
	VelMult    float64 // Velocity multiplier.

	MixLayers   bool // It True, mix layers together.
	FakeLayerRC bool // Use RC filter to construct fake zero-layer.
	Sustain     bool // Sustain pedal value (0-1).
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------

func NewControls

func NewControls(sampler *Sampler) *Controls

func (*Controls) CalcAmp

func (c *Controls) CalcAmp(key int, velocity, rms float64) float32

func (*Controls) CalcPan

func (c *Controls) CalcPan(key int) float32

func (*Controls) LoadDefaults

func (c *Controls) LoadDefaults()

func (*Controls) LoadFrom

func (c *Controls) LoadFrom(path string) error

func (*Controls) LoadMidiConfig

func (c *Controls) LoadMidiConfig() error

func (*Controls) Print

func (c *Controls) Print()

func (*Controls) ProcessCommand

func (c *Controls) ProcessCommand(cmd string)

func (*Controls) ProcessMidi

func (c *Controls) ProcessMidi(num int32, value float64)

func (*Controls) Run

func (c *Controls) Run()

func (*Controls) UpdateAmp

func (c *Controls) UpdateAmp(x float64)

func (*Controls) UpdateCropThresh

func (c *Controls) UpdateCropThresh(x float64)

func (*Controls) UpdateGammaAmp

func (c *Controls) UpdateGammaAmp(x float64)

func (*Controls) UpdateGammaLayer

func (c *Controls) UpdateGammaLayer(x float64)

func (*Controls) UpdateMixLayers

func (c *Controls) UpdateMixLayers(x float64)

func (*Controls) UpdatePanHigh

func (c *Controls) UpdatePanHigh(x float64)

func (*Controls) UpdatePanLow

func (c *Controls) UpdatePanLow(x float64)

func (*Controls) UpdatePitchBendMax

func (c *Controls) UpdatePitchBendMax(x float64)

func (*Controls) UpdateRmsHigh

func (c *Controls) UpdateRmsHigh(x float64)

func (*Controls) UpdateRmsLow

func (c *Controls) UpdateRmsLow(x float64)

func (*Controls) UpdateRmsTime

func (c *Controls) UpdateRmsTime(x float64)

func (*Controls) UpdateSustain

func (c *Controls) UpdateSustain(x float64)

func (*Controls) UpdateTau

func (c *Controls) UpdateTau(x float64)

func (*Controls) UpdateTauCut

func (c *Controls) UpdateTauCut(x float64)

func (*Controls) UpdateTauFadeIn

func (c *Controls) UpdateTauFadeIn(x float64)

func (*Controls) UpdateTranspose

func (c *Controls) UpdateTranspose(x float64)

---------------------------------------------------------------------------- Update functions, one for each control.

func (*Controls) UpdateVelMult

func (c *Controls) UpdateVelMult(x float64)

type KeySampler

type KeySampler struct {
	Key int // The midi key number.
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------

func NewKeySampler

func NewKeySampler(controls *Controls, key int) *KeySampler

func (*KeySampler) AddLayer

func (ks *KeySampler) AddLayer()

func (*KeySampler) AddSample

func (ks *KeySampler) AddSample(sample *Sample, layer int)

func (*KeySampler) BorrowFrom

func (ks *KeySampler) BorrowFrom(ks2 *KeySampler) error

func (*KeySampler) Copy

func (ks *KeySampler) Copy() *KeySampler

func (*KeySampler) HasData

func (ks *KeySampler) HasData() bool

func (*KeySampler) NoteOff

func (ks *KeySampler) NoteOff()

func (*KeySampler) NoteOn

func (ks *KeySampler) NoteOn(velocity float64)

func (*KeySampler) NumLayers

func (ks *KeySampler) NumLayers() int

func (*KeySampler) Transpose

func (ks *KeySampler) Transpose(trans int) *KeySampler

func (*KeySampler) UpdateCropThresh

func (ks *KeySampler) UpdateCropThresh(thresh float64)

func (*KeySampler) UpdateRms

func (ks *KeySampler) UpdateRms(rmsTime float64)

func (*KeySampler) WriteOutput

func (ks *KeySampler) WriteOutput(buf *Sound, amp, di []float32)

type MidiListener

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

----------------------------------------------------------------------------

func NewMidiListener

func NewMidiListener(
	sampler *Sampler, name, midiIn string) (*MidiListener, error)

NewMidiListener * name : The name of the device. * midiPort : An incoming midi port to connect to.

func (*MidiListener) Run

func (ml *MidiListener) Run()

Run * Read incoming midi events and send them to the sampler.

type PlayingSample

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

----------------------------------------------------------------------------

func NewPlayingSample

func NewPlayingSample(
	controls *Controls,
	sample1, sample2 *Sample,
	amp1, amp2, pan, mix float32) *PlayingSample

NewPlayingSample: If not mixing layers, then mix should be 0, and amp2 is ignored.

func (*PlayingSample) WriteOutput

func (ps *PlayingSample) WriteOutput(buf *Sound, amp, di []float32) bool

type Sample

type Sample struct {
	Rms  float64 // The RMS value of the initial samples.
	Idx0 int     // Zero index.
	Len  int     // Number of samples in each channel.
	L    []int16 // Left channel samples.
	R    []int16 // Right channel samples.
}

----------------------------------------------------------------------------

func LoadFlac

func LoadFlac(path string) (*Sample, error)

----------------------------------------------------------------------------

func NewSample

func NewSample(size int) *Sample

func NewSampleFromArrays

func NewSampleFromArrays(L, R []int16) *Sample

func (*Sample) FakeLayerRC

func (s *Sample) FakeLayerRC() *Sample

func (*Sample) Interp

func (s *Sample) Interp(idx float32) (float32, float32)

Return interpolated L and R samples for the given index. Samples are scaled to 1.0 max.

func (*Sample) Stretched

func (s *Sample) Stretched(semitones float64) *Sample

func (*Sample) UpdateCropThresh

func (s *Sample) UpdateCropThresh(thresh float64)

func (*Sample) UpdateRms

func (s *Sample) UpdateRms(rmsTime float64)

type SampleLayer

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

----------------------------------------------------------------------------

func (*SampleLayer) AddSample

func (sl *SampleLayer) AddSample(sample *Sample)

func (*SampleLayer) BorrowFrom

func (sl *SampleLayer) BorrowFrom(sl2 *SampleLayer, semitones int)

func (*SampleLayer) Copy

func (sl *SampleLayer) Copy() *SampleLayer

func (*SampleLayer) GetSample

func (sl *SampleLayer) GetSample(idx int) (int, *Sample)

GetSample: Get a sample from the layer. If idx is -1, then get the next round-robbin sample. Otherwise return the indicated sample. Return: The sample and the sample's index.

func (*SampleLayer) NumSamples

func (sl *SampleLayer) NumSamples() int

func (*SampleLayer) Transpose

func (sl *SampleLayer) Transpose(trans int) *SampleLayer

func (*SampleLayer) UpdateCropThresh

func (sl *SampleLayer) UpdateCropThresh(thresh float64)

func (*SampleLayer) UpdateRms

func (sl *SampleLayer) UpdateRms(rmsTime float64)

type Sampler

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

func NewSampler

func NewSampler(name, path string) (*Sampler, error)

func (*Sampler) ControllerEvent

func (s *Sampler) ControllerEvent(control int32, value float64)

func (*Sampler) JackProcess

func (s *Sampler) JackProcess(bufIn, bufOut [][]float32) error

Jack processing callback.

func (*Sampler) NoteOffEvent

func (s *Sampler) NoteOffEvent(note int8, value float64)

func (*Sampler) NoteOnEvent

func (s *Sampler) NoteOnEvent(note int8, value float64)

---------------------------------------------------------------------------- Functions below protected by mutex.

func (*Sampler) PitchBendEvent

func (s *Sampler) PitchBendEvent(value float64)

func (*Sampler) Run

func (s *Sampler) Run()

func (*Sampler) UpdateCropThresh

func (s *Sampler) UpdateCropThresh()

---------------------------------------------------------------------------- These functions run slowly and could cause skipping.

func (*Sampler) UpdateRms

func (s *Sampler) UpdateRms()

type Sound

type Sound struct {
	Len int       // The length of the sound.
	L   []float32 // Left channel.
	R   []float32 // Right channel.
}

----------------------------------------------------------------------------

func NewSound

func NewSound(size int) *Sound

func NewSoundFromSample

func NewSoundFromSample(samp *Sample) *Sound

func (*Sound) Zero

func (s *Sound) Zero()

type TuningFile

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

func LoadTuningFile

func LoadTuningFile() *TuningFile

func (*TuningFile) GetTuning

func (tf *TuningFile) GetTuning(filename string) float64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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