Skip to content

Commit

Permalink
cleared up bug that caused script to fail in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
richrath committed Oct 15, 2024
1 parent 0281bef commit 120ed7d
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 115 deletions.
66 changes: 20 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# wavetabler
Create wavetables for Serum, Vital, etc from any short wav file.
Create wavetables for Serum, Vital, etc from any short mono wav file

## description
wavetabler creates 2048 sample X 256 frames wavetables that can be imported as fixed size 2048 in Serum's wavetable editor import screen. Have not tested on other synths but should be able to figure it out if you rtm for that synth I think.

Wavetabler creates 2048 sample X 256 frames wavetables that can be imported as fixed size 2048 in Serum's wavetable editor import screen. Have not tested on other synths but should be able to figure it out if you rtm for that synth I think.
This is an alpha release. It works for me, ymmv. I have a Linux and windows box and have tested it on both.

This is an alpha release. It works for me, ymmv. I have a Linux and a Windows box and have tested it on both.
My packaging skills are not there yet, so for now, download or clone the repository and copy the top folder (wavetabler) to where you wnat to run it. if you cloned it, you definitely want to work form a dedicated separate folder outside your git folder because we will create and delete tons of files. CD into wavetabler folder. There you will find the following tree:

To download, click where it says "code" [on the github page](https://github.com/rcrath/wavetabler) just above and to the right of the file listing and download the zip file.

Move the zip file to where you want to run it, referably outside the reach of cloud services like dropbox and onedrive since the scripts generate scads of tmp files and cloud services try to grab them all and interfere with the script.

Unzip the file and then navigate into the wavetabler folder. There you will find the following tree:
from within wavetabler, open a command prompt,

```
wavetabler
Expand Down Expand Up @@ -61,64 +58,41 @@ wavetabler

## setup

You need to set the project up first, Make sure you have python installed. If the script fails, install [python 3.11.9](https://www.python.org/downloads/release/python-3119/), even if you already have another version of python installed. When installing, no need to set it as your main python, just install it as usual and let it go. The setpy commands will take care of using this version.

On all platforms, you will need to open a terminal and navigate to the wavetabler folder you just unzipped.
You need to set the project up first, Make sure you have python installed. If the script fails, find the python 3.11 version from the python site and install that, even if you already have another version of python installed. when installing, no need to set it as your main python, just install it as usual and let it go. the setpy commands will take care of using this version.

### Windows

From your command prompt in the wavetabler folder, run:

from your command prompt in the wavetabler folder, run:
`setpy`

You only need to do this once.

### MacOS (untested) or Linux

Make your two launchers executable. From a command prompt in the wavetablers folder, you only need to enter this once:

`chmod +x *.sh`

Then enter

`./setpy.sh`

from a command prompt in the wavetabler folder run `chmod +x setpy.sh)` and then `./setpy.sh`
You only need to do this once.

Possible problem: if you are on Manjaro, Arch, or any Arch-derived Linux that uses Pacman, you might have to run the following command after setpy.sh:

`pip install numpy scipy librosa resampy soundfile pydub matplotlib pandas tabulate`

because they won't install from the script.


## warning:

pause dropbox or any other cloud serive while running the script or run put the wavetabler folder outside of the dropbox folder. If you get a permissions error, that is usually the cause.
pause dropbox or any other cloud serive while running the script or run it outside of the dropbox folder. If you get a permissions error, that is usually the cause.

## Test Run

run a test on the example input files:

type `wvtbl` on windows, (`./wvtbl.sh` on Mac/Linux) from you command prompt and choose one or both of the two sample files. When it asks you to accept defaults, just hit enter, and after a little processing, you should have a shiny new 2048 sample per wwavecycle, 256 frame wavetable in the wavetables folder
### Windows:
type `wvtbl` from you command prompt and choose one of the two sample files. when it asks you to accept defaults, just hit enter, and after a little processing, you should have a shiny new 2048 sample per wwavecycle, 256 frame wavetable in the wavetables folder.

## Creating your own wavetables
### Mac/:inux:
you have to set the permissions for it to execute the first time:
`chmod +x wvtbl.sh)` and then `./wvtbl.sh` runs it
``

Copy some short wav files you want to convert to wavetables to the `wavetabler/imput` folder.
## Creating your own wavetables

- They can be any sample rate or bit depth between `44.1kHz` and `192kHz`, `16 bit` to `32 bit float`. Higher bit depths will help with the quality of the results.
- Stereo files in the input folder get converted to mono, so make sure you keep a copy somewhere.
- While you can load any length file, *anything more than ten seconds or so will take an inordinate amount of time*, so your best bet is to pick a 2-10 second slice.
Copy some samples you want to convert to wavetables to the `wavetabler/imput` folder. They can be any sample rate or bit depth between `44.1kHz` and `192kHz`, `16 bit` to `32 bit float`. Higher sample rates and bit depths will help with the quality of the results. For now the files must be mono. While you can load any length file, *anything more than ten seconds or so will take an inordinate amount of time*, so your best bet is to pick a 2-10 second slice, make sure you save it to mono.

run `wvtbl` on windows or ./wvrbl.sh on MacOS or Linux and select from the attending file menu. Once you select a file or files, accept defaults, and look in your `wavetables` subfolder for your finished wavetables nce the script finishes.
run `wvtbl` and select from the attending file menu. accept defaults, and look in your `wavetables` folder for your finished wavetables.

## Loading into Serum (and other wavetable synths)
I only have instructions for Serum ATM: In Serum, click on
one of the wavetable edit icons in the oscillator section. From the import menu choose `import-fixed-frame` pick a wavetable and enter 2048 when prompted. Your oscillator will load up the wavetable you select from the wavetables subfolder.
I only have instructions for Serum ATM: in serum click on one of the wavetable edit icons in the oscillator section. from the import menu choose `import-fixed-frame` and enter 2048. Your oscillator will load up the wavetable you select from the output folder.

## Advanced
- **known isssue**, in the last section, you get a choice of fitting the wavetable, chopping it into arbitrary chunks, or picking a chunk. There is an issue with the "pick" function where the selection does not start at a zero crossing, throwing the whole selection off. hang tight, will fix it soon, but for now avoid.

TBD. If you do not accept defaults, you get an advanced series of prompts, which can help if your wavetables are not to your liking. I have tried to make the choices clear in the script and will later provide some details about how to choose among the options.

- **known isssue**, in the last section, you get a choice of fitting the wavetable, chopping it into arbitrary chunks, or picking a chunk. There is an issue with the "pick" function where the selection does not start at a zero crossing, throwing the whole selection off. Hang tight, will fix it soon, but for now avoid.

3 changes: 2 additions & 1 deletion setpy.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

python3.11 -m venv wvtbl_win
python -m venv wvtbl_win
call wvtbl_win\Scripts\activate && pip install -r requirements.txt

REM pip install numpy scipy librosa resampy soundfile pydub matplotlib pandas tabulate
cls
1 change: 1 addition & 0 deletions setpy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ pip install -r requirements.txt

# Optional: You can uncomment these lines if you prefer manual installation of packages
# pip install numpy scipy librosa resampy soundfile pydub matplotlib pandas tabulate
alias wvtbl=./wvtbl.sh
Binary file added src/__pycache__/aa_common.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/b_menu.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/b_stereo2mono.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/c_upsample.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/debug.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/e_seg.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/f_sort.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/g_choose.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/h_interpolate.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/j_wvtblr.cpython-311.pyc
Binary file not shown.
Binary file added src/__pycache__/k_clean.cpython-311.pyc
Binary file not shown.
13 changes: 7 additions & 6 deletions src/a_wvtbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import k_clean
import aa_common
import shutil
import subprocess
import b_stereo2mono


def process_single_file(file_name):
Expand Down Expand Up @@ -75,17 +75,18 @@ def process_single_file(file_name):


def main():
# Call stereo2mono.py to convert any stereo files to mono in tmp/src
script_dir = os.path.dirname(os.path.abspath(__file__))
stereo2mono_path = os.path.join(script_dir, "stereo2mono.py") # Correct the path here
subprocess.run(["python", stereo2mono_path], check=True)

# Initialize settings
aa_common.global_settings = aa_common.initialize_settings()

# Run the stereo-to-mono conversion, and quit if the user opts to cancel
if not b_stereo2mono.run():
print("Exiting as per user request.")
return # Exit the script if the user cancels

# Run the menu to select the source file(s)
selected_files = b_menu.run()


# If multiple files are selected, run in batch mode
for file_name in selected_files:
process_single_file(file_name)
Expand Down
62 changes: 62 additions & 0 deletions src/b_stereo2mono.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os
import soundfile as sf
import aa_common

def is_stereo(file_path):
"""Check if the given audio file is stereo."""
try:
with sf.SoundFile(file_path) as f:
return f.channels == 2
except Exception as e:
print(f"Error checking {file_path}: {e}")
return False

def convert_to_mono(file_path):
"""Convert a stereo audio file to mono and overwrite the original file."""
try:
data, sample_rate = sf.read(file_path)
if data.ndim == 2:
# Average the left and right channels to create a mono track
mono_data = data.mean(axis=1)
sf.write(file_path, mono_data, sample_rate)
print(f"Converted {os.path.basename(file_path)} to mono.")
except Exception as e:
print(f"Error converting {file_path}: {e}")

def prompt_user():
"""Display a prompt to inform the user about the process."""
message = (
"This script converts any of the files you choose from the input folder into wavetables. "
"If you have not done so yet, place COPIES of any short wav files you wish to process in the input folder. "
"Any that are stereo will be reduced to mono first.\n"
"Proceed? (Y/n): "
)
proceed = input(message).strip().lower() or 'y'
return proceed == 'y'

def run():
if not prompt_user():
print("Operation cancelled. Exiting.")
return False # Signal to quit the main script

input_folder = aa_common.source_folder
stereo_files_found = False

# Loop through all WAV files in the input folder
for filename in os.listdir(input_folder):
if filename.endswith(aa_common.ext):
file_path = os.path.join(input_folder, filename)
if is_stereo(file_path):
stereo_files_found = True
convert_to_mono(file_path)

if stereo_files_found:
print("\nAll stereo files have been converted to mono.")
else:
print("\nNo stereo files found. Proceeding to the menu.")

return True # Signal to continue the main script


if __name__ == "__main__":
run()
62 changes: 0 additions & 62 deletions src/stereo2mono.py

This file was deleted.

Binary file added waymusic256.ico
Binary file not shown.

0 comments on commit 120ed7d

Please sign in to comment.