Skip to content

Commit

Permalink
Refactor away qoa package (#47)
Browse files Browse the repository at this point in the history
* Use qoa package from different repo
* Add demo gif
  • Loading branch information
braheezy authored Jul 20, 2024
1 parent cf723c9 commit a060893
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 1,106 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ dist/
/*.ogg
/*.flac
/fuzz/*.qoa
/assets/*.gif
/assets/after.gif
/assets/before.gif
*.prof
/output_*
/*.wav
Expand Down
53 changes: 9 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# QOA: Quite OK Audio
> The Quite OK Audio Format for Fast, Lossy Compression.
[![Go Reference](https://pkg.go.dev/badge/github.com/braheezy/goqoa.svg)](https://pkg.go.dev/github.com/braheezy/goqoa)
[![Build Status](https://github.com/braheezy/goqoa/actions/workflows/ci.yml/badge.svg)](https://github.com/braheezy/goqoa/actions)

A Go implementation of the [QOA Format Specification](https://qoaformat.org/).
A CLI tool for working with audio files following the [QOA Format Specification](https://qoaformat.org/).

![demo](./assets/demo.gif)

Features:
- `qoa` library package for QOA encoding and decoding
- Go standard library only
- Fuzz testing coverage
- Some optimizations. See [Benchmarks](#benchmarks)
- `goqoa` CLI tool
- `convert` your WAV, FLAC, OGG, or MP3 files to QOA
- `convert` your QOA files to WAV or MP3
- All conversions are in pure Go, no C libraries to install
- `play` QOA file(s)
- Pre-built binaries for Linux, Windows, and Mac
- `convert` WAV, FLAC, OGG, or MP3 files to QOA
- `convert` QOA files to WAV or MP3
- All conversions are in pure Go, no C libraries to install
- `play` QOA file(s)
- Pre-built binaries for Linux, Windows, and Mac

[This blog post](https://phoboslab.org/log/2023/02/qoa-time-domain-audio-compression) by the author of QOA is a great introduction to the format and how it works.

Expand All @@ -35,38 +31,7 @@ Then, install directly with Go:
go install github.com/braheezy/goqoa@latest

## `qoa` Package
The `qoa` package is a pure Go implementation.

Decode a `.qoa` file:
```go
data, _ := os.ReadFile("groovy-tunes.qoa")
qoaMetadata, decodedData, err = qoa.Decode(inputData)
// Do stuff with decodedData
```

Or encode audio samples. This example shows a WAV file:
```go
// Read a WAV
data, _ := os.ReadFile("groovy-tunes.wav")
wavReader := bytes.NewReader(data)
wavDecoder := wav.NewDecoder(wavReader)
wavBuffer, err := wavDecoder.FullPCMBuffer()

// Figure out audio metadata and create a new QOA encoder using the info
numSamples := uint32(len(wavBuffer.Data) / wavBuffer.Format.NumChannels)
qoaFormat := qoa.NewEncoder(
uint32(wavBuffer.Format.SampleRate),
uint32(wavBuffer.Format.NumChannels),
numSamples)
// Convert the audio data to int16 (QOA format)
decodedData = make([]int16, len(wavBuffer.Data))
for i, val := range wavBuffer.Data {
decodedData[i] = int16(val)
}

// Finally, encode the audio data
qoaEncodedData, err := qoa.Encode(decodedData)
```
The library `qoa` has been moved to [this repository](https://github.com/braheezy/qoa) so I could manage the version of the library separate from the `goqoa` CLI.

## Development
You'll need the following:
Expand Down
Binary file added assets/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"

"github.com/braheezy/goqoa/pkg/qoa"
"github.com/braheezy/qoa"
"github.com/go-audio/audio"
"github.com/go-audio/wav"
"github.com/jfreymuth/oggvorbis"
Expand Down
2 changes: 1 addition & 1 deletion cmd/convert_mp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"os"

"github.com/braheezy/goqoa/pkg/qoa"
"github.com/braheezy/qoa"
"github.com/braheezy/shine-mp3/pkg/mp3"
"github.com/tosone/minimp3"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

"github.com/braheezy/goqoa/pkg/qoa"
"github.com/braheezy/qoa"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/braheezy/goqoa/pkg/qoa"
"github.com/braheezy/qoa"
"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/list"
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/braheezy/goqoa

go 1.21.0
go 1.21.9

require (
github.com/braheezy/qoa v1.0.0
github.com/braheezy/shine-mp3 v0.1.0
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.26.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/braheezy/qoa v1.0.0 h1:lkay4dxEEyrr2Uj7qrNGQ2gQuNeCabSRqGCF3UotOwY=
github.com/braheezy/qoa v1.0.0/go.mod h1:jnqLftWKRxq9xZ+9XDmzKoN7tYYimDHTCjWhePkFt1g=
github.com/braheezy/shine-mp3 v0.1.0 h1:N2wZhv6ipCFduTSftaPNdDgZ5xFmQAPvB7JcqA4sSi8=
github.com/braheezy/shine-mp3 v0.1.0/go.mod h1:0H/pmcpFAd+Fnrj6Pc7du7wL36U/HqtfcgPJuCgc1L4=
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
Expand Down
149 changes: 0 additions & 149 deletions pkg/qoa/decode.go

This file was deleted.

Loading

0 comments on commit a060893

Please sign in to comment.