Skip to content

add concat.go #22

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

Open
wants to merge 1 commit 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
Binary file added corpus/0009.wav
Binary file not shown.
Binary file added corpus/0918.wav
Binary file not shown.
Binary file added corpus/1827.wav
Binary file not shown.
Binary file added corpus/of.wav
Binary file not shown.
87 changes: 87 additions & 0 deletions examples/wavConcat/concat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"fmt"
"github.com/rlfosterjr/wav"
"os"
)

func concat(files []string, ofn string) {
var wf = wav.File{
Channels: 2,
SampleRate: 44100,
SignificantBits: 16,
}

of, _ := os.Create(ofn)
defer of.Close()

inc := len(files)
ww, err := wf.NewWriter(of)

if err != nil {
fmt.Println(err)
} else {
for i := 0; i < inc; i++ {
fmt.Println("File: " + files[i])
f, _ := os.Open(files[i])
stat, _ := f.Stat()
wr, _ := wav.NewReader(f, stat.Size())
fmt.Println(wr.String())

var s uint32
samps := wr.GetSampleCount()

for s = 0; s < samps; s++ {
cs, _ := wr.ReadRawSample()
ww.WriteSample(cs)
}
f.Close()
}
ww.Close()
}
}

//Test Wav Concat (stereo)
func main() {

//concat incremnts
inc := 3

increments := make([]string, inc)
increments[0] = "../../corpus/0009.wav"
increments[1] = "../../corpus/0918.wav"
increments[2] = "../../corpus/1827.wav"

of, _ := os.Create("concat.wav")
defer of.Close()

var wf = wav.File{
Channels: 2,
SampleRate: 44100,
SignificantBits: 16,
}

ww, err := wf.NewWriter(of)
if err != nil {
fmt.Println(err)
} else {
for i := 0; i < inc; i++ {
fmt.Println("File: " + increments[i])
f, _ := os.Open(increments[i])
stat, _ := f.Stat()
wr, _ := wav.NewReader(f, stat.Size())
fmt.Println(wr.String())

var s uint32
samps := wr.GetSampleCount()

for s = 0; s < samps; s++ {
cs, _ := wr.ReadRawSample()
ww.WriteSample(cs)
}
f.Close()
}
ww.Close()
}
}
Binary file added examples/wavConcat/concat.wav
Binary file not shown.
2 changes: 1 addition & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Writer struct {

// NewWriter creates a new WaveWriter and writes the header to it
func (file File) NewWriter(out output) (wr *Writer, err error) {
if file.Channels != 1 {
if file.Channels < 0 || file.Channels > 2 {
err = fmt.Errorf("sorry, only mono currently")
return
}
Expand Down