mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
feat: upgrade oto and output float audio
This commit is contained in:
parent
890ebe3294
commit
81a6d1acea
@ -43,6 +43,7 @@ func main() {
|
||||
*play = true // if the user gives nothing to output, then the default behaviour is just to play the file
|
||||
}
|
||||
var audioContext sointu.AudioContext
|
||||
var playWaiter sointu.CloserWaiter
|
||||
if *play {
|
||||
var err error
|
||||
audioContext, err = oto.NewContext()
|
||||
@ -50,7 +51,6 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "could not acquire oto AudioContext: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer audioContext.Close()
|
||||
}
|
||||
process := func(filename string) error {
|
||||
output := func(extension string, contents []byte) error {
|
||||
@ -98,11 +98,7 @@ func main() {
|
||||
return fmt.Errorf("sointu.Play failed: %v", err)
|
||||
}
|
||||
if *play {
|
||||
output := audioContext.Output()
|
||||
defer output.Close()
|
||||
if err := output.WriteAudio(buffer); err != nil {
|
||||
return fmt.Errorf("error playing: %v", err)
|
||||
}
|
||||
playWaiter = audioContext.Play(buffer.Source())
|
||||
}
|
||||
if *rawOut {
|
||||
raw, err := buffer.Raw(*pcm)
|
||||
@ -122,6 +118,9 @@ func main() {
|
||||
return fmt.Errorf("error outputting .wav file: %v", err)
|
||||
}
|
||||
}
|
||||
if *play {
|
||||
playWaiter.Wait()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
retval := 0
|
||||
|
@ -28,6 +28,16 @@ func (NullContext) BPM() (bpm float64, ok bool) {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
type PlayerAudioSource struct {
|
||||
*tracker.Player
|
||||
playerProcessContext tracker.PlayerProcessContext
|
||||
}
|
||||
|
||||
func (p *PlayerAudioSource) ReadAudio(buf sointu.AudioBuffer) error {
|
||||
p.Player.Process(buf, p.playerProcessContext)
|
||||
return nil
|
||||
}
|
||||
|
||||
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
|
||||
var memprofile = flag.String("memprofile", "", "write memory profile to `file`")
|
||||
|
||||
@ -49,7 +59,6 @@ func main() {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer audioContext.Close()
|
||||
recoveryFile := ""
|
||||
if configDir, err := os.UserConfigDir(); err == nil {
|
||||
recoveryFile = filepath.Join(configDir, "Sointu", "sointu-track-recovery")
|
||||
@ -63,18 +72,10 @@ func main() {
|
||||
f.Close()
|
||||
}
|
||||
tracker := gioui.NewTracker(model)
|
||||
output := audioContext.Output()
|
||||
defer output.Close()
|
||||
go func() {
|
||||
buf := make(sointu.AudioBuffer, 1024)
|
||||
ctx := NullContext{}
|
||||
for {
|
||||
player.Process(buf, ctx)
|
||||
output.WriteAudio(buf)
|
||||
}
|
||||
}()
|
||||
audioCloser := audioContext.Play(&PlayerAudioSource{player, NullContext{}})
|
||||
go func() {
|
||||
tracker.Main()
|
||||
audioCloser.Close()
|
||||
if *cpuprofile != "" {
|
||||
pprof.StopCPUProfile()
|
||||
f.Close()
|
||||
|
Reference in New Issue
Block a user