Mix two wave body into one.
424297
def mix_wave(src, dst):
    """"""
    if len(src) > len(dst):
        # output should be longer
        dst, src = src, dst

    for i, sv in enumerate(src):
        dv = dst[i]
        if sv < 128 and dv < 128:
            dst[i] = int(sv * dv / 128)
        else:
            dst[i] = int(2 * (sv + dv) - sv * dv / 128 - 256)
    return dst
390153
def merge(data,skip=50,fraction=1.0):
    """"""

    w,s,d = data.chains.shape
    
    start = int((1.0 - fraction) * s)
    total = int((s - start) / skip)
        
    return data.chains[:,start::skip,:].reshape((w*total,d))
1358386
def join_channels(*channels: Channel) -> Channel:
    """"""
    vectors = [chan.vec for chan in channels]
    vec = reduce(outer_product, vectors)
    return Channel(vec.tensor, vec.qubits)
119967
function combineSplitters (splitters) {
  var l = splitters.length
  return function (str) {
    for (var i = 0; i < l; i++) {
      var result = splitters[i](str)
      if (result) return result
    }
  }
}
620425
def mix_c!(i, j, c = nil)
      @body.mix_c!(i, j, c)
      @right.mix_c!(i, j, c)
      self
    end
446790
def concatenate_slh(self, other):
        """"""
        selfS = self.S
        otherS = other.S
        new_S = block_matrix(
                selfS, zerosm((selfS.shape[0], otherS.shape[1]), dtype=int),
                zerosm((otherS.shape[0], selfS.shape[1]), dtype=int), otherS)
        new_L = vstackm((self.L, other.L))
        new_H = self.H + other.H

        return SLH(new_S, new_L, new_H)
1191713
def mix(color1, color2, pos=0.5):
    
    opp_pos = 1 - pos

    red = color1[0] * pos + color2[0] * opp_pos
    green = color1[1] * pos + color2[1] * opp_pos
    blue = color1[2] * pos + color2[2] * opp_pos
    return int(red), int(green), int(blue)
501851
function mixin(target, source, force, deepStringMixin) {
        if (source) {
            eachProp(source, function (value, prop) {
                if (force || !hasProp(target, prop)) {
                    if (deepStringMixin && typeof value !== 'string') {
                        if (!target[prop]) {
                            target[prop] = {};
                        }
                        mixin(target[prop], value, force, deepStringMixin);
                    } else {
                        target[prop] = value;
                    }
                }
            });
        }
        return target;
    }
1055629
private Mixer createNewMixer()
	{
		Mixer mixer = getCurrentContainer().createNewMixer();
		if (mixer!=null)
		{
			mixer.setAudioProcessor(audioProcessor);
			mixer.setVolume(currentVolume);
			mixer.setBalance(currentBalance);
			mixer.setSoundOutputStream(getSoundOutputStream());
			getSeekBarPanel().setCurrentMixer(mixer);
		}
		return mixer;
	}
775989
static double mix( double color1, double color2, double weight ) {
        long col1 = Double.doubleToRawLongBits( color1 );
        long col2 = Double.doubleToRawLongBits( color2 );

        int alpha1 = (int)(col1  >>> 48);
        int red1 = (int)(col1  >> 32) & 0xFFFF;
        int green1 = (int)(col1  >> 16) & 0xFFFF;
        int blue1 = (int)(col1) & 0xFFFF;
        int alpha2 = (int)(col2  >>> 48);
        int red2 = (int)(col2  >> 32) & 0xFFFF;
        int green2 = (int)(col2  >> 16) & 0xFFFF;
        int blue2 = (int)(col2) & 0xFFFF;

        double w = weight * 2 - 1;
        double a = (alpha1 - alpha2) / (double)0XFFFF;

        double w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
        double w2 = 1 - w1;

        long red = Math.round(red1 * w1 + red2 * w2);
        long green = Math.round(green1 * w1 + green2 * w2);
        long blue = Math.round(blue1 * w1 + blue2 * w2);

        long alpha = Math.round(alpha1 * weight + alpha2 * (1 - weight));

        long color = (alpha << 48) | (red << 32) | (green << 16) | (blue);
        return Double.longBitsToDouble( color );
    }
1016013
def mix2(servo1, servo2, mixtype=1, gain=0.5):
    ''''''
    (v1,v2) = mixer(servo1, servo2, mixtype=mixtype, gain=gain)
    return v2
212995
private Wave createWave(final WaveGroup waveGroup, final WaveType waveType, final Class<?> componentClass, final WaveData<?>... waveData) {

        final Wave wave = wave()
                                .waveGroup(waveGroup)
                                .waveType(waveType)
                                .fromClass(this.getClass())
                                .componentClass(componentClass)
                                .addDatas(waveData);

        // Track wave creation
        localFacade().globalFacade().trackEvent(JRebirthEventType.CREATE_WAVE, this.getClass(), wave.getClass());

        return wave;
    }
718946
def generateComponent(m):
    """"""
    freq = 25*np.random.random()
    phase = 2*np.pi*np.random.random()
    x = np.arange(m)
    return np.cos(x/freq-phase)**2
1011198
function mix(receiver, supplier) {
    var p;
    for (p in supplier) {
        if (supplier.hasOwnProperty(p)) {
            if (has(supplier, p) && has(receiver, p) && supplier[p].constructor === Object && receiver[p].constructor === Object) {
                receiver[p] = mix(receiver[p], supplier[p]);
            } else {
                receiver[p] = supplier[p];
            }
        }
    }

    return receiver;
}
1131764
function mixin(inObj/*, inProps, inMoreProps, ...*/) {
    var obj = inObj || {};
    for (var i = 1; i < arguments.length; i++) {
      var p = arguments[i];
      try {
        for (var n in p) {
          copyProperty(n, p, obj);
        }
      } catch(x) {
      }
    }
    return obj;
  }
823057
def mul(*args):
    """"""
    if len(args) > 2:
        return add(args[0], add(args[1], args[1:]))

    if len(args) == 1:
        return args[0]

    part1, part2 = args

    if not isinstance(part2, Poly):

        if isinstance(part2, (float, int)):
            part2 = np.asarray(part2)

        if not part2.shape:
            core = part1.A.copy()
            dtype = chaospy.poly.typing.dtyping(
                part1.dtype, part2.dtype)
            for key in part1.keys:
                core[key] = np.asarray(core[key]*part2, dtype)
            return Poly(core, part1.dim, part1.shape, dtype)

        part2 = Poly(part2)

    if part2.dim > part1.dim:
        part1 = chaospy.dimension.setdim(part1, part2.dim)

    elif part2.dim < part1.dim:
        part2 = chaospy.dimension.setdim(part2, part1.dim)

    if np.prod(part1.shape) >= np.prod(part2.shape):
        shape = part1.shape
    else:
        shape = part2.shape

    dtype = chaospy.poly.typing.dtyping(part1.dtype, part2.dtype)
    if part1.dtype != part2.dtype:

        if part1.dtype == dtype:
            part2 = chaospy.poly.typing.asfloat(part2)

        else:
            part1 = chaospy.poly.typing.asfloat(part1)

    core = {}
    for idx1 in part2.A:
        for idx2 in part1.A:
            key = tuple(np.array(idx1) + np.array(idx2))
            core[key] = np.asarray(
                core.get(key, 0) + part2.A[idx1]*part1.A[idx2])
    core = {key: value for key, value in core.items() if np.any(value)}

    out = Poly(core, part1.dim, shape, dtype)
    return out
1270682
def write_wavefile(f, samples, nframes=None, nchannels=2, sampwidth=2, framerate=44100, bufsize=2048):
    ""
    if nframes is None:
        nframes = 0

    w = wave.open(f, 'wb')
    w.setparams((nchannels, sampwidth, framerate, nframes, 'NONE', 'not compressed'))

    max_amplitude = float(int((2 ** (sampwidth * 8)) / 2) - 1)

    # split the samples into chunks (to reduce memory consumption and improve performance)
    for chunk in grouper(bufsize, samples):
        frames = b''.join(b''.join(struct.pack('h', int(max_amplitude * sample)) for sample in channels) for channels in chunk if channels is not None)
        w.writeframesraw(frames)

    w.close()