Skip to content

Commit

Permalink
Add tools for audio conversion and cleanup some binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
hansbonini committed Jul 12, 2024
1 parent 9c85ac1 commit 8183689
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
audio/pcm/*.wav
audio/pcm/*.pcm
build/*
gfx/nemesis/*.smd
gfx/segard/*.smd
rom/*
smps/*
z80/*.bin
z80/pcm_driver/*.bin

33 changes: 23 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WORKSPACE := .
AUDIO_DIR := $(WORKSPACE)/audio
BUILD_DIR := $(WORKSPACE)/build
GFX_DIR := $(WORKSPACE)/gfx
INCLUDES_DIR := $(WORKSPACE)/includes
ROM_DIR := $(WORKSPACE)/rom
TOOLS_DIR := $(WORKSPACE)/tools
Z80_DIR := $(WORKSPACE)/z80
Expand All @@ -18,18 +19,27 @@ RETROARCH_DIR := $(TOOLS_DIR)/RetroArch-Win64
# Tooling
ASM68K := $(TOOLS_DIR)/asm68k/asm68k.exe
ASM68K_SWITCHES ?= /m /p /k
FFMPEG := $(TOOLS_DIR)/ffmpeg/ffmpeg.exe
GO := go run
GRPDMP := $(TOOLS_DIR)/grpdmp/grpdmp.exe
SEGARD_DECOMP := $(TOOLS_DIR)/segard/decomp.go
PCM2WAV := $(TOOLS_DIR)/pcm2wav/pcm2wav.go
SHA1CHECK := $(TOOLS_DIR)/checksum/sha1.go
RETROARCH := $(RETROARCH_DIR)/retroarch.exe
RETROARCH_CORE_BLASTEM := $(RETROARCH_DIR)/cores/blastem_libretro.dll
RETROARCH_CORE_GPGX := $(RETROARCH_DIR)/cores/genesis_plus_gx_libretro.dll
RETROARCH_CORE_PICODRIVE := $(RETROARCH_DIR)/cores/picodrive_libretro.dll
SJASMPLUS := $(TOOLS_DIR)/sjasmplus/sjasmplus.exe
WAV2PCM := $(TOOLS_DIR)/wav2pcm/wav2pcm.go

all: extract build
build: z80_assemble 68k_assemble sha1
build: wav2pcm z80_assemble 68k_assemble sha1
wav2pcm:
$(GO) $(WAV2PCM) "$(AUDIO_DIR)/pcm/000138EC.wav" $(AUDIO_DIR)/pcm/000138EC.pcm 8000
$(GO) $(WAV2PCM) "$(AUDIO_DIR)/pcm/0001552C.wav" $(AUDIO_DIR)/pcm/0001552C.pcm 4000
$(GO) $(WAV2PCM) "$(AUDIO_DIR)/pcm/000173B4.wav" $(AUDIO_DIR)/pcm/000173B4.pcm 4000
$(GO) $(WAV2PCM) "$(AUDIO_DIR)/pcm/0001AFD4.wav" $(AUDIO_DIR)/pcm/0001AFD4.pcm 4000
$(GO) $(WAV2PCM) "$(AUDIO_DIR)/pcm/0001CF56.wav" $(AUDIO_DIR)/pcm/0001CF56.pcm 4000
$(GO) $(WAV2PCM) "$(AUDIO_DIR)/pcm/0001EED8.wav" $(AUDIO_DIR)/pcm/0001EED8.pcm 4000
z80_assemble:
$(SJASMPLUS) --raw="$(Z80_DIR)/sounddriver.bin" --lst="$(Z80_DIR)/sounddriver.txt" "$(Z80_DIR)/sounddriver.asm"
$(SJASMPLUS) --raw="$(Z80_DIR)/pcm_driver/pcm_driver1.bin" --lst="$(Z80_DIR)/pcm_driver/pcm_driver1.txt" "$(Z80_DIR)/pcm_driver/pcm_driver1.asm"
Expand All @@ -43,7 +53,7 @@ z80_assemble:
sha1:
$(GO) $(SHA1CHECK) "$(BUILD_DIR)/$(NAME) ($(REGION)) ($(VERSION)) [!].bin" $(SHA1)

extract: dpcm2wav segard_decomp
extract: pcm2wav segard_decomp gfx2png
segard_decomp:
$(GO) $(SEGARD_DECOMP) "$(ROM_DIR)/$(ROM_$(REGION)_$(VERSION))" $(GFX_DIR)/segard/00024000.smd 0x00024000 # Game Font
$(GO) $(SEGARD_DECOMP) "$(ROM_DIR)/$(ROM_$(REGION)_$(VERSION))" $(GFX_DIR)/segard/00027DDA.smd 0x00027DDA # Stage 1 background elements
Expand Down Expand Up @@ -93,13 +103,16 @@ segard_decomp:
$(GO) $(SEGARD_DECOMP) "$(ROM_DIR)/$(ROM_$(REGION)_$(VERSION))" $(GFX_DIR)/segard/0007F00E.smd 0x0007F00E # Bolts
$(GO) $(SEGARD_DECOMP) "$(ROM_DIR)/$(ROM_$(REGION)_$(VERSION))" $(GFX_DIR)/segard/0007F4C6.smd 0x0007F4C6 # Game Over
$(GO) $(SEGARD_DECOMP) "$(ROM_DIR)/$(ROM_$(REGION)_$(VERSION))" $(GFX_DIR)/segard/0007F8B6.smd 0x0007F8B6 # Font
dpcm2wav:
$(FFMPEG) -y -f u8 -ar 8000 -ac 1 -i "$(AUDIO_DIR)/pcm/000138EC.pcm" -c:a pcm_u8 $(AUDIO_DIR)/pcm/000138EC.wav
$(FFMPEG) -y -f u8 -ar 4000 -ac 1 -i "$(AUDIO_DIR)/pcm/0001552C.pcm" -c:a pcm_u8 $(AUDIO_DIR)/pcm/0001552C.wav
$(FFMPEG) -y -f u8 -ar 4000 -ac 1 -i "$(AUDIO_DIR)/pcm/000173B4.pcm" -c:a pcm_u8 $(AUDIO_DIR)/pcm/000173B4.wav
$(FFMPEG) -y -f u8 -ar 4000 -ac 1 -i "$(AUDIO_DIR)/pcm/0001AFD4.pcm" -c:a pcm_u8 $(AUDIO_DIR)/pcm/0001AFD4.wav
$(FFMPEG) -y -f u8 -ar 4000 -ac 1 -i "$(AUDIO_DIR)/pcm/0001CF56.pcm" -c:a pcm_u8 $(AUDIO_DIR)/pcm/0001CF56.wav
$(FFMPEG) -y -f u8 -ar 4000 -ac 1 -i "$(AUDIO_DIR)/pcm/0001EED8.pcm" -c:a pcm_u8 $(AUDIO_DIR)/pcm/0001EED8.wav
pcm2wav:
$(GO) $(PCM2WAV) "$(AUDIO_DIR)/pcm/000138EC.pcm" $(AUDIO_DIR)/pcm/000138EC.wav 8000
$(GO) $(PCM2WAV) "$(AUDIO_DIR)/pcm/0001552C.pcm" $(AUDIO_DIR)/pcm/0001552C.wav 4000
$(GO) $(PCM2WAV) "$(AUDIO_DIR)/pcm/000173B4.pcm" $(AUDIO_DIR)/pcm/000173B4.wav 4000
$(GO) $(PCM2WAV) "$(AUDIO_DIR)/pcm/0001AFD4.pcm" $(AUDIO_DIR)/pcm/0001AFD4.wav 4000
$(GO) $(PCM2WAV) "$(AUDIO_DIR)/pcm/0001CF56.pcm" $(AUDIO_DIR)/pcm/0001CF56.wav 4000
$(GO) $(PCM2WAV) "$(AUDIO_DIR)/pcm/0001EED8.pcm" $(AUDIO_DIR)/pcm/0001EED8.wav 4000
gfx2png:
$(GRPDMP) $(GFX_DIR)/00009FB4.smd $(GFX_DIR)/00009FB4.png -p $(INCLUDES_DIR)/palettes/00009F6C.bin


test-blastem:
$(RETROARCH) --libretro=$(RETROARCH_CORE_BLASTEM) "$(BUILD_DIR)/$(NAME) ($(REGION)) ($(VERSION)) [!].bin" --verbose
Expand Down
Binary file renamed audio/pcm/000138EC.pcm → audio/pcm/000138EC.wav
Binary file not shown.
Binary file renamed audio/pcm/0001552C.pcm → audio/pcm/0001552C.wav
Binary file not shown.
Binary file renamed audio/pcm/000173B4.pcm → audio/pcm/000173B4.wav
Binary file not shown.
Binary file renamed audio/pcm/0001AFD4.pcm → audio/pcm/0001AFD4.wav
Binary file not shown.
Binary file renamed audio/pcm/0001CF56.pcm → audio/pcm/0001CF56.wav
Binary file not shown.
Binary file renamed audio/pcm/0001EED8.pcm → audio/pcm/0001EED8.wav
Binary file not shown.
Binary file added gfx/00009FB4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module tools

go 1.22.4

require (
github.com/go-audio/audio v1.0.0
github.com/go-audio/wav v1.1.0
)

require github.com/go-audio/riff v1.0.0 // indirect
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/go-audio/audio v1.0.0 h1:zS9vebldgbQqktK4H0lUqWrG8P0NxCJVqcj7ZpNnwd4=
github.com/go-audio/audio v1.0.0/go.mod h1:6uAu0+H2lHkwdGsAY+j2wHPNPpPoeg5AaEFh9FlA+Zs=
github.com/go-audio/riff v1.0.0 h1:d8iCGbDvox9BfLagY94fBynxSPHO80LmZCaOsmKxokA=
github.com/go-audio/riff v1.0.0/go.mod h1:l3cQwc85y79NQFCRB7TiPoNiaijp6q8Z0Uv38rVG498=
github.com/go-audio/wav v1.1.0 h1:jQgLtbqBzY7G+BM8fXF7AHUk1uHUviWS4X39d5rsL2g=
github.com/go-audio/wav v1.1.0/go.mod h1:mpe9qfwbScEbkd8uybLuIpTgHyrISw/OTuvjUW2iGtE=
Binary file added includes/palettes/00009F6C.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions includes/palettes/00009F6C.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
00000000 0EC0 0EA0 0E80 0E60 0E40+ pal_9F6C: dc.w $EC0, $EA0, $E80, $E60, $E40, $E20, $E00, $C00, $A00
00000012 ; DATA XREF: draw_segalogo+DC o
00000012 0800 0600 0800 0A00 0C00+ dc.w $800, $600, $800, $A00, $C00, $E00, $E20, $E40, $E60
00000024 0E80 0EA0 dc.w $E80, $EA0
Binary file added tools/grpdmp/grpdmp.exe
Binary file not shown.
Binary file removed tools/pcm2dpcm/pcm2dpcm.exe
Binary file not shown.
66 changes: 66 additions & 0 deletions tools/pcm2wav/pcm2wav.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package main

import (
"encoding/binary"
"fmt"
"io"
"log"
"os"
"strconv"

"github.com/go-audio/audio"
"github.com/go-audio/wav"
)

func main() {
pcm_src := os.Args[1]
wav_dest := os.Args[2]
freq, _ := strconv.ParseInt(os.Args[3], 10, 0)

in, err := os.Open(pcm_src)
if err != nil {
log.Fatal(err)
}

out, err := os.Create(wav_dest)
if err != nil {
log.Fatal(err)
}
defer out.Close()

fmt.Print(int(freq))

e := wav.NewEncoder(out, int(freq), 8, 1, 1)

audioBuf, err := newAudioIntBuffer(in, int(freq))
if err != nil {
log.Fatal(err)
}

if err := e.Write(audioBuf); err != nil {
log.Fatal(err)
}
if err := e.Close(); err != nil {
log.Fatal(err)
}
}

func newAudioIntBuffer(r io.Reader, freq int) (*audio.IntBuffer, error) {
buf := audio.IntBuffer{
Format: &audio.Format{
NumChannels: 1,
SampleRate: int(freq),
},
}
for {
var sample int8
err := binary.Read(r, binary.LittleEndian, &sample)
switch {
case err == io.EOF:
return &buf, nil
case err != nil:
return nil, err
}
buf.Data = append(buf.Data, int(sample))
}
}
Binary file removed tools/superfamiconv/superfamiconv.exe
Binary file not shown.
72 changes: 72 additions & 0 deletions tools/wav2pcm/wav2pcm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"bufio"
"log"
"os"
"strconv"

"github.com/go-audio/audio"
"github.com/go-audio/wav"
)

func main() {
wav_src := os.Args[1]
pcm_dest := os.Args[2]
freq, _ := strconv.ParseInt(os.Args[3], 10, 0)

in, err := os.Open(wav_src)
if err != nil {
log.Fatal(err)
}

out, err := os.Create(pcm_dest)
if err != nil {
log.Fatal(err)
}
defer out.Close()

e := wav.NewDecoder(in)

bfo := bufio.NewWriter(out)
buf := &audio.IntBuffer{
Format: &audio.Format{
NumChannels: 1,
SampleRate: int(freq),
},
Data: make([]int, 2048),
SourceBitDepth: 8,
}
chunk := make([]byte, 2048)

err = e.FwdToPCM()
if err != nil {
log.Fatal(err)
}

n, err := e.PCMBuffer(buf)
if err != nil {
log.Fatal(err)
}
for n > 0 {
k := 0
p := 0
for i := 0; i < n; i++ {
chunk[k] = byte(buf.Data[p])
k++
p++
}

_, err = bfo.Write(chunk[0:k])
if err != nil {
log.Fatal(err)
}

n, err = e.PCMBuffer(buf)
if err != nil {
log.Fatal(err)
}
}
bfo.Flush()

}
Binary file removed z80/pcm_driver/pcm_driver1.bin
Binary file not shown.
Binary file removed z80/pcm_driver/pcm_driver2.bin
Binary file not shown.
Binary file removed z80/pcm_driver/pcm_driver3.bin
Binary file not shown.
Binary file removed z80/pcm_driver/pcm_driver4.bin
Binary file not shown.
Binary file removed z80/pcm_driver/pcm_driver5.bin
Binary file not shown.
Binary file removed z80/pcm_driver/pcm_driver6.bin
Binary file not shown.
Binary file removed z80/sounddriver.bin
Binary file not shown.

0 comments on commit 8183689

Please sign in to comment.