forked from gen2brain/aac-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_test.go
More file actions
50 lines (40 loc) · 795 Bytes
/
encode_test.go
File metadata and controls
50 lines (40 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package aac_test
import (
"bytes"
"os"
"path/filepath"
"testing"
"github.com/gen2brain/aac-go"
"github.com/youpy/go-wav"
)
func TestEncode(t *testing.T) {
file, err := os.Open(filepath.Join("testdata", "test.wav"))
if err != nil {
t.Fatal(err)
}
wr := wav.NewReader(file)
f, err := wr.Format()
if err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(make([]byte, 0))
opts := &aac.Options{}
opts.SampleRate = int(f.SampleRate)
opts.NumChannels = int(f.NumChannels)
enc, err := aac.NewEncoder(buf, opts)
if err != nil {
t.Fatal(err)
}
err = enc.Encode(wr)
if err != nil {
t.Error(err)
}
err = enc.Close()
if err != nil {
t.Error(err)
}
err = os.WriteFile(filepath.Join(os.TempDir(), "test.aac"), buf.Bytes(), 0640)
if err != nil {
t.Error(err)
}
}