waveform

package module
v0.0.0-...-835111f Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 3 Imported by: 0

README

go-waveform

go-waveform

Golang project for the purpose of practicing, understanding golang and audio file format.

Usage

Requirements

Go 1.11 (Go Modules)

Cli

Generate waveform image via CLI

GO111MODULE=on make
./bin/go-waveform -t dark -r 1000 -f png example/violin.wav

open example/violin-L.png
open example/violin-R.png
Import as package

Import as package,

import "github.com/dreadl0ck/go-waveform"

and decode wav audio file

w := waveform.DecodeWav(wavFileBytes)
fmt.Println(w.BitsPerSample)

data, _ := w.GetData()

if stereoData, ok := data.(*waveform.StereoData); ok {
  fmt.Println(stereoData.RSample)
  fmt.Println(stereoData.LSample)
} else if monoData, ok := data.(*waveform.MonoData); ok {
  fmt.Println(monoData.Sample)
}
Todo
  • More wav file details
  • Converter
  • Raw Waveform
  • Waveform image customization
  • Test

Documentation

Index

Constants

View Source
const (
	WaveFormatPCM        WaveFormat = 0x0001
	WaveFormatIEEEFloat             = 0x0003
	WaveFormatALaw                  = 0x0006
	WaveFormatMULaw                 = 0x0007
	WaveFormatExtensible            = 0xFFFE
)

WaveFormat wave format tag

Variables

This section is empty.

Functions

func GetSampleParser

func GetSampleParser(bitsPerSample uint16, waveFormat WaveFormat) (func([]byte) float64, error)

GetSampleParser get sample parser

Types

type Bound

type Bound struct {
	Upper float64
	Lower float64
}

Bound sample value upper and lower boundary

func GetBound

func GetBound(bitsPerSample uint16, waveFormat WaveFormat) (*Bound, error)

GetBound get sample value bound

type MonoData

type MonoData struct {
	Sample Sample
	Bound  *Bound
}

MonoData mono data

type Parser

type Parser func([]byte) float64

Parser type

type Sample

type Sample []float64

Sample sample

type StereoData

type StereoData struct {
	LSample Sample
	RSample Sample
	Bound   *Bound
}

StereoData stereo data

type Wav

type Wav struct {
	WaveFormat    WaveFormat
	NumChannels   uint16
	SampleRate    uint32
	BitsPerSample uint16
	DataChuckSize uint32

	Data []byte
}

Wav struct

func DecodeWav

func DecodeWav(bytes []byte) *Wav

DecodeWav decode wav file information from bytes

func (*Wav) GetData

func (w *Wav) GetData() (interface{}, error)

GetData get wav audio data

type WaveFormat

type WaveFormat uint16

WaveFormat type

func (WaveFormat) String

func (f WaveFormat) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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