diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..f744573 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: https://gumroad.com/l/hGYGh diff --git a/samplicity/samplicity.py b/samplicity/samplicity.py index 9f941d4..3337ae3 100644 --- a/samplicity/samplicity.py +++ b/samplicity/samplicity.py @@ -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 = {} @@ -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 @@ -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: @@ -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: @@ -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!)