Skip to content

Commit

Permalink
better docs for new in-AMY load sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bwhitman committed Oct 15, 2024
1 parent b0e3dda commit de82d54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 36 deletions.
2 changes: 1 addition & 1 deletion amy
12 changes: 7 additions & 5 deletions docs/music.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,26 @@ s.note_on(40, 1.0)
s.note_off(40) # looped instruments require a note_off to stop
```

You can load your own samples into Tulip. Take any .wav file and [load it onto Tulip.](getting_started.md#transfer-files-between-tulip-and-your-computer) Now, load it in as a `CUSTOM` PCM patch:
You can load your own samples into Tulip. Take any .wav file and [load it onto Tulip.](getting_started.md#transfer-files-between-tulip-and-your-computer) Now, load it in as a PCM patch:

```python
patch = tulip.load_sample('sample.wav')
s = midi.OscSynth(wave=amy.CUSTOM, patch=patch)
amy.load_sample('sample.wav', patch=50)
s = midi.OscSynth(wave=amy.PCM, patch=50)
s.note_on(60, 1.0)
```

You can also load PCM patches with looped segments if you have their loopstart and loopend parameters (these are often stored in the WAVE metadata. If the .wav file has this metadata, we'll parse it. The example file `/sys/ex/vlng3.wav` has it. You can also provide the metadata directly.) To indicate looping, use `feedback=1`.

```python
patch = tulip.load_sample("/sys/ex/vlng3.wav") # loads wave looping metadata
s = midi.OscSynth(wave=amy.CUSTOM, patch=patch, feedback=1, num_voices=1)
amy.load_sample("/sys/ex/vlng3.wav", patch=50) # loads wave looping metadata
s = midi.OscSynth(wave=amy.CUSTOM, patch=50, feedback=1, num_voices=1)
s.note_on(60, 1.0) # loops
s.note_on(55, 1.0) # loops
s.note_off(55) # stops
```

You can unload samples from RAM with `amy.unload_sample(patch_number)`.

## Modify Juno-6 patches programatically

We showed above how to `run('juno6')` to see a Juno-6 editor. But if you want your code to change the patches, you can do it yourself with:
Expand Down
16 changes: 7 additions & 9 deletions docs/tulip_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,24 +439,22 @@ amy.send(voices='0', load_patch=101, note=50, vel=1, client=2) # just a certain
alles.local() # turns off mesh mode and goes back to local mode
```

To load your own WAVE files as samples, use `tulip.load_sample`:
To load your own WAVE files as samples, use `amy.load_sample`:

```python
# To save space / RAM, you may want to downsample your WAVE files to 11025 or 22050Hz. We detect SR automatically.
patch = tulip.load_sample("flutea4.wav") # samples are converted to mono if they are stereo
amy.load_sample("flutea4.wav", patch=50) # samples are converted to mono if they are stereo. patch # can be anything

# You can optionally tell us the loop start and end point (in samples), and base MIDI note of the sample.
# We can detect this in WAVE file metadata if it exists! (Many sample packs include this.)
patch = tulip.load_sample("flutea4.wav", midinote=81, loopstart=1020, loopend=1500)
amy.load_sample("flutea4.wav", midinote=81, loopstart=1020, loopend=1500, patch=50)

# The patch number can now be used in the custom Tulip memory PCM sample player.
# It has all the features of the AMY's PCM wave type.
amy.send(osc=20, wave=amy.CUSTOM, patch=patch, vel=1, note=50)
# The patch number can now be used in AMY's PCM sample player.
amy.send(osc=20, wave=amy.PCM, patch=50, vel=1, note=50)

# You can load up to 32 custom PCM patches. Be careful of memory use. load_sample will return -1 if there's no more room.
# You can unload already allocated patches:
tulip.unload_patch(patch) # frees the RAM and the patch slot
tulip.unload_patch() # frees all allocated PCM patches
amy.unload_sample(patch) # frees the RAM and the patch slot
amy.reset() # frees all allocated PCM patches
```

To send signals over CV on Tulip CC (hardware only):
Expand Down
21 changes: 0 additions & 21 deletions tulip/shared/py/tulip.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,27 +660,6 @@ def wifi(ssid, passwd, wait_timeout=10):
return ip()


def load_sample(wavfile, midinote=0, loopstart=0, loopend=0):
import wave
w = wave.open(wavfile, 'r')
f = w.readframes(w.getnframes())
if(w.getnchannels()>1):
# de-interleave and just choose the first channel
f = bytes([f[j] for i in range(0,len(f),4) for j in (i,i+1)])
if(loopstart==0):
if(hasattr(w,'_loopstart')):
loopstart = w._loopstart
if(loopend==0):
if(hasattr(w,'_loopend')):
loopend = w._loopend
if(midinote==0):
if(hasattr(w,'_midinote')):
midinote = w._midinote
else:
midinote=60
return call_load_sample(f, w.getframerate(), midinote, loopstart, loopend)


def tar_create(directory):
import utarfile
t = utarfile.TarFile(directory+".tar", 'w')
Expand Down

0 comments on commit de82d54

Please sign in to comment.