A class to represent sound sources. This object represents a sound source in a room by a list containing the original source position as well as all the image sources, up to some maximum order. It also keeps track of the sequence of generated images and the index of the walls (in
| 10 | |
| 11 | |
| 12 | class SoundSource(object): |
| 13 | """ |
| 14 | A class to represent sound sources. |
| 15 | |
| 16 | This object represents a sound source in a room by a list containing the original source position |
| 17 | as well as all the image sources, up to some maximum order. |
| 18 | |
| 19 | It also keeps track of the sequence of generated images and the index of the walls (in the original room) |
| 20 | that generated the reflection. |
| 21 | """ |
| 22 | |
| 23 | def __init__( |
| 24 | self, |
| 25 | position, |
| 26 | images=None, # source position |
| 27 | damping=None, |
| 28 | generators=None, # parent source |
| 29 | walls=None, # generating wall |
| 30 | orders=None, |
| 31 | signal=None, |
| 32 | delay=0, |
| 33 | directivity=None, |
| 34 | ): |
| 35 | position = np.array(position) |
| 36 | self.dim = position.shape[0] |
| 37 | |
| 38 | # Check the shape of the passed array |
| 39 | if self.dim != 2 and self.dim != 3: |
| 40 | dim_mismatch = True |
| 41 | else: |
| 42 | dim_mismatch = False |
| 43 | |
| 44 | if position.ndim == 2 and position.shape[1] == 1: |
| 45 | position = position[:, 0] |
| 46 | |
| 47 | if position.ndim != 1 or dim_mismatch: |
| 48 | raise ValueError( |
| 49 | "The source location of microphones should be provided as an object " |
| 50 | "that can be converted to a numpy.ndarray. The array should be of " |
| 51 | "shape `(2,)`, `(2, 1)`, `(3,)`, or `(3, 1)`." |
| 52 | ) |
| 53 | |
| 54 | self.position = position |
| 55 | |
| 56 | if images is None: |
| 57 | # set to empty list if nothing provided |
| 58 | self.images = np.asfortranarray(np.array([position], dtype=np.float32).T) |
| 59 | self.damping = np.array([[1.0]]) |
| 60 | self.generators = np.array([-1], dtype=np.int32) |
| 61 | self.walls = np.array([-1], dtype=np.int32) |
| 62 | self.orders = np.array([0], dtype=np.int32) |
| 63 | |
| 64 | else: |
| 65 | # we need to have damping factors for every image |
| 66 | if damping is None: |
| 67 | # set to one if not set |
| 68 | damping = np.ones((1, images.shape[1])) |
| 69 |
no outgoing calls
no test coverage detected