Skip to content

Commit 1554536

Browse files
committed
actually making it work, adding more customization
1 parent 3fcac45 commit 1554536

File tree

9 files changed

+285
-155
lines changed

9 files changed

+285
-155
lines changed

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
# beepFade
22
Adds a new fading effect for the Golang Beep library
33
## How to use
4-
### Fading streamer
5-
```go
6-
// Create the set of parameters for it's stream function
7-
// TimeSpan is how many samples to fade-in for, and then how many samples before the end to fade out for. It is set to 9 seconds here.
8-
// audioLength is how long the audio it is playing is, which is necessary for fading out properly
9-
// id should be a unique number so that it can stream while keeping some variable persistent.
10-
var faderStream = &fader{Streamer: s, Volume: 1, TimeSpan: float64(format.SampleRate.N(time.Second * 9)), audioLength: float64(s.Len()), id: id}
11-
// Create streamer with fading applied
12-
changedStreamer := beep.StreamerFunc(faderStream.Stream)
13-
```
144
### Crossfade between songs
155
```go
16-
// You can use this high level function to crossfade between streams
17-
streamer := crossfadeStream(stream1, stream2)
6+
// CrossfadeStream crossfades between all songs specified in files
7+
// The sample-rates between the two streams must be the same, otherwise weird things might happen
8+
// If opts is nil, then reasonable defaults are used
9+
streamer := beepFade.CrossfadeStream(format, nil, stream1, stream2)
1810
// This streamer will fade into stream1, and then crossfade between stream1 and stream2, and then fade out of stream2
1911
```
12+
A full example can be found in the example folder

example/go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module gitlab.com/256/beepFadeTest
2+
3+
go 1.12
4+
5+
require (
6+
github.com/Programmerino/beepFade v0.0.0-20180218012637-3fcac458b4e8
7+
github.com/faiface/beep v1.0.1
8+
)
9+
10+
replace github.com/Programmerino/beepFade => ../

example/go.sum

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
github.com/Programmerino/beepFade v0.0.0-20180218012637-3fcac458b4e8 h1:MNEwdJ+5eTNPHbe1UadIIRe6LA0wuCBjNZ9YM4if3gQ=
2+
github.com/Programmerino/beepFade v0.0.0-20180218012637-3fcac458b4e8/go.mod h1:vv9YVsGPxWMPIO0Br1QEemezKw1tS13UNJWJ13vQxlM=
3+
github.com/faiface/beep v1.0.1 h1:SYTt7Bpt0C9KgeLkyNzTTuW9o3D3lTyAPAwCr5EQjO4=
4+
github.com/faiface/beep v1.0.1/go.mod h1:1yLb5yRdHMsovYYWVqYLioXkVuziCSITW1oarTeduQM=
5+
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
6+
github.com/gdamore/tcell v1.1.1/go.mod h1:K1udHkiR3cOtlpKG5tZPD5XxrF7v2y7lDq7Whcj+xkQ=
7+
github.com/gopherjs/gopherjs v0.0.0-20180628210949-0892b62f0d9f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
8+
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
9+
github.com/gopherjs/gopherwasm v0.1.1/go.mod h1:kx4n9a+MzHH0BJJhvlsQ65hqLFXDO/m256AsaDPQ+/4=
10+
github.com/gopherjs/gopherwasm v1.0.0/go.mod h1:SkZ8z7CWBz5VXbhJel8TxCmAcsQqzgWGR/8nMhyhZSI=
11+
github.com/hajimehoshi/go-mp3 v0.1.1 h1:Y33fAdTma70fkrxnc9u50Uq0lV6eZ+bkAlssdMmCwUc=
12+
github.com/hajimehoshi/go-mp3 v0.1.1/go.mod h1:4i+c5pDNKDrxl1iu9iG90/+fhP37lio6gNhjCx9WBJw=
13+
github.com/hajimehoshi/oto v0.1.1/go.mod h1:hUiLWeBQnbDu4pZsAhOnGqMI1ZGibS6e2qhQdfpwz04=
14+
github.com/hajimehoshi/oto v0.3.1 h1:cpf/uIv4Q0oc5uf9loQn7PIehv+mZerh+0KKma6gzMk=
15+
github.com/hajimehoshi/oto v0.3.1/go.mod h1:e9eTLBB9iZto045HLbzfHJIc+jP3xaKrjZTghvb6fdM=
16+
github.com/jfreymuth/oggvorbis v1.0.0/go.mod h1:abe6F9QRjuU9l+2jek3gj46lu40N4qlYxh2grqkLEDM=
17+
github.com/jfreymuth/vorbis v1.0.0/go.mod h1:8zy3lUAm9K/rJJk223RKy6vjCZTWC61NA2QD06bfOE0=
18+
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4=
19+
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
20+
github.com/mewkiz/flac v1.0.5/go.mod h1:EHZNU32dMF6alpurYyKHDLYpW1lYpBZ5WrXi/VuNIGs=
21+
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
22+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
23+
golang.org/x/exp v0.0.0-20180710024300-14dda7b62fcd/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
24+
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
25+
golang.org/x/mobile v0.0.0-20180806140643-507816974b79/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
26+
golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
27+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
28+
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=

example/main.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"os"
6+
"time"
7+
8+
"github.com/Programmerino/beepFade"
9+
"github.com/faiface/beep"
10+
"github.com/faiface/beep/mp3"
11+
"github.com/faiface/beep/speaker"
12+
)
13+
14+
func main() {
15+
f, err := os.Open("song1.mp3")
16+
if err != nil {
17+
log.Fatal(err)
18+
}
19+
streamer, format, err := mp3.Decode(f)
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
defer streamer.Close()
24+
25+
f2, err := os.Open("song2.mp3")
26+
if err != nil {
27+
log.Fatal(err)
28+
}
29+
streamer2, _, err := mp3.Decode(f2)
30+
if err != nil {
31+
log.Fatal(err)
32+
}
33+
defer streamer2.Close()
34+
35+
opts := beepFade.Options{
36+
TimeSpan: 20 * time.Second, // this setting sounds terrible, but hey, this is just an example
37+
Volume: 1,
38+
}
39+
40+
final := beepFade.CrossfadeStream(format, &opts, streamer, streamer2)
41+
42+
speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
43+
44+
done := make(chan bool)
45+
speaker.Play(beep.Seq(final, beep.Callback(func() {
46+
done <- true
47+
})))
48+
49+
<-done
50+
51+
}

example/song1.mp3

955 KB
Binary file not shown.

example/song2.mp3

13.9 MB
Binary file not shown.

0 commit comments

Comments
 (0)