summaryrefslogtreecommitdiff
path: root/basetypes.py
diff options
context:
space:
mode:
authorJohn Glover <john@john-glovers-macbook.local>2010-12-21 11:25:11 +0000
committerJohn Glover <john@john-glovers-macbook.local>2010-12-21 11:25:11 +0000
commit8373f12eaf63b6db27a1848202a86aeeb15c4d26 (patch)
tree4f00a58a2d9b4939ccc3225aa76d20570d793cc2 /basetypes.py
parent3f5c5d34d99b121bb621230a918b621a9524a015 (diff)
downloadsimpl-8373f12eaf63b6db27a1848202a86aeeb15c4d26.tar.gz
simpl-8373f12eaf63b6db27a1848202a86aeeb15c4d26.tar.bz2
simpl-8373f12eaf63b6db27a1848202a86aeeb15c4d26.zip
Fixing bugs in SMSResidual.
Diffstat (limited to 'basetypes.py')
-rw-r--r--basetypes.py49
1 files changed, 42 insertions, 7 deletions
diff --git a/basetypes.py b/basetypes.py
index 09c5256..b58da34 100644
--- a/basetypes.py
+++ b/basetypes.py
@@ -352,18 +352,53 @@ class Residual(object):
"Calculate a residual signal"
def __init__(self):
- self.hop_size = 512
- self.frame_size = 2048
+ self._hop_size = 512
+ self._frame_size = 512
+
+ def residual_frame(self, synth, original):
+ "Computes the residual signal for a frame of audio"
+ raise Exception("NotYetImplemented")
- # TODO: break this up into find_residual and residual_frame
- # so that it can be streamed
def find_residual(self, synth, original):
"Calculate and return the residual signal"
+ # pad the signals if necessary
+ if len(synth) % self._hop_size != 0:
+ synth = np.hstack((synth, np.zeros(self._hop_size - (len(synth) % self._hop_size))))
+ if len(original) % self._hop_size != 0:
+ original = np.hstack((original, np.zeros(self._hop_size - (len(original) % self._hop_size))))
+
+ num_frames = len(original) / self._hop_size
+ residual = simpl.array([])
+ sample_offset = 0
+
+ for i in range(num_frames):
+ synth_frame = synth[sample_offset:sample_offset+self._hop_size]
+ original_frame = original[sample_offset:sample_offset+self._hop_size]
+ residual = np.hstack((residual,
+ self.residual_frame(synth_frame, original_frame)))
+ sample_offset += self._hop_size
+ return residual
+
+ def synth_frame(self, synth, original):
+ "Calculate and return one frame of the synthesised residual signal"
raise Exception("NotYetImplemented")
- # TODO: break this up into synth and synth_frame
- # so that it can be streamed
def synth(self, synth, original):
"Calculate and return a synthesised residual signal"
- raise Exception("NotYetImplemented")
+ # pad the signals if necessary
+ if len(synth) % self._hop_size != 0:
+ synth = np.hstack((synth, np.zeros(self._hop_size - (len(synth) % self._hop_size))))
+ if len(original) % self._hop_size != 0:
+ original = np.hstack((original, np.zeros(self._hop_size - (len(original) % self._hop_size))))
+
+ num_frames = len(original) / self._hop_size
+ residual = simpl.array([])
+ sample_offset = 0
+ for i in range(num_frames):
+ synth_frame = synth[sample_offset:sample_offset+self._hop_size]
+ original_frame = original[sample_offset:sample_offset+self._hop_size]
+ residual = np.hstack((residual,
+ self.synth_frame(synth_frame, original_frame)))
+ sample_offset += self._hop_size
+ return residual