From 007bb3ceafb940a3b7e2b7a082f29cf6e77d828d Mon Sep 17 00:00:00 2001 From: jweigele Date: Thu, 29 Sep 2022 16:25:49 -0700 Subject: [PATCH] Multi-channel drifting! --- ffmpegfile.py | 52 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/ffmpegfile.py b/ffmpegfile.py index 4bfe8d7..cbe2724 100644 --- a/ffmpegfile.py +++ b/ffmpegfile.py @@ -32,15 +32,16 @@ class AudioChunk(object): if init_bytes is not None: init_bytes = self.pad_out(init_bytes) self.samples = numpy.array([x[0] for x in struct.iter_unpack(' 0: - channels = len(next_samples.shape) - while len(next_samples) > 0: - # this is to format the samples in the style opus wants - #log.debug('channels are {}'.format(channels)) - #if channels == 2: - # # interleave the samples L/R to form a bytestream eventually - # next_samples = numpy.squeeze(numpy.dstack((next_samples[0], next_samples[1])).reshape(1, -1)) - # right now, this is the only path taken (because we discard the other channel) - #else: - next_samples = numpy.repeat(next_samples, 2) - # for the downcast to int16 - #next_samples *= 32768.0 - #next_bytes = next_samples.astype('int16') - chunk = AudioChunk(init_samples=next_samples) - #log.debug(chunk, chunk.samples) - chunks_to_append.append(chunk) - # get next chunk - index += MAX_SAMPLES - next_samples = buffer_samples[index:index+MAX_SAMPLES] + next_samples = buffer_samples[:,index:index+MAX_SAMPLES] + while next_samples.size > 0: + chunk = AudioChunk(init_samples=next_samples) + #log.debug(chunk, chunk.samples) + chunks_to_append.append(chunk) + # get next chunk + index += MAX_SAMPLES + next_samples = buffer_samples[:,index:index+MAX_SAMPLES] # chunk append/insertion (along with mixing) -- 2.30.2