Giter Club home page Giter Club logo

chunk's Introduction

chunk

Build GoDoc

Library for decoding and encoding chunked audio containers like RIFF / AIFF.

Features

  • Supported formats:
    • Waveform Audio File Format (WAVE)
    • Broadcast Wave Format (BWF)
    • Audio Interchange File Format (AIFF, AIFF-C)
  • Supported chunks (Decode / Encode)
    • 'fmt ' - WAVE format and PCM format
    • 'COMM' - Common
    • 'bext' - Broadcast Extension for sound metadata in BWF (version 0, 1, 2)
    • 'iXML' - Extension for sound metadata in BWF (iXML Specification Revision 2.10)
  • Decode headers of unknown chunks
  • Encode custom header
  • Byte array presentation of known chunks for further processing

Prerequisites

Download and install chunk into your GOPATH.

go get github.com/metawav/chunk

Import the package to get started.

import "github.com/metawav/chunk"

Examples

Read headers from RIFF (.wav) file

fileName := "sample.wav"
file, err := os.Open(fileName)

if err != nil {
    panic(err)
}

defer file.Close()

reader := io.ReadSeeker(file)
container, _ := chunk.ReadRiff(file.Name(), reader)

for _, header := range container.Headers {
    fmt.Printf("%s\n", header)
}

Example output:

ID: fmt  Size: 16 FullSize: 24 StartPos: 12 HasPadding: false
ID: data Size: 88200 FullSize: 88208 StartPos: 36 HasPadding: false
ID: LIST Size: 68 FullSize: 76 StartPos: 88244 HasPadding: false
ID: JUNK Size: 10 FullSize: 18 StartPos: 88320 HasPadding: false

Find and decode format chunk

headers := container.FindHeaders("fmt ") // keep care of trailing space :)
chunkBytes := make([]byte, headers[0].FullSize())
_, err = file.ReadAt(chunkBytes, int64(headers[0].StartPos()))

if err != nil {
    //handle err
}

format, err := chunk.DecodePCMFormatChunk(chunkBytes)

if err != nil {
    //handle err
}

fmt.Printf("%s\n", format)

Example output:

Format: 1
Channels: 1
Sample rate: 44100
Byte rate: 88200
Bytes per sample: 2
Bits per sample: 16

Encode format chunk

format = chunk.EncodePCMFormatChunk(16, 1, 1, 44100, 88200, 2, 24)
fmt.Printf("%s\n", format)

Example output:

Format: 1
Channels: 1
Sample rate: 44100
Byte rate: 88200
Bytes per sample: 2
Bits per sample: 24

Get bytes representation of format chunk

format = chunk.EncodePCMFormatChunk(16, 1, 1, 44100, 88200, 2, 24)
fmt.Printf("%08b\n", format.Bytes())

Example output:

[
01100110 01101101 01110100 00100000 // ID               = "fmt "
00010000 00000000 00000000 00000000 // size             = 16
00000001 00000000                   // format           = 1
00000001 00000000                   // channels         = 1
01000100 10101100 00000000 00000000 // samples per sec  = 44100
10001000 01011000 00000001 00000000 // bytes per sec    = 88200
00000010 00000000                   // block align      = 2
00011000 00000000                   // bits per sample  = 24
]

Documentation

See package documentation:

GoDoc

License

chunk is released under Apache License, Version 2.0. See LICENSE.

chunk's People

Contributors

pmoule avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.