Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Local .wav generation script #23

Merged
merged 2 commits into from
Apr 8, 2024
Merged
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
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
## About
Generate valid WAV files in Cairo

## Features
- [x] Output WAV file
- [x] Handle bit-depths (4, 8, 16, 32)
- [ ] Handle multiple/stereo channels
- [x] Generate square wave form
- [x] Generate sawtooth wave forms
- [x] Generate triangle wave forms
- [ ] Generate sine wave forms
- [ ] Generate an instrument (see [Koji](https://github.com/cienicera/Koji))
- [x] Play [Koji](https://github.com/cienicera/Koji) notes
- [ ] Play [Koji midi tracks](https://github.com/cienicera/Koji)
- [ ] Generate an 4/8-bit low sample rate sound pack (kick, bass, snare, hi-hat)
- [X] Play short melodies


## Local testing:
```bash
scarb test -f get_notes > tmp/test;
python scripts/data_to_wave.py tmp/test;
scarb test -f get_notes > tmp/test
python scripts/data_to_wave.py tmp/test
mplayer tmp/test.wav
```

Expand All @@ -17,7 +32,6 @@ python scripts/get_notes.py
mplayer tmp/out.wav
```


## Resources
- [WAVE PCM File format](http://soundfile.sapp.org/doc/WaveFormat/)
- Unix: `man sox`, `ffprobe file.wave`
Expand Down
8 changes: 5 additions & 3 deletions scripts/data_to_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
with open(input_file) as f:
data = f.read().splitlines()

# plt.plot("".join(data[5:-3]))
# plt.show()
i = 0
while i < len(data):
if data[i].startswith('RIFF'): break
i+=1

data_bytes = "".join(data[5:-3])
data_bytes = "".join(data[i:-3])
data_bytes = data_bytes.encode('utf-8')
data_bytes = data_bytes.decode('unicode-escape')
data_bytes = data_bytes.encode('ISO-8859-1')
Expand Down
Loading