Remove examples, tests, change module name

This commit is contained in:
DataHoarder 2022-12-06 10:40:54 +01:00
parent 52c23bd389
commit e088a49a96
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
7 changed files with 5 additions and 294 deletions

View file

@ -1,19 +1,7 @@
## aac-go
[![TravisCI Build Status](https://travis-ci.org/gen2brain/aac-go.svg?branch=master)](https://travis-ci.org/gen2brain/aac-go)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/cig800cju43dbn8u?svg=true)](https://ci.appveyor.com/project/gen2brain/aac-go)
[![GoDoc](https://godoc.org/github.com/gen2brain/aac-go?status.svg)](https://godoc.org/github.com/gen2brain/aac-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/gen2brain/aac-go?branch=master)](https://goreportcard.com/report/github.com/gen2brain/aac-go)
`aac-go` provides AAC codec encoder based on [VisualOn AAC encoder](https://github.com/mstorsjo/vo-aacenc) library.
### Installation
go get -u github.com/gen2brain/aac-go
### Examples
See [micgrab](https://github.com/gen2brain/aac-go/blob/master/examples/micgrab/micgrab.go) example.
### Usage
```go
@ -24,7 +12,7 @@ import (
"io/ioutil"
"os"
"github.com/gen2brain/aac-go"
"git.gammaspectra.live/S.O.N.G/voaac-go"
"github.com/youpy/go-wav"
)

View file

@ -8,7 +8,7 @@ import (
"io"
"unsafe"
"github.com/aam335/aac-go/aacenc"
"git.gammaspectra.live/S.O.N.G/voaac-go/aacenc"
)
// Options represent encoding options.

View file

@ -1,136 +0,0 @@
package aac
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"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 := &Options{}
opts.SampleRate = int(f.SampleRate)
opts.NumChannels = int(f.NumChannels)
enc, err := 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 = ioutil.WriteFile(filepath.Join(os.TempDir(), "test.aac"), buf.Bytes(), 0644)
if err != nil {
t.Error(err)
}
if want, got := 8192, len(buf.Bytes()); want != got {
t.Errorf("encoded file length %d is different from expected length %d", got, want)
}
}
type testReader struct {
bufLen int
from io.Reader
adjust func() int
}
func (t *testReader) Read(in []byte) (int, error) {
defer func() {
t.bufLen = t.adjust()
}()
if t.bufLen > len(in) {
t.bufLen = len(in)
}
if t.bufLen == 0 {
// This is not EOF, just unavailable data at this point.
return 0, nil
}
buf := make([]byte, t.bufLen)
n, err := t.from.Read(buf)
if n > 0 {
copy(in, buf[:n])
}
return n, err
}
func TestEncodeVariableReadLength(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)
}
tr := &testReader{
bufLen: 1,
from: wr,
}
bufLenPrev := 1
tr.adjust = func() int {
bufLenPrev += 1
if bufLenPrev%5 == 0 {
return 0
}
return bufLenPrev
}
buf := bytes.NewBuffer(make([]byte, 0))
opts := &Options{}
opts.SampleRate = int(f.SampleRate)
opts.NumChannels = int(f.NumChannels)
enc, err := NewEncoder(buf, opts)
if err != nil {
t.Fatal(err)
}
err = enc.Encode(tr)
if err != nil {
t.Error(err)
}
err = enc.Close()
if err != nil {
t.Error(err)
}
err = ioutil.WriteFile(filepath.Join(os.TempDir(), "test-2.aac"), buf.Bytes(), 0644)
if err != nil {
t.Error(err)
}
if want, got := 8192, len(buf.Bytes()); want != got {
t.Errorf("encoded file length %d is different from expected length %d", got, want)
}
}

View file

@ -1,48 +0,0 @@
package main
import (
"bytes"
"io/ioutil"
"os"
aac "github.com/aam335/aac-go"
)
func main() {
file, err := os.Open("test.wav")
if err != nil {
panic(err)
}
wreader := wav.NewReader(file)
f, err := wreader.Format()
if err != nil {
panic(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 {
panic(err)
}
err = enc.Encode(wreader)
if err != nil {
panic(err)
}
err = enc.Close()
if err != nil {
panic(err)
}
err = ioutil.WriteFile("test.aac", buf.Bytes(), 0644)
if err != nil {
panic(err)
}
}

View file

@ -1,96 +0,0 @@
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"github.com/gen2brain/aac-go"
"github.com/gen2brain/malgo"
)
func main() {
device := mal.NewDevice()
numChannels := 2
sampleRate := 48000
var capturedSampleCount uint32
pCapturedSamples := make([]byte, 0)
onRecvFrames := func(framecount uint32, pSamples []byte) {
sizeInBytes := device.SampleSizeInBytes(device.Format())
sampleCount := framecount * device.Channels() * sizeInBytes
newCapturedSampleCount := capturedSampleCount + sampleCount
pCapturedSamples = append(pCapturedSamples, pSamples...)
capturedSampleCount = newCapturedSampleCount
}
err := device.ContextInit(nil, mal.ContextConfig{})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer device.ContextUninit()
config := device.ConfigInit(mal.FormatS16, uint32(numChannels), uint32(sampleRate), onRecvFrames, nil)
fmt.Println("Recording...")
err = device.Init(mal.Capture, nil, &config)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = device.Start()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Press Enter to stop recording...")
fmt.Scanln()
device.Uninit()
fmt.Println("Encoding...")
buf := bytes.NewBuffer(make([]byte, 0))
opts := &aac.Options{}
opts.SampleRate = sampleRate
opts.NumChannels = numChannels
enc, err := aac.NewEncoder(buf, opts)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
reader := bytes.NewReader(pCapturedSamples)
err = enc.Encode(reader)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = enc.Close()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = ioutil.WriteFile("capture.aac", buf.Bytes(), 0644)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Press Enter to quit...")
fmt.Scanln()
os.Exit(0)
}

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module git.gammaspectra.live/S.O.N.G/voaac-go
go 1.17

BIN
testdata/test.wav vendored

Binary file not shown.