Code Monkey home page Code Monkey logo

goriffa's Introduction

Goriffa

Build

Goriffa is a package focused on writing and reading RIFF (Resource Interchange File Format) files. Wavefiles (.wav) and WEBP files are stored via RIFF, for example.

The main motivation for this library was (initially) to fork go-riff and go-wav in order to allow streaming/dynamic sizing of RIFF data. However, given the lack of updates for the aforementioned packages and the drastic API redesign, it made more sense for Goriffa to become its own repository.

Currently, Goriffa supports

  • Reading RIFF data.
  • Writing RIFF data and dynamically setting the data size RIFF field.
  • Reading Wavefile format data (and samples - though, the sample will be raw bytes)
  • Writing Wavefile data (including the format data)

Okay, give me an example!

Reading

Say you want to read a Wavefile - let's call it cool-audio.wav:

import (
    "os"

    "github.com/standoffvenus/goriffa/reader"
    "github.com/standoffvenus/goriffa/wave"
)

// Open the .wav file
f, fErr := os.Open("cool-audio.wav")
if fErr != nil {
    panic(fErr)
}
defer f.Close()

reader, readerErr := reader.New(f)
if readerErr != nil {
    panic(readerErr)
}

format, formatErr := wave.FormatFromReader(reader)
if formatErr != nil {
    panic(formatErr)
}

// Do something with the format data...

Then, assuming that the Wavefile contains raw PCM audio data, you could read the PCM data by reading from the initial reader:

var dataChunk goriffa.Chunk
if _, err := reader.ReadChunk(&dataChunk); err != nil {
    panic(err)
}

// Do something with the data chunk, which now contains
// the PCM data...

Writing

Let's say we want to write a RIFF file. This is rather trivial with Goriffa:

import (
    "os"

    "github.com/standoffvenus/goriffa/writer"
)

// Open the .wav file
f, fErr := os.Open("cool-audio.wav")
if fErr != nil {
    panic(fErr)
}
defer f.Close()

writer, writerErr := writer.New(f)
if readerErr != nil {
    panic(readerErr)
}
defer writer.Close() // You must call Close when done with the writer or the dynamic content size is not persisted

someData := GetSomeData()
if _, err := writer.WriteChunk(goriffa.Chunk{
    Identifier: goriffa.FourCCData,
    Data: someData,
}); err != nil {
    panic(err)
}

// Hurray! We wrote the data!

How do I execute/test locally?

To compile the application, immediately after cloning, generate the necessary Go code:

go generate ./...

Then, to test the project, you may run

go test ./...

The examplary WAVE and WEBP data used in some tests are embedded via //go:embed. Thanks, youpy, for packaging some example data with go-riff!

goriffa's People

Contributors

standoffvenus avatar

Watchers

 avatar

goriffa's Issues

Detect And Handle Different Wavefile Audio Formats

Currently, Wavefiles can only be written with raw PCM data. Additionally, Goriffa does very little to handle/simplify the Wavefile's samples. This makes writing bad data incredibly easy.

If there is enough motivation/interest for this use case, I would be willing to champion the changes to implement it.

Impose Stricter Constraints on Wavefile Data

Right now, very little validation of Wavefile data is done before writing it to the Goriffa writer. For example, you can write

  • Any sample rate
  • Any bit-per-sample size

We should return an error in the cases where format data like this makes no sense.

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.