Skip to content

Instantly share code, notes, and snippets.

@dudk

dudk/example4.go Secret

Created August 5, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudk/02cc671873ecf2d8299164788d320ec8 to your computer and use it in GitHub Desktop.
Save dudk/02cc671873ecf2d8299164788d320ec8 to your computer and use it in GitHub Desktop.
phono example 4
package example
import (
"github.com/dudk/phono"
"github.com/dudk/phono/asset"
"github.com/dudk/phono/pipe"
"github.com/dudk/phono/portaudio"
"github.com/dudk/phono/track"
"github.com/dudk/phono/wav"
)
// Example 4:
// Read .wav file
// Split it to samples
// Put samples to track
// Save track into .wav and play it with portaudio
func four() {
bufferSize := phono.BufferSize(512)
inPath := "_testdata/sample1.wav"
outPath := "_testdata/example4_out.wav"
wavPump, err := wav.NewPump(inPath, bufferSize)
check(err)
asset := &asset.Asset{
SampleRate: wavPump.WavSampleRate(),
}
importAsset := pipe.New(
pipe.WithPump(wavPump),
pipe.WithSinks(asset),
)
err = importAsset.Do(pipe.Run)
check(err)
track := track.New(bufferSize, asset.NumChannels())
track.AddFrame(198450, asset.Frame(0, 44100))
track.AddFrame(66150, asset.Frame(44100, 44100))
track.AddFrame(132300, asset.Frame(0, 44100))
wavSink, err := wav.NewSink(
outPath,
wavPump.WavSampleRate(),
wavPump.WavNumChannels(),
wavPump.WavBitDepth(),
wavPump.WavAudioFormat(),
)
paSink := portaudio.NewSink(
bufferSize,
wavPump.WavSampleRate(),
wavPump.WavNumChannels(),
)
p := pipe.New(
pipe.WithPump(track),
pipe.WithSinks(wavSink, paSink),
)
err = p.Do(pipe.Run)
}
package example
func check(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment