diff --git a/scripts/ls_layouts/cicp13.txt b/scripts/ls_layouts/cicp13.txt index 5ff15f86c1cafe763148db2ce71a19443dab59a4..d0510c1d8f3cc981fd311723a177170ab2c66723 100644 --- a/scripts/ls_layouts/cicp13.txt +++ b/scripts/ls_layouts/cicp13.txt @@ -1,3 +1,3 @@ -0, 30 -30, 60, -60, 90, -90, 135, -135, 180, 0, 45, -45, 90, -90, 0, 135, -135, 180, 0, 45, -45 -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 35, 35, 35, 35, 90, 35, 35, 35, -15, -15, -15 -3, 9 \ No newline at end of file +0, 30, -30, 60, -60, 90, -90, 135, -135, 180, 0, 45, -45, 90, -90, 0, 135, -135, 180, 0, 45, -45 +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 35, 35, 35, 35, 90, 35, 35, 35, -15, -15, -15 +3, 9 diff --git a/scripts/pyaudio3dtools/audio3dtools.py b/scripts/pyaudio3dtools/audio3dtools.py old mode 100644 new mode 100755 diff --git a/scripts/pyaudio3dtools/audioarray.py b/scripts/pyaudio3dtools/audioarray.py index dd2c5fca5f7ff61da8a8c485567eeafe77d660fc..917cdf59c6537a30153bb42ba468ed1f62e8fc36 100644 --- a/scripts/pyaudio3dtools/audioarray.py +++ b/scripts/pyaudio3dtools/audioarray.py @@ -32,9 +32,10 @@ import logging import math -from typing import Optional, Tuple +from typing import Callable, Iterable, Optional, Tuple import numpy as np +import multiprocessing as mp import scipy.signal as sig main_logger = logging.getLogger("__main__") @@ -409,7 +410,7 @@ def limiter(x: np.ndarray, fs: int): fr_sig[idx_min] = -32768 -def get_framewise(x: np.ndarray, chunk_size: int) -> np.ndarray: +def get_framewise(x: np.ndarray, chunk_size: int, zero_pad=False) -> np.ndarray: """Generator to yield a signal frame by frame If array size is not a multiple of chunk_size, last frame contains the remainder @@ -419,6 +420,8 @@ def get_framewise(x: np.ndarray, chunk_size: int) -> np.ndarray: Input reference array chunk_size: int Size of frames to yield + zero_pad: bool + Whether to zero pad the last chunk if there are not enough samples Yields ------- @@ -429,4 +432,22 @@ def get_framewise(x: np.ndarray, chunk_size: int) -> np.ndarray: for i in range(n_frames): yield x[i * chunk_size : (i + 1) * chunk_size, :] if x.shape[0] % chunk_size: - yield x[n_frames * chunk_size :, :] + last_chunk = x[n_frames * chunk_size :, :] + if zero_pad: + yield np.pad(last_chunk, [[0, chunk_size - (x.shape[0] % chunk_size)], [0, 0]]) + else: + yield last_chunk + + +def process_async(files: Iterable, func: Callable, **kwargs): + """Applies a function asynchronously to an array of audio files/filenames using a multiprocessing pool""" + + p = mp.pool(mp.cpu_count()) + results = [] + for f in files: + results.append(p.apply_async(func, args=(f, kwargs))) + p.close() + p.join() + for r in results: + r.get() + return results diff --git a/scripts/pyaudio3dtools/audiofile.py b/scripts/pyaudio3dtools/audiofile.py old mode 100755 new mode 100644 diff --git a/scripts/pyaudio3dtools/spatialaudioconvert.py b/scripts/pyaudio3dtools/spatialaudioconvert.py index 2dc1fc073772796a43912059864d4c95cd136006..1ed144943f8bf90ce47f31ec6fd14f2131476757 100644 --- a/scripts/pyaudio3dtools/spatialaudioconvert.py +++ b/scripts/pyaudio3dtools/spatialaudioconvert.py @@ -201,7 +201,7 @@ def spatial_audio_convert( # initialise metadata object for ISM metadata_obj = spatialmetadata.Metadata() - metadata_obj.init_for_ism(in_file, in_fs, in_meta_files) + metadata_obj.init_for_ism(in_file, in_fs, in_nchans, in_meta_files) # TODO decide on reference path for BINAURAL_ROOM if out_spfmt.name.startswith("BINAURAL_ROOM"): @@ -426,6 +426,13 @@ def convert_ism( audioarray.get_framewise(out_sig, frame_len), ) ): + # update the crossfade if we have a smaller last frame + if out_frame.shape[0] != frame_len: + frame_size = out_frame.shape[0] + fade_in = np.arange(frame_size) / (frame_size - 1) + fade_in = fade_in[:, np.newaxis] + fade_out = 1.0 - fade_in + pos = EFAP.wrap_angles(*pos_data[i_frame % pos_frames, :], clip_ele=True) # ISM -> MC diff --git a/scripts/pyaudio3dtools/spatialmetadata.py b/scripts/pyaudio3dtools/spatialmetadata.py index d1933d0f5781a0927c601f7e0716e1ce200ba21e..fa89595b70e0ceb2a14abbee716e5fc9a07a4780 100644 --- a/scripts/pyaudio3dtools/spatialmetadata.py +++ b/scripts/pyaudio3dtools/spatialmetadata.py @@ -211,13 +211,13 @@ class Metadata: for object_index in range(self.nb_objects): print(f" Object #{object_index} Type: {self.objects[object_index]}") - def _append_audio_array(self, audio_wav=None, fs=48000, object_index=None): + def _append_audio_array(self, audio_wav=None, fs=48000, nchan=1, object_index=None): if audio_wav is None: audio_wav = self.audio_wav[-1] if object_index is None: object_index = -1 - x, fs = audiofile.readfile(audio_wav, fs=fs) + x, fs = audiofile.readfile(audio_wav, fs=fs, nchannels=nchan) logger.debug(f"Append {audio_wav}: {x.shape[0]} by {x.shape[1]}") # Select appropriate channels & resample if necessary @@ -245,6 +245,7 @@ class Metadata: self, in_file: str, in_fs: int, + in_nchan: int, metadata_files: list, ) -> None: self.audio_wav.append(in_file) @@ -252,7 +253,7 @@ class Metadata: for csv in metadata_files: self.objects.append(read_ism_ivas_data(csv, object_index=self.nb_objects)) self.objects[-1]["track_index"] = self.nb_objects - self._append_audio_array(self.audio_wav[-1], fs=in_fs) + self._append_audio_array(self.audio_wav[-1], fs=in_fs, nchan=in_nchan) self.nb_objects += 1 # Get audio array with sampling rate diff --git a/scripts/pyivastest/IvasModeRunner.py b/scripts/pyivastest/IvasModeRunner.py old mode 100755 new mode 100644