Skip to content

Commit

Permalink
add: export loop point in smpl chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanTaquet committed Oct 25, 2016
1 parent 54c777d commit 047df9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Oe2sSLE_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ def export_sample(self):
if filename:
try:
with open(filename, 'wb') as f:
e2s_sample.write(f)
e2s_sample.write(f, export_smpl=True)
except Exception as e:
tk.messagebox.showwarning(
"Export sample as",
Expand Down Expand Up @@ -2090,7 +2090,7 @@ def fct():
while not ok:
try:
with open(filename, 'wb') as f:
e2s_sample.write(f)
e2s_sample.write(f, export_smpl=True)
except Exception as e:
tk.messagebox.showwarning(
"Export sample as",
Expand Down
20 changes: 19 additions & 1 deletion e2s_sample_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,30 @@ def read(self, file):
"Expected {} chunk, got {}; ignored.".format(b"RIFF", self.header.id))
self.RIFF = RIFF.Form(file,self.header,registeredForms={b'WAVE':RIFF_korgWAVEChunkList})

def write(self, file, _do_clean=True):
def write(self, file, export_smpl=False, _do_clean=True):
sample = self

if _do_clean:
sample = self.get_clean_copy()

esli = sample.get_esli()
fmt = sample.get_fmt()
uid = 0

if export_smpl and esli.OSC_LoopStartPoint_offset < esli.OSC_EndPoint_offset:
smpl = RIFF_smpl()
smpl.samplePeriod = int(round(1./esli.samplingFreq*10.**9))
loop = smpl.add_loop()
loop.identifier = uid # not adding a cue point for the loop
#loop.type = 0 # loop forward
loop.start = (esli.OSC_StartPoint_address + esli.OSC_LoopStartPoint_offset)//fmt.blockAlign
loop.end = (esli.OSC_StartPoint_address + esli.OSC_EndPoint_offset)//fmt.blockAlign
#loop.fraction = 0
#loop.playCount = 0 # infinite loop
smpl_chunk = RIFF.Chunk(header=RIFF.ChunkHeader(id=b'smpl'),data=smpl)
sample.RIFF.chunkList.chunks.append(smpl_chunk)
uid += 1

sample.update_header()
sample.header.write(file)
sample.RIFF.write(file)
Expand Down

0 comments on commit 047df9e

Please sign in to comment.