Skip to content

Commit

Permalink
Merge pull request #159 from oakmound/release/3.0.0-2-perf
Browse files Browse the repository at this point in the history
Release/3.0.0 Beta 1
  • Loading branch information
200sc committed Jul 6, 2021
2 parents 4933876 + 7a67301 commit a950e70
Show file tree
Hide file tree
Showing 277 changed files with 7,968 additions and 3,489 deletions.
1 change: 0 additions & 1 deletion alg/floatgeom/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ func (p Point3) ToRect(span float64) Rect3 {

// ProjectX projects the Point3 onto the x axis, removing it's
// x component and returning a Point2
// todo: I'm not sure about this (these) function name
func (p Point3) ProjectX() Point2 {
return Point2{p[1], p[2]}
}
Expand Down
1 change: 0 additions & 1 deletion alg/floatgeom/point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ func TestPointAccess(t *testing.T) {
// Pattern here: there's a set of input pairs here
// each test takes these and has expected outputs for each pair index.
var (
// Todo: add more test cases
pt3cases = []struct{ x1, y1, z1, x2, y2, z2 float64 }{
{0, 0, 0, 1, 1, 1},
}
Expand Down
1 change: 0 additions & 1 deletion alg/intgeom/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func (p Point3) ToRect(span int) Rect3 {

// ProjectX projects the Point3 onto the x axis, removing it's
// x component and returning a Point2
// todo: I'm not sure about this (these) function name
func (p Point3) ProjectX() Point2 {
return Point2{p[1], p[2]}
}
Expand Down
1 change: 0 additions & 1 deletion alg/intgeom/point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ func TestPointAccess(t *testing.T) {
// Pattern here: there's a set of input pairs here
// each test takes these and has expected outputs for each pair index.
var (
// Todo: add more test cases
pt3cases = []struct{ x1, y1, z1, x2, y2, z2 int }{
{0, 0, 0, 1, 1, 1},
}
Expand Down
20 changes: 10 additions & 10 deletions audio/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package audio
import (
"fmt"

"github.com/200sc/klangsynthese/audio"
"github.com/200sc/klangsynthese/font"
"github.com/oakmound/oak/v3/audio/font"
"github.com/oakmound/oak/v3/audio/klang"
"github.com/oakmound/oak/v3/oakerr"
)

// Audio is a struct of some audio data and the variables
// required to filter it through a sound font.
type Audio struct {
*font.Audio
toStop audio.Audio
toStop klang.Audio
X, Y *float64
setVolume int32
}
Expand Down Expand Up @@ -76,22 +76,22 @@ func (a *Audio) Stop() error {
}

// Copy returns a copy of the audio
func (a *Audio) Copy() (audio.Audio, error) {
func (a *Audio) Copy() (klang.Audio, error) {
a2, err := a.Audio.Copy()
if err != nil {
return nil, err
}
return New(a.Audio.Font, a2.(audio.FullAudio), a.X, a.Y), nil
return New(a.Audio.Font, a2.(klang.FullAudio), a.X, a.Y), nil
}

// MustCopy acts like Copy, but panics on an error.
func (a *Audio) MustCopy() audio.Audio {
return New(a.Audio.Font, a.Audio.MustCopy().(audio.FullAudio), a.X, a.Y)
func (a *Audio) MustCopy() klang.Audio {
return New(a.Audio.Font, a.Audio.MustCopy().(klang.FullAudio), a.X, a.Y)
}

// Filter returns the audio with some set of filters applied to it.
func (a *Audio) Filter(fs ...audio.Filter) (audio.Audio, error) {
var ad audio.Audio = a
func (a *Audio) Filter(fs ...klang.Filter) (klang.Audio, error) {
var ad klang.Audio = a
var err, consErr error
for _, f := range fs {
ad, err = f.Apply(ad)
Expand All @@ -107,7 +107,7 @@ func (a *Audio) Filter(fs ...audio.Filter) (audio.Audio, error) {
}

// MustFilter acts like Filter but ignores errors.
func (a *Audio) MustFilter(fs ...audio.Filter) audio.Audio {
func (a *Audio) MustFilter(fs ...klang.Filter) klang.Audio {
ad, _ := a.Filter(fs...)
return ad
}
Expand Down
13 changes: 11 additions & 2 deletions audio/audio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"
"time"

"github.com/200sc/klangsynthese/audio/filter"
"github.com/200sc/klangsynthese/synth"
"github.com/oakmound/oak/v3/audio/klang/filter"
"github.com/oakmound/oak/v3/audio/synth"
)

func TestAudioFuncs(t *testing.T) {
Expand All @@ -14,6 +14,10 @@ func TestAudioFuncs(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
a := New(DefaultFont, kla.(Data))
err = a.SetVolume(0)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
err = <-a.Play()
if err != nil {
t.Fatalf("unexpected error: %v", err)
Expand Down Expand Up @@ -54,4 +58,9 @@ func TestAudioFuncs(t *testing.T) {
a.Play()
time.Sleep(a.PlayLength())
// Assert yet quieter audio is playing
a.SetVolume(-2000)
a.Play()
time.Sleep(a.PlayLength())
// Assert yet quieter audio is playing

}
54 changes: 0 additions & 54 deletions audio/channelManager.go

This file was deleted.

34 changes: 0 additions & 34 deletions audio/channel_test.go

This file was deleted.

112 changes: 0 additions & 112 deletions audio/channels.go

This file was deleted.

5 changes: 0 additions & 5 deletions audio/ears.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package audio

import (
"github.com/oakmound/oak/v3/dlog"
"github.com/oakmound/oak/v3/physics"
)

Expand Down Expand Up @@ -58,15 +57,11 @@ func (e *Ears) CalculateVolume(v physics.Vector) float64 {
v2 := physics.NewVector(*e.X, *e.Y)
dist := v2.Distance(v)

dlog.Verb("Vector Distance:", dist, v, v2)

// Ignore scaling variable
lin := (e.SilenceRadius - dist) / e.SilenceRadius
if lin < 0 {
lin = 0
}

dlog.Verb("Silence scale", lin, e.SilenceRadius, dist)

return lin
}
46 changes: 46 additions & 0 deletions audio/flac/flac.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Package flac provides functionality to handle .flac files and .flac encoded data
package flac

import (
"fmt"
"io"

"github.com/eaburns/flac"
audio "github.com/oakmound/oak/v3/audio/klang"
)

// def flac format
var format = audio.Format{
SampleRate: 44100,
Bits: 16,
Channels: 2,
}

// Load loads flac data from the incoming reader as an audio
func Load(r io.Reader) (audio.Audio, error) {
data, meta, err := flac.Decode(r)
if err != nil {
return nil, fmt.Errorf("failed to load flac: %w", err)
}

fformat := audio.Format{
SampleRate: uint32(meta.SampleRate),
Channels: uint16(meta.NChannels),
Bits: uint16(meta.BitsPerSample),
}
return audio.EncodeBytes(
audio.Encoding{
Data: data,
Format: fformat,
})
}

// Save will eventually save an audio encoded as flac to the given writer
func Save(r io.ReadWriter, a audio.Audio) error {
return fmt.Errorf("unsupported Functionality")
}

// Format returns the default flac formatting
func Format() audio.Format {
return format
}
Binary file added audio/flac/testdata/test.flac
Binary file not shown.
Binary file added audio/flac/testdata/test2.flac
Binary file not shown.

0 comments on commit a950e70

Please sign in to comment.