Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CFLAGS = -Wall -O2
LDLIBS = -lm

PYTHON = python3
PLAY = ffplay -v fatal -nodisp -autoexit -f s32le -ar 48000 -ch_layout mono -i pipe:0
PLAY = ffplay -v fatal -nodisp -autoexit -f s32le -ar 48000 -ch_layout mono

effects = flanger echo fm phaser discont am distortion tube growlingbass
flanger_defaults = 0.6 0.6 0.6 0.6
Expand All @@ -22,7 +22,7 @@ default:
@echo "Pick one of" $(effects)

play: output.raw
$(PLAY) < output.raw
$(PLAY) $<

visualize: input.raw output.raw magnitude.raw outmagnitude.raw
$(PYTHON) visualize.py input.raw output.raw magnitude.raw outmagnitude.raw
Expand All @@ -33,7 +33,7 @@ visualize: input.raw output.raw magnitude.raw outmagnitude.raw
$(effects): input.raw convert
./convert $@ $($@_defaults) input.raw output.raw
ffmpeg -y -v fatal -f s32le -ar 48000 -ac 1 -i output.raw -f mp3 $@.mp3
$(PLAY) < output.raw
$(PLAY) output.raw

convert.o: CFLAGS += -ffast-math -fsingle-precision-constant -Wfloat-conversion # -Wdouble-promotion
convert.o: $(HEADERS)
Expand All @@ -53,7 +53,11 @@ input.raw: BassForLinus.mp3
ffmpeg -y -v fatal -i $< -f s32le -ar 48000 -ac 1 $@

SeymourDuncan: convert
for i in ~/Wav/Seymour\ Duncan/*; do ffmpeg -y -v fatal -i "$$i" -f s32le -ar 48000 -ac 1 pipe:1 | ./convert phaser $(phaser_defaults) | $(PLAY) ; done
@if [ ! -d ~/Wav/Seymour\ Duncan ]; then echo "Directory ~/Wav/Seymour Duncan not found"; exit 0; fi
for i in ~/Wav/Seymour\ Duncan/*; do \
[ -f "$$i" ] || continue; \
ffmpeg -y -v fatal -i "$$i" -f s32le -ar 48000 -ac 1 pipe:1 | ./convert phaser $(phaser_defaults) | $(PLAY) -i pipe:0 ; \
done

gensin.h: gensin
./gensin > gensin.h
Expand Down
76 changes: 75 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The digital [RP2354 and TAC5112-based guitar
pedal](https://github.com/torvalds/GuitarPedal) actually does work, even
if I'm not thrilled about some of my analog interface choices (ie the
pots in particular, and I'm growing to hate the clicky footswitch even
potentiometers in particular, and I'm growing to hate the clicky footswitch even
if I do love how it also doubles as a boot selector switch for
programming).

Expand Down Expand Up @@ -40,3 +40,77 @@ much -- than I do about python. It started out as my typical "google
and do the monkey-see-monkey-do" kind of programming, but then I cut out
the middle-man -- me -- and just used Google Antigravity to do the audio
sample visualizer.


## Building and Running

### Dependencies

- GCC
- FFmpeg and FFplay (for audio format conversion and playback)
- Python 3 with NumPy and Matplotlib (for visualization only)

On macOS with Homebrew:
```
brew install ffmpeg
pip3 install numpy matplotlib
```

On Debian/Ubuntu:
```
apt install gcc ffmpeg python3-numpy python3-matplotlib
```

Or install Python dependencies via:
```bash
pip install -r requirements.txt
```

Or using [uv](https://docs.astral.sh/uv/):
```bash
uv sync
```

### Build

Compile the audio processor:
```
make convert
```

### Running Effects

The workflow converts an MP3 to raw 48kHz mono 32-bit audio, processes it through an effect, and plays the result.

Available effects: `flanger`, `echo`, `fm`, `am`, `phaser`, `discont`, `distortion`, `tube`, `growlingbass`

To run an effect (uses `BassForLinus.mp3` as input by default):
```
make flanger
make echo
make distortion
# etc.
```

This will process the audio, save the output as `<effect>.mp3`, and play it back.

To use your own input file:
```
ffmpeg -y -i yourfile.mp3 -f s32le -ar 48000 -ac 1 input.raw
./convert flanger 0.6 0.6 0.6 0.6 input.raw output.raw
ffmpeg -y -f s32le -ar 48000 -ac 1 -i output.raw output.mp3
```

### Visualization

To visualize the input/output waveforms:
```
make visualize
```

### Tests

Run the unit tests:
```
make test
```
10 changes: 9 additions & 1 deletion convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void *modify_pots(void *arg)
if (n <= 0)
return NULL;
switch (buf[0]) {
case 'p':
case 'p': {
unsigned int idx = buf[1]-'0';
unsigned int d1 = buf[2]-'0';
unsigned int d2 = buf[3]-'0';
Expand All @@ -98,6 +98,7 @@ static void *modify_pots(void *arg)
pots[idx] = (d1*10+d2) / 100.0;
eff->describe(pots);
break;
}
}
}
}
Expand Down Expand Up @@ -125,6 +126,8 @@ int main(int argc, char **argv)
float val = strtof(arg, &endptr);
if (endptr != arg) {
if (potnr < 4) {
if (!isfinite(val))
val = 0.5;
pots[potnr++] = val;
continue;
}
Expand Down Expand Up @@ -184,6 +187,11 @@ int main(int argc, char **argv)
if (output < 0)
output = 1;

if (!eff) {
fprintf(stderr, "No effect specified\n");
exit(1);
}

#ifdef F_SETPIPE_SZ
// Limit the output buffer size if we are
// writing to a pipe. At least on Linux,
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "audionoisefork"
version = "0.1.0"
description = "A Python toolkit to visualize noise characteristics in audio signals"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"matplotlib>=3.10.8",
"numpy>=2.4.1",
]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
matplotlib
Loading