Skip to content

Commit

Permalink
Renamed constructor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
zaf committed Dec 28, 2016
1 parent 53a0a09 commit 9641bd2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
41 changes: 19 additions & 22 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# g711
--

import "github.com/zaf/g711"

Package g711 implements encoding and decoding of G711.0 compressed sound data.
G.711 is an ITU-T standard for audio companding.

For usage details please see the code snippets in the cmd folder.


## Usage

```go
const (
// Alaw G711 encoded PCM data
Alaw = iota
// Ulaw G711 encoded PCM data
Ulaw
// Lpcm 16bit signed linear data
Lpcm
// Input and output formats
Alaw = iota // Alaw G711 encoded PCM data
Ulaw // Ulaw G711 encoded PCM data
Lpcm // Lpcm 16bit signed linear data
)
```

Expand Down Expand Up @@ -73,20 +70,20 @@ type Reader struct {
Reader reads G711 PCM data and decodes it to 16bit LPCM or directly transcodes
between A-law and u-law

#### func NewAlawReader
#### func NewAlawDecoder

```go
func NewAlawReader(reader io.Reader, output int) (*Reader, error)
func NewAlawDecoder(reader io.Reader, output int) (*Reader, error)
```
NewAlawReader returns a pointer to a Reader that decodes or trans-codes A-law
NewAlawDecoder returns a pointer to a Reader that decodes or trans-codes A-law
data. It takes as input the source data Reader and the output encoding fomrat.

#### func NewUlawReader
#### func NewUlawDecoder

```go
func NewUlawReader(reader io.Reader, output int) (*Reader, error)
func NewUlawDecoder(reader io.Reader, output int) (*Reader, error)
```
NewUlawReader returns a pointer to a Reader that decodes or trans-codes u-law
NewUlawDecoder returns a pointer to a Reader that decodes or trans-codes u-law
data. It takes as input the source data Reader and the output encoding fomrat.

#### func (*Reader) Read
Expand Down Expand Up @@ -115,21 +112,21 @@ type Writer struct {
Writer encodes 16bit LPCM data to G711 PCM or directly transcodes between A-law
and u-law

#### func NewAlawWriter
#### func NewAlawEncoder

```go
func NewAlawWriter(writer io.Writer, input int) (*Writer, error)
func NewAlawEncoder(writer io.Writer, input int) (*Writer, error)
```
NewAlawWriter returns a pointer to a Writer that encodes data to A-law. It takes
as input the destination data Writer and the input encoding fomrat.
NewAlawEncoder returns a pointer to a Writer that encodes data to A-law. It
takes as input the destination data Writer and the input encoding fomrat.

#### func NewUlawWriter
#### func NewUlawEncoder

```go
func NewUlawWriter(writer io.Writer, input int) (*Writer, error)
func NewUlawEncoder(writer io.Writer, input int) (*Writer, error)
```
NewUlawWriter returns a pointer to a Writer that encodes data to u-law. It takes
as input the destination data Writer and the input encoding fomrat.
NewUlawEncoder returns a pointer to a Writer that encodes data to u-law. It
takes as input the destination data Writer and the input encoding fomrat.

#### func (*Writer) Flush

Expand Down
4 changes: 2 additions & 2 deletions cmd/g711dec/g711dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func decodeG711(file string) error {
extension := strings.ToLower(filepath.Ext(file))
var decoder *g711.Reader
if extension == ".alaw" || extension == ".al" {
decoder, err = g711.NewAlawReader(input, g711.Lpcm)
decoder, err = g711.NewAlawDecoder(input, g711.Lpcm)
if err != nil {
return err
}
} else if extension == ".ulaw" || extension == ".ul" {
decoder, err = g711.NewUlawReader(input, g711.Lpcm)
decoder, err = g711.NewUlawDecoder(input, g711.Lpcm)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/g711enc/g711enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ func encodeG711(file, format string) error {
defer outFile.Close()
var encoder *g711.Writer
if format == "alaw" {
encoder, err = g711.NewAlawWriter(outFile, g711.Lpcm)
encoder, err = g711.NewAlawEncoder(outFile, g711.Lpcm)
if err != nil {
return err
}
} else {
encoder, err = g711.NewUlawWriter(outFile, g711.Lpcm)
encoder, err = g711.NewUlawEncoder(outFile, g711.Lpcm)
if err != nil {
return err
}
Expand Down
26 changes: 12 additions & 14 deletions g711.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import (
)

const (
// Alaw G711 encoded PCM data
Alaw = iota
// Ulaw G711 encoded PCM data
Ulaw
// Lpcm 16bit signed linear data
Lpcm
// Input and output formats
Alaw = iota // Alaw G711 encoded PCM data
Ulaw // Ulaw G711 encoded PCM data
Lpcm // Lpcm 16bit signed linear data
)

type encoder func(int16) uint8
Expand All @@ -50,39 +48,39 @@ type Writer struct {
buf *bytes.Buffer //local buffer
}

// NewAlawReader returns a pointer to a Reader that decodes or trans-codes A-law data.
// NewAlawDecoder returns a pointer to a Reader that decodes or trans-codes A-law data.
// It takes as input the source data Reader and the output encoding fomrat.
func NewAlawReader(reader io.Reader, output int) (*Reader, error) {
func NewAlawDecoder(reader io.Reader, output int) (*Reader, error) {
if output != Ulaw && output != Lpcm {
return nil, errors.New("Invalid output format")
}
b := new(bytes.Buffer)
return &Reader{input: Alaw, output: output, r: reader, buf: b}, nil
}

// NewUlawReader returns a pointer to a Reader that decodes or trans-codes u-law data.
// NewUlawDecoder returns a pointer to a Reader that decodes or trans-codes u-law data.
// It takes as input the source data Reader and the output encoding fomrat.
func NewUlawReader(reader io.Reader, output int) (*Reader, error) {
func NewUlawDecoder(reader io.Reader, output int) (*Reader, error) {
if output != Alaw && output != Lpcm {
return nil, errors.New("Invalid output format")
}
b := new(bytes.Buffer)
return &Reader{input: Ulaw, output: output, r: reader, buf: b}, nil
}

// NewAlawWriter returns a pointer to a Writer that encodes data to A-law.
// NewAlawEncoder returns a pointer to a Writer that encodes data to A-law.
// It takes as input the destination data Writer and the input encoding fomrat.
func NewAlawWriter(writer io.Writer, input int) (*Writer, error) {
func NewAlawEncoder(writer io.Writer, input int) (*Writer, error) {
if input != Ulaw && input != Lpcm {
return nil, errors.New("Invalid input format")
}
b := new(bytes.Buffer)
return &Writer{input: input, output: Alaw, w: writer, buf: b}, nil
}

// NewUlawWriter returns a pointer to a Writer that encodes data to u-law.
// NewUlawEncoder returns a pointer to a Writer that encodes data to u-law.
// It takes as input the destination data Writer and the input encoding fomrat.
func NewUlawWriter(writer io.Writer, input int) (*Writer, error) {
func NewUlawEncoder(writer io.Writer, input int) (*Writer, error) {
if input != Alaw && input != Lpcm {
return nil, errors.New("Invalid input format")
}
Expand Down

0 comments on commit 9641bd2

Please sign in to comment.