wav

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2022 License: ISC Imports: 11 Imported by: 1

README

go-wav workflow status

A Go library to read/write WAVE(RIFF waveform Audio) Format

Usage

package main

import (
	"flag"
	"fmt"
	"github.com/youpy/go-wav"
	"io"
	"os"
)

func main() {
	infile_path := flag.String("infile", "", "wav file to read")
	flag.Parse()

	file, _ := os.Open(*infile_path)
	reader := wav.NewReader(file)

  	defer file.Close()

	for {
		samples, err := reader.ReadSamples()
		if err == io.EOF {
			break
		}

		for _, sample := range samples {
			fmt.Printf("L/R: %d/%d\n", reader.IntValue(sample, 0), reader.IntValue(sample, 1))
		}
	}
}

Supported format

Format

  • PCM
  • IEEE float (read-only)
  • G.711 A-law (read-only)
  • G.711 µ-law (read-only)

Number of channels

  • 1(mono)
  • 2(stereo)

Bits per sample

  • 32-bit
  • 24-bit
  • 16-bit
  • 8-bit

Documentation

See Also

Documentation

Index

Constants

View Source
const (
	AudioFormatPCM       = 1
	AudioFormatIEEEFloat = 3
	AudioFormatALaw      = 6
	AudioFormatMULaw     = 7
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	*WavData
	// contains filtered or unexported fields
}

func NewReader

func NewReader(r riff.RIFFReader) *Reader

func (*Reader) Duration

func (r *Reader) Duration() (time.Duration, error)

func (*Reader) FloatValue

func (r *Reader) FloatValue(sample Sample, channel uint) float64

func (*Reader) Format

func (r *Reader) Format() (format *WavFormat, err error)

func (*Reader) Info

func (r *Reader) Info() (*WavInfo, error)

func (*Reader) IntValue

func (r *Reader) IntValue(sample Sample, channel uint) int

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

func (*Reader) ReadSamples

func (r *Reader) ReadSamples(params ...uint32) (samples []Sample, err error)

type Sample

type Sample struct {
	Values [2]int
}

type WavData

type WavData struct {
	io.Reader
	Size uint32
	// contains filtered or unexported fields
}

type WavFormat

type WavFormat struct {
	AudioFormat   uint16
	NumChannels   uint16
	SampleRate    uint32
	ByteRate      uint32
	BlockAlign    uint16
	BitsPerSample uint16
}

type WavInfo

type WavInfo struct {
	NFrames     int
	SampleWidth int
	FrameRate   int
	NChannels   int
	FrameSize   int
}

type Writer

type Writer struct {
	io.Writer
	Format *WavFormat
}

func NewWriter

func NewWriter(w io.Writer, numSamples uint32, numChannels uint16, sampleRate uint32, bitsPerSample uint16) (writer *Writer)

func (*Writer) WriteSamples

func (w *Writer) WriteSamples(samples []Sample) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL