Documentation ¶
Index ¶
- func ConvertSampleRate(segment *Segment, want uint64) ([]float32, error)
- func FakeReadSeeker(initial []byte) fileBuffer
- func GetFormatString(format AudioFormat) string
- type AudioFormat
- type Segment
- func Empty(sampleRate uint64, channels uint) *Segment
- func LoadAudio(reader io.Reader, format AudioFormat) (*Segment, error)
- func LoadAudioFromPath(path string, format AudioFormat) (*Segment, error)
- func SegmentFromData(data []float32, channels int, sampleRate uint64) *Segment
- func Silent(seconds float64, sampleRate uint64, channels uint) *Segment
- func (segment *Segment) ApplyNote(key int)
- func (segment *Segment) CalcBPM(minBpm float64, maxBpm float64, steps float64, samplesPerBeat uint64) float64
- func (segment *Segment) Clone() *Segment
- func (segment *Segment) ConcatenateAt(segment2 *Segment, index uint64) error
- func (segment *Segment) ConcatenateAtSecond(segment2 *Segment, second float64)
- func (segment *Segment) ConcatenateEnd(segment2 *Segment) error
- func (segment *Segment) ConcatenateStart(segment2 *Segment) error
- func (segment *Segment) ConvertChannels(channels int)
- func (segment *Segment) DetectSilence(threshold float32) (float64, float64)
- func (segment *Segment) DetectSilenceEnd(threshold float32) float64
- func (segment *Segment) DetectSilenceStart(threshold float32) float64
- func (segment *Segment) EchoEffect(delay float64, layers int)
- func (segment *Segment) Export(writer io.Writer, format AudioFormat) error
- func (segment *Segment) Fade(start float64, end float64)
- func (segment *Segment) FadeIn(seconds float64)
- func (segment *Segment) FadeOut(seconds float64)
- func (segment *Segment) GetIndexAtTime(time float64) uint64
- func (segment *Segment) GetMaxAbsValue() float32
- func (segment *Segment) InvertPhase()
- func (segment *Segment) Normalize()
- func (segment *Segment) Overlay(segment2 *Segment, start float64) error
- func (segment *Segment) RemoveEndSilence(threshold float32)
- func (segment *Segment) RemoveStartAndEndSilence(threshold float32)
- func (segment *Segment) RemoveStartSilence(threshold float32)
- func (segment *Segment) Repeat(amount uint) error
- func (segment *Segment) Reverse()
- func (segment *Segment) SamplesToSeconds(index uint64) float64
- func (segment *Segment) SetSpeed(speed float64)
- func (segment *Segment) Slice(start float64, end float64) *Segment
- func (segment *Segment) SlowDown(speed float64)
- func (segment *Segment) SpeedUp(speed float64)
- func (segment *Segment) Trim(start float64, end float64)
- func (segment *Segment) TrimEnd(seconds float64)
- func (segment *Segment) TrimStart(seconds float64)
- func (segment *Segment) UpdateLength()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertSampleRate ¶
Convert the sample rate of the segment.
func FakeReadSeeker ¶
func FakeReadSeeker(initial []byte) fileBuffer
Creates new buffer that implements io.ReadWriteSeeker.
func GetFormatString ¶
func GetFormatString(format AudioFormat) string
Types ¶
type AudioFormat ¶
type AudioFormat int
const ( FormatFLAC AudioFormat = 1 // .flac FormatWAVE AudioFormat = 2 // .wav FormatMP3 AudioFormat = 3 // .mp3 FormatRAW AudioFormat = 4 // Custom format // Tracker formats FormatMOD AudioFormat = 5 // ProTracker .mod, rendered with gomodplay. This is faster than gotracker, but less accurate. FormatGotrackerMod AudioFormat = 6 // ProTracker .mod, rendered with Gotracker. This is slower than gomodplay, but more accurate. FormatS3M AudioFormat = 7 // ScreamTracker III .s3m, rendered with Gotracker FormatXM AudioFormat = 8 // FastTracker II .xm, rendered with Gotracker FormatIT AudioFormat = 9 // ImpulseTracker .it, rendered with Gotracker )
type Segment ¶
type Segment struct { Data []float32 Channels int // Amount of channels (will be 2, even if there is one) SampleRate uint64 // The sample rate of the segment Length uint64 // Length of the segment in samples LengthSeconds float64 // Length of the segment in seconds Format AudioFormat }
func LoadAudio ¶
func LoadAudio(reader io.Reader, format AudioFormat) (*Segment, error)
Loads an audio file from a reader.
func LoadAudioFromPath ¶
func LoadAudioFromPath(path string, format AudioFormat) (*Segment, error)
Loads an audio file from the file path.
func SegmentFromData ¶
Converts a float32 array to a Segment. Structure of the audio array values (assume you have 2 channels): [channel 1 val, channel 2 val, channel 1 val, channel 2 val, ...]
func (*Segment) ApplyNote ¶
Pitches audio down to the note. Pitch formula: 2 ** (key / 12). This will change the sample rate.
func (*Segment) CalcBPM ¶
func (segment *Segment) CalcBPM(minBpm float64, maxBpm float64, steps float64, samplesPerBeat uint64) float64
Calculates the BPM of this segment. Warning: this is very slow (and inaccurate), and even slower for bigger segments. Use a smaller slice of a segment instead of the entire thing to get faster results. minBpm: the minimum BPM you expect (120) maxBpm: the maximum BPM you expect (200) steps: the amount of steps per interval (1024) samplesPerBeat: the amount of samples used for a single beat (1024) Returns the calculated BPM value
func (*Segment) ConcatenateAt ¶
Concatenate a segment at a specified index
func (*Segment) ConcatenateAtSecond ¶
func (*Segment) ConcatenateEnd ¶
Concatenate a segment at the end
func (*Segment) ConcatenateStart ¶
Concatenate a segment at the start
func (*Segment) ConvertChannels ¶
func (*Segment) DetectSilence ¶
Detect silence (volume <= threshold) in audio. Returns the amount of silence from the start and the end (in seconds). Volume ranges from 0 to 1.
func (*Segment) DetectSilenceEnd ¶
Detect trailing silence (volume <= threshold) in seconds
func (*Segment) DetectSilenceStart ¶
Detect starting silence (volume <= threshold) in audio in seconds
func (*Segment) EchoEffect ¶
Applies an echo effect on the segment. delay: delay between echo layers (0.05) layers: amount of layer (2)
func (*Segment) Fade ¶
Fade in/out effect. start float64: the amount of fade-in seconds end float64: the amount of fade-out seconds
func (*Segment) GetIndexAtTime ¶
Returns the index of the specified second in segment.Data If the index is bigger than the segment length, returns the last index.
func (*Segment) GetMaxAbsValue ¶
Get the maximum (absolute) value of the segment.
func (*Segment) InvertPhase ¶
func (segment *Segment) InvertPhase()
Inverts the phase of this segment
func (*Segment) Normalize ¶
func (segment *Segment) Normalize()
Normalizes audio values of this segment from -1.0 to 1.0.
func (*Segment) Overlay ¶
Overlay one segment on top of another. segment2 *gaudio.Segment: The segment you want to overlay. start float64: The second you want to overlay the segment at. This will automatically normalize the audio to avoid clipping. If the length of the overlayed segment is bigger, the second second will be cropped to the size of the target segment.
func (*Segment) RemoveEndSilence ¶
Removes the trailing silence (volume <= threshold) from the segment
func (*Segment) RemoveStartAndEndSilence ¶
Removes all silence (volume <= threshold) from the segment
func (*Segment) RemoveStartSilence ¶
Removes the starting silence (volume <= threshold) from the segment
func (*Segment) SamplesToSeconds ¶
func (*Segment) Slice ¶
Takes a slice out of this segment, and returns a new segment. start: the start of the slice in seconds end: the end of the slice in seconds
func (*Segment) SpeedUp ¶
Speeds up the segment by n times without changing the sample rate. Currently this rounds up speeds to integers (read fixme).
func (*Segment) UpdateLength ¶
func (segment *Segment) UpdateLength()
Updates .Length and .LengthSeconds of the segment. Call after modifying the length of segment.Data.