Exemplo n.º 1
0
 def __init__(self, rt60_opt, absc_opt, room_dim):
     """
     rt60_opt: "" or "a,b", higher priority than absc_opt
     absc_opt: tuple like (a,b)
     room_dim: str like "a,b;c,d;e,d"
     """
     self.rt60_opt = rt60_opt
     if not rt60_opt:
         self.absc = UniformSampler(absc_opt)
     else:
         rt60_r = str2tuple(rt60_opt)
         self.rt60 = UniformSampler(rt60_r)
     dim_range = [str2tuple(t) for t in room_dim.split(";")]
     if len(dim_range) != 3:
         raise RuntimeError(f"Wrong format with --room-dim={room_dim}")
     self.dim_sampler = [UniformSampler(c) for c in dim_range]
Exemplo n.º 2
0
class RoomGenerator(object):
    """
    Room generator
    """
    def __init__(self, rt60_opt, absc_opt, room_dim):
        """
        rt60_opt: "" or "a,b", higher priority than absc_opt
        absc_opt: tuple like (a,b)
        room_dim: str like "a,b;c,d;e,d"
        """
        self.rt60_opt = rt60_opt
        if not rt60_opt:
            self.absc = UniformSampler(absc_opt)
        else:
            rt60_r = str2tuple(rt60_opt)
            self.rt60 = UniformSampler(rt60_r)
        dim_range = [str2tuple(t) for t in room_dim.split(";")]
        if len(dim_range) != 3:
            raise RuntimeError(
                "Wrong format with --room-dim={}".format(room_dim))
        self.dim_sampler = [UniformSampler(c) for c in dim_range]

    def generate(self, v=340):
        # (l, w, h)
        (l, w, h) = (s.sample() for s in self.dim_sampler)
        if self.rt60_opt:
            # no reflection is ok
            if self.rt60.max == 0:
                return Room(l, w, h, rt60=0)
            else:
                # check rt60 here
                S, V = l * w * h, (l * w + l * h + w * h) * 2
                # sabine formula
                rt60_min = 24 * V * np.log(10) / (v * S)
                if rt60_min >= self.rt60.max:
                    return None
                    # raise RuntimeError(
                    #     "Configuration error in rt60: {}, minimum {:.2f} "
                    #     "required with ({:.2f}x{:.2f}x{:.2f})".format(
                    #         self.rt60_opt, rt60_min, l, w, h))
                else:
                    rt60 = random.uniform(rt60_min, self.rt60.max)
                    return Room(l, w, h, rt60=rt60)
        else:
            absc = self.absc.sample()
            return Room(l, w, h, refl=np.sqrt(1 - absc))