Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Audio #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions audio_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// +build windows

package audio

import (
"log"
"time"

"bitbucket.org/StephenPatrick/go-winaudio/winaudio"
)

type Player struct {
player winaudio.Audio
duration time.Duration
src string
format int
samplesPerSecond int64
Paused bool
}

func notImplemented(msg string) {
log.Println("[WARNING] " + msg + " is not implemented on Windows")
}

func NewPlayer(src string, format int, samplesPerSecond int64) (*Player, error) {
winaudio.InitWinAudio()
wavfile, err := winaudio.LoadWav(src)
if err != nil {
panic(err)
}
wavfile.SetLooping(true)
return &Player{player: wavfile, src: src, format: format, samplesPerSecond: samplesPerSecond}, nil
}

func NewSimplePlayer(src string) (*Player, error) {
return NewPlayer(src, 0, 0)
}

func (p *Player) Close() error {
notImplemented("close")
return nil
}

func (p *Player) Current() time.Duration {
dur, _ := time.ParseDuration("3000ms")
return dur
}

func (p *Player) Play() error {
err := p.player.Play()
if err != nil {
panic(err)
}
p.Paused = false
return nil
}

func (p *Player) Seek(offset time.Duration) error {
notImplemented("seek")
return nil
}

func (p *Player) Pause() error {
p.player.Pause()
p.Paused = true
return nil
}

func (p *Player) SetVolume(volume float64) error {
p.player.SetVolume(int32(volume))
return nil
}

func (p *Player) Volume() int32 {
vol, _ := p.player.GetVolume()
return vol
}

func (p *Player) State() State {
if p.Paused {
return Paused
} else {
return Playing
}
}

func (p *Player) Stop() error {
notImplemented("stop")
return nil
}

func (p *Player) Total(bg bool) time.Duration {
//TODO: Use the bg parameter
return p.duration
}

func (p *Player) Rewind() {
notImplemented("rewind")
}

func (p *Player) PlaySources() {
notImplemented("playSources")
}
Binary file added demos/assets/48hz16bit2ch.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion demos/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
player, err := audio.NewSimplePlayer("assets/birds.wav")
player, err := audio.NewSimplePlayer("assets/48hz16bit2ch.wav")
if err != nil {
panic(err)
}
Expand Down