Skip to content

Commit

Permalink
initial commit v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
trapexit committed Nov 11, 2024
0 parents commit 400a4db
Show file tree
Hide file tree
Showing 52 changed files with 28,627 additions and 0 deletions.
17 changes: 17 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
ISC License

Copyright (c) 2024, Antonio SJ Musumeci <trapexit@spawn.link>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FILENAME := 3at
PLATFORM := $(shell uname -s | tr A-Z a-z)_$(shell arch)
COMPILER_PREFIX :=
EXE := $(FILENAME)_$(PLATFORM)

include Makefile.base
65 changes: 65 additions & 0 deletions Makefile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
JOBS := $(shell nproc)
PUID := $(shell id -u)
PGID := $(shell id -g)

OUTPUT = build/$(EXE)

CC := $(COMPILER_PREFIX)-gcc
CXX := $(COMPILER_PREFIX)-g++
STRIP := $(COMPILER_PREFIX)-strip

ifeq ($(NDEBUG),1)
OPT := -O3 -flto -static
else
OPT := -O0 -ggdb -ftrapv
endif

ifeq ($(SANITIZE),1)
OPT += -fsanitize=address
endif

CFLAGS = $(OPT) -Wall
CXXFLAGS = $(OPT) -Wall -std=c++17
CPPFLAGS ?= -MMD -MP

SRCS_C := $(wildcard src/*.c)
SRCS_CXX := $(wildcard src/*.cpp)

BUILDDIR = build/$(PLATFORM)
OBJS := $(SRCS_C:src/%.c=$(BUILDDIR)/%.c.o)
OBJS += $(SRCS_CXX:src/%.cpp=$(BUILDDIR)/%.cpp.o)
DEPS = $(OBJS:.o=.d)


all: $(OUTPUT)

$(OUTPUT): builddir $(OBJS)
$(CXX) $(CXXFLAGS) -o $(OUTPUT) $(OBJS) $(LDFLAGS)

strip: $(OUTPUT)
$(STRIP) --strip-all $(OUTPUT)

$(BUILDDIR)/%.c.o: src/%.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

$(BUILDDIR)/%.cpp.o: src/%.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@

clean:
rm -rfv build/

builddir:
mkdir -p $(BUILDDIR)

release-base: clean
$(MAKE) -f Makefile NDEBUG=1 -j$(JOBS) strip
# $(MAKE) -f Makefile.win32 NDEBUG=1 -j$(JOBS) strip
$(MAKE) -f Makefile.win64 NDEBUG=1 -j$(JOBS) strip

release:
docker run --rm -it -e PUID=$(PUID) -e PGID=$(PGID) -v ${PWD}:/src alpine:edge "/src/buildtools/docker-make-release"


.PHONY: clean builddir release docker-release

-include $(DEPS)
6 changes: 6 additions & 0 deletions Makefile.win32
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FILENAME := 3at
PLATFORM := win32
COMPILER_PREFIX := i686-w64-mingw32
EXE := $(FILENAME)_$(PLATFORM).exe

include Makefile.base
6 changes: 6 additions & 0 deletions Makefile.win64
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FILENAME := 3at
PLATFORM := win64
COMPILER_PREFIX := x86_64-w64-mingw32
EXE := $(FILENAME)_$(PLATFORM).exe

include Makefile.base
149 changes: 149 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# 3at: 3DO Audio Tool

A 3DO audio codec encoder / decoder. Supports SDX2 (square/xact/delta)
and Intel DVI / ADP4 codecs. Optionally uses FFmpeg for reading and
writing non-raw formats.

The eventual goal is to upstream the SDX2 and ADP4 encoders to FFmpeg.


## Usage

```
$ 3at --help
3at: 3DO Audio Tool v1.0.0
Usage: ./build/3at_linux_x86_64 [OPTIONS] SUBCOMMAND
Options:
-h,--help Print this help message and exit
--help-all List help for all subcommands
Subcommands:
to-adp4 Convert input to Intel/DVI ADP4 codec
to-sdx2 Convert input to SDX2 codec
from-adp4 Convert from raw Intel/DVI ADP4
from-sdx2 Convert from raw SDX2
version print 3at version
```

All subcommands have their own help and arguments. Use `--help` or
`--help-all` to see all available options.


## FFmpeg

Any input or output which is not `raw` requires FFmpeg to be
available. You can [download FFmpeg](https://ffmpeg.org) and place the
executable in your PATH or in the same directory as `3at`.


## Examples

```
$ 3at to-sdx2 --channels=1 --freq=22050 --output-type=raw input.wav
input.wav:
- output file name: input.wav.sdx2.1ch.22050hz.raw
- sample count: 661500
- input file size: 1323000b
- output file size: 661500b
$ 3at to-sdx2 --channels=1 --freq=22050 --output-type=aifc input.wav
input.wav:
- output file name: input.wav.sdx2.1ch.22050hz.aifc
- sample count: 661500
- input file size: 1323000b
- output file size: 661500b
$ 3at from-sdx2 --channels=1 --freq=22050 --output-type=wav input.wav.sdx2.1ch.22050hz.raw
orig.wav.sdx2.1ch.22050hz.raw:
- output file name: orig.wav.sdx2.1ch.22050hz.raw.wav
- sample count: 661500
- input data size: 661500b
- output data size: 1323000b
```


## FFmpeg / FFplay Examples

Rather than duplicate effort and place other format encoding/decoding
into `3at` here are some examples to encode audio using FFmpeg for
audio codecs and formats which can be used on the 3DO.


### Convert to uncompressed AIFF signed 16bit bigendian

```
ffmpeg -i input.file -ar 22050 -c:a pcm_s16be output.aiff"
```


### Convert to uncompressed AIFF signed 8bit

```
ffmpeg -i input.file -ar 22050 -c:a pcm_s8 output.aiff"
```


### Convert to uncompressed raw signed 16bit bigendian

Raw files can be useful if you want to create multiple samples at
runtime from the same file.

```
ffmpeg -i input.file -ar 22050 -f s16be -acodec pcm_s16be output.raw"
```

### Convert to uncompressed raw signed 8bit

```
ffmpeg -i input.file -ar 22050 -f s8 -acodec pcm_s8 output.raw"
```


### Play raw SDX2 file

```
$ ffplay -hide_banner -autoexit -f u8 -acodec sdx2_dpcm -ac 1 -ar 22050 input.wav.sdx2.1ch.22050hz.raw
[u8 @ 0x7f78a4000c40] Estimating duration from bitrate, this may be inaccurate
Input #0, u8, from 'orig.wav.sdx2.1ch.22050hz.raw':
Duration: 00:00:30.00, bitrate: 176 kb/s
Stream #0:0: Audio: pcm_u8, 22050 Hz, 1 channels, u8, 176 kb/s
```

### Play raw Intel DVI / ADP4 file

```
$ ffplay -hide_banner -autoexit -f u8 -acodec adpcm_ima_ws -ac 1 -ar 22050 input.wav.sdx2.1ch.22050hz.raw
[u8 @ 0x7f78a4000c40] Estimating duration from bitrate, this may be inaccurate
Input #0, u8, from 'orig.wav.sdx2.1ch.22050hz.raw':
Duration: 00:00:30.00, bitrate: 176 kb/s
Stream #0:0: Audio: pcm_u8, 22050 Hz, 1 channels, u8, 176 kb/s
```


## Documentation

* https://3dodev.com
* https://3dodev.com/documentation/development/opera/pf25/ppgfldr/mgsfldr/mpgfldr/03mpg004
* [IMA_ADPCM.pdf (Intel DVI/ADP4)](docs/IMA_ADPCM.pdf)
* [Patent US005617506A - Method for Communicating a Value Over a
Transmission Medium and for Decoding Same (SDX2)](docs/pat5617506_-_method_for_communicating_a_value_over_a_transmission_medium_and_for_decoding_same.pdf)
* [AIFF-1.3.pdf](docs/AIFF-1.3.pdf)
* [AIFF-C.9.26.91.pdf](docs/AIFF-C.9.26.91.pdf)


## Links

* 3DO Dev Repo: https://3dodev.com
* 3DO Disc Tool: https://github.com/trapexit/3dt
* 3DO Image Tool: https://github.com/trapexit/3it
* 3DO Compression Tool: https://github.com/trapexit/3ct
* 'Modern' 3DO DevKit: https://github.com/trapexit/3do-devkit


## Donations / Sponsorship

If you find 3at useful please consider supporting its ongoing
development.

https://github.com/trapexit/support
11 changes: 11 additions & 0 deletions buildtools/docker-make-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

apk update
apk add \
make \
g++ \
mingw-w64-gcc \
s6

cd /src
s6-applyuidgid -u "${PUID}" -g "${PGID}" make release-base
Binary file added docs/AIFF-1.3.pdf
Binary file not shown.
Binary file added docs/AIFF-C.9.26.91.pdf
Binary file not shown.
Binary file added docs/IMA_ADPCM.pdf
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 400a4db

Please sign in to comment.