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 https://github.com/ckald/Samplicity/issues/11 #12

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: https://gumroad.com/l/hGYGh
16 changes: 12 additions & 4 deletions samplicity/samplicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import math
import shutil
import numpy as np
from random import random
from scikits.audiolab import Sndfile, play

from common import wrap, pad_name, path_insensitive

VERSION = 'Samplicity v' + __version__

OPTIONS = {}
Expand Down Expand Up @@ -66,8 +66,8 @@ def read_wav(self, sample_path):
channels = sample.channels
encoding = sample.encoding
frames_count = sample.nframes

frames = sample.read_frames(frames_count, dtype=np.float32)

sample.close()
del sample

Expand Down Expand Up @@ -221,10 +221,12 @@ def __init__(self, file):
for i, region in enumerate(self.regions):
if self.is_region_used(i):
region.load_audio()
region['delta_sample'] = tempdir + str(time.clock()) + '.dat'
region['delta_sample'] = tempdir + str(random()) + '.dat'
region['sample_length'] = len(region['sample_data']) * region['channels']
region['sample_data'].T.flatten().tofile(region['delta_sample'], format='f')

region['sample_data'] = ''

del region['sample_data']
used_regions.append(region)
else:
Expand Down Expand Up @@ -357,7 +359,11 @@ def write_regions_meta(self):
for region in self.regions:
self.output_file.write(struct.pack(
'i', region['sample_bittype'] * region['sample_length'])) # sample length
self.output_file.write(struct.pack('2i', 0, 0)) # sample loop start and end
loopstart = region['sample_bittype'] * int(region['loop_start']) if 'loop_start' in region else 0
loopend = region['sample_bittype'] * int(region['loop_end']) if 'loop_end' in region else 0
loopend -= loopstart # loop-length

self.output_file.write(struct.pack('2i', loopstart*2, loopend*2)) # sample loop start and end
# volume
volume = 255
if 'volume' in region:
Expand All @@ -368,6 +374,8 @@ def write_regions_meta(self):
self.output_file.write(struct.pack('B', volume))

self.output_file.write(struct.pack('b', int(region['tune']))) # finetune (signed!)
if loopstart:
region['sample_type'] = 0b1100101
self.output_file.write(struct.pack('b', region['sample_type'])) # sample type

#panning (unsigned!)
Expand Down