// mixSound mixes src into dst. Dst must have length equal to or greater than
// src length.
165597
func mixSound(dst, src []byte) {
	for i, v := range src {
		av := int(v)
		bv := int(dst[i])
		if av < 128 && bv < 128 {
			dst[i] = byte(av * bv / 128)
		} else {
			dst[i] = byte(2*(av+bv) - av*bv/128 - 256)
		}
	}
}
239584
func (Encoder) AppendString(dst []byte, s string) []byte {
	major := majorTypeUtf8String

	l := len(s)
	if l <= additionalMax {
		lb := byte(l)
		dst = append(dst, byte(major|lb))
	} else {
		dst = appendCborTypePrefix(dst, majorTypeUtf8String, uint64(l))
	}
	return append(dst, s...)
}
532662
func MixedCaps(s string) string {
	chunks := strings.Split(s, "_")
	for i, chunk := range chunks {
		chunks[i] = strings.Title(chunk)
	}

	return strings.Join(chunks, "")
}
780589
func CopyFile(src, dst string) (int64, error) {
	cleanSrc := filepath.Clean(src)
	cleanDst := filepath.Clean(dst)
	if cleanSrc == cleanDst {
		return 0, nil
	}
	sf, err := os.Open(cleanSrc)
	if err != nil {
		return 0, err
	}
	defer sf.Close()
	if err := os.Remove(cleanDst); err != nil && !os.IsNotExist(err) {
		return 0, err
	}
	df, err := os.Create(cleanDst)
	if err != nil {
		return 0, err
	}
	defer df.Close()
	return io.Copy(df, sf)
}
570526
func (e Encoder) AppendStrings(dst []byte, vals []string) []byte {
	major := majorTypeArray
	l := len(vals)
	if l <= additionalMax {
		lb := byte(l)
		dst = append(dst, byte(major|lb))
	} else {
		dst = appendCborTypePrefix(dst, major, uint64(l))
	}
	for _, v := range vals {
		dst = e.AppendString(dst, v)
	}
	return dst
}
148665
func (d *Decoder) stereo3() {
	// The standard is fairly vague on this step, and the reference
	// implementation is garbage. So this function may or may not be correct,
	// but at least it's correct enough to pass the compliance test.

	if d.mode != ModeJointStereo || d.modeExtension == 0 {
		return
	}

	ms, intensity := d.modeExtension&2 != 0, d.modeExtension&1 != 0

	for gr := 0; gr < 2; gr++ {
		longLow, longHigh := 0, 22
		shortLow, shortHigh := 0, 13
		if d.blockType[gr][1] == 2 {
			if d.mixedBlockFlag[gr][1] == 1 {
				longHigh = 8
				shortLow = 3
			} else {
				longLow = 22
			}
		} else {
			shortLow = 13
		}

		zeroPartStartS := [3]int{shortLow, shortLow, shortLow}
		nonzeroShort := false
		for window := 0; window < 3; window++ {
		sfbShort:
			for sfb := shortHigh - 1; sfb >= shortLow; sfb-- {
				low := scfBandsS[d.samplingFreq][sfb]
				length := scfBandsS[d.samplingFreq][sfb+1] - low
				winLow := 3*low + window*length
				winHigh := winLow + length
				for f := winLow; f < winHigh; f++ {
					if d.huffmanData[gr][1][f] != 0 {
						zeroPartStartS[window] = sfb + 1
						nonzeroShort = true
						break sfbShort
					}
				}
			}
		}

		zeroPartStartL := longLow
		if nonzeroShort {
			zeroPartStartL = longHigh
		} else {
		sfbLong:
			for sfb := longHigh - 1; sfb >= longLow; sfb-- {
				low := scfBandsL[d.samplingFreq][sfb]
				high := scfBandsL[d.samplingFreq][sfb+1]
				for f := low; f < high; f++ {
					if d.huffmanData[gr][1][f] != 0 {
						zeroPartStartL = sfb + 1
						break sfbLong
					}
				}
			}
		}

		for window := 0; window < 3; window++ {
			for sfb := shortLow; sfb < shortHigh; sfb++ {
				low := scfBandsS[d.samplingFreq][sfb]
				length := scfBandsS[d.samplingFreq][sfb+1] - low
				winLow := 3*low + window*length
				winHigh := winLow + length
				isPos := sfb
				if isPos == 12 {
					isPos = 11
				}
				isPos = d.scalefacS[gr][1][isPos][window]
				if intensity && sfb >= zeroPartStartS[window] && isPos < 7 {
					L := intensityFactors[isPos]
					R := 1 - L
					for f := winLow; f < winHigh; f++ {
						d.huffmanData[gr][1][f] = R * d.huffmanData[gr][0][f]
						d.huffmanData[gr][0][f] *= L
					}
				} else if ms {
					for f := winLow; f < winHigh; f++ {
						M, S := d.huffmanData[gr][0][f], d.huffmanData[gr][1][f]
						d.huffmanData[gr][0][f] = (M + S) / sqrt2
						d.huffmanData[gr][1][f] = (M - S) / sqrt2
					}
				}
			}
		}

		for sfb := longLow; sfb < longHigh; sfb++ {
			low := scfBandsL[d.samplingFreq][sfb]
			high := scfBandsL[d.samplingFreq][sfb+1]
			isPos := sfb
			if isPos == 21 {
				isPos = 20
			}
			isPos = d.scalefacL[gr][1][isPos]
			if intensity && sfb >= zeroPartStartL && isPos < 7 {
				L := intensityFactors[isPos]
				R := 1 - L
				for f := low; f < high; f++ {
					d.huffmanData[gr][1][f] = R * d.huffmanData[gr][0][f]
					d.huffmanData[gr][0][f] *= L
				}
			} else if ms {
				for f := low; f < high; f++ {
					M, S := d.huffmanData[gr][0][f], d.huffmanData[gr][1][f]
					d.huffmanData[gr][0][f] = (M + S) / sqrt2
					d.huffmanData[gr][1][f] = (M - S) / sqrt2
				}
			}
		}
	}
}
1137955
func Merge(dst map[string]interface{}, srcs ...map[string]interface{}) (map[string]interface{}, error) {
	for _, src := range srcs {
		dst = mergeValues(src, dst)
	}
	return dst, nil
}
1111330
func mixinNP(ln *line, isDeclaration bool) (string, []string, error) {
	s := strings.TrimSpace(ln.s)

	if !strings.HasPrefix(s, dollarMark) {
		return "", nil, fmt.Errorf("mixin must start with %q [line: %d]", dollarMark, ln.no)
	}

	s = strings.TrimPrefix(s, dollarMark)

	np := strings.Split(s, openParenthesis)

	if len(np) != 2 {
		return "", nil, fmt.Errorf("mixin's format is invalid [line: %d]", ln.no)
	}

	paramsS := strings.TrimSpace(np[1])

	if !strings.HasSuffix(paramsS, closeParenthesis) {
		return "", nil, fmt.Errorf("mixin must end with %q [line: %d]", closeParenthesis, ln.no)
	}

	paramsS = strings.TrimSuffix(paramsS, closeParenthesis)

	if strings.Index(paramsS, closeParenthesis) != -1 {
		return "", nil, fmt.Errorf("mixin's format is invalid [line: %d]", ln.no)
	}

	var params []string

	if paramsS != "" {
		params = strings.Split(paramsS, comma)
	}

	for i, p := range params {
		p = strings.TrimSpace(p)

		if isDeclaration {
			if !strings.HasPrefix(p, dollarMark) {
				return "", nil, fmt.Errorf("mixin's parameter must start with %q [line: %d]", dollarMark, ln.no)
			}

			p = strings.TrimPrefix(p, dollarMark)
		}

		params[i] = p
	}

	return np[0], params, nil
}
410235
func (Encoder) AppendFloats32(dst []byte, vals []float32) []byte {
	if len(vals) == 0 {
		return append(dst, '[', ']')
	}
	dst = append(dst, '[')
	dst = appendFloat(dst, float64(vals[0]), 32)
	if len(vals) > 1 {
		for _, val := range vals[1:] {
			dst = appendFloat(append(dst, ','), float64(val), 32)
		}
	}
	dst = append(dst, ']')
	return dst
}
337637
func (m *Mixer) Stream(samples [][2]float64) (n int, ok bool) {
	var tmp [512][2]float64

	for len(samples) > 0 {
		toStream := len(tmp)
		if toStream > len(samples) {
			toStream = len(samples)
		}

		// clear the samples
		for i := range samples[:toStream] {
			samples[i] = [2]float64{}
		}

		for si := 0; si < len(m.streamers); si++ {
			// mix the stream
			sn, sok := m.streamers[si].Stream(tmp[:toStream])
			for i := range tmp[:sn] {
				samples[i][0] += tmp[i][0]
				samples[i][1] += tmp[i][1]
			}
			if !sok {
				// remove drained streamer
				sj := len(m.streamers) - 1
				m.streamers[si], m.streamers[sj] = m.streamers[sj], m.streamers[si]
				m.streamers = m.streamers[:sj]
				si--
			}
		}

		samples = samples[toStream:]
		n += toStream
	}

	return n, true
}
512986
func MonoDownmix(buf *audio.PCMBuffer) error {
	if buf == nil || buf.Format == nil {
		return audio.ErrInvalidBuffer
	}
	nChans := buf.Format.NumChannels
	if nChans < 2 {
		return nil
	}
	nChansF := float64(nChans)

	frameCount := buf.Size()
	newData := make([]float64, frameCount)
	buf.SwitchPrimaryType(audio.Float)
	for i := 0; i < frameCount; i++ {
		newData[i] = 0
		for j := 0; j < nChans; j++ {
			newData[i] += buf.Floats[i*nChans+j]
		}
		newData[i] /= nChansF
	}
	buf.Floats = newData
	buf.Format.NumChannels = 1

	return nil
}
280543
func (p *Pattern) geoSineWaves() {
	period := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 100, 400)
	amplitude := utils.Map(utils.HexVal(p.Hash, 1, 1), 0, 15, 30, 100)
	waveWidth := utils.Map(utils.HexVal(p.Hash, 2, 1), 0, 15, 3, 30)

	p.Svg.SetHeight(int(waveWidth * 36))
	p.Svg.SetWidth(int(period))

	for i := 0; i <= 35; i++ {
		val := utils.HexVal(p.Hash, i, 1)
		opacity := utils.Opacity(val)
		fill := utils.FillColor(val)
		xOffset := (period / 4) * 0.7

		styles := make(map[string]interface{})
		styles["fill"] = "none"
		styles["stroke"] = fill
		styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", waveWidth)}

		str := fmt.Sprintf("M0 %v C %v 0, %v 0, %v %v S %v %v, %v %v S %v 0, %v, %v", amplitude, xOffset, period/2-xOffset, period/2, amplitude, period-xOffset, amplitude*2, period, amplitude, period*1.5-xOffset, period*1.5, amplitude)

		style := make(map[string]interface{})

		style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5))
		p.Svg.Path(str, utils.Merge(styles, style))

		style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5)+waveWidth*36)
		p.Svg.Path(str, utils.Merge(styles, style))
	}
}
1015769
func (Encoder) AppendTimes(dst []byte, vals []time.Time, format string) []byte {
	switch format {
	case timeFormatUnix:
		return appendUnixTimes(dst, vals)
	case timeFormatUnixMs:
		return appendUnixMsTimes(dst, vals)
	}
	if len(vals) == 0 {
		return append(dst, '[', ']')
	}
	dst = append(dst, '[')
	dst = append(vals[0].AppendFormat(append(dst, '"'), format), '"')
	if len(vals) > 1 {
		for _, t := range vals[1:] {
			dst = append(t.AppendFormat(append(dst, ',', '"'), format), '"')
		}
	}
	dst = append(dst, ']')
	return dst
}
753163
func (e Encoder) AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool) []byte {
	if useInt {
		return e.AppendInt64(dst, int64(d/unit))
	}
	return e.AppendFloat64(dst, float64(d)/float64(unit))
}
974081
func (l *Live) AddMultipleStreamMixService(mixStream MixStreamParam, resp interface{}) (err error) {
	req := l.cloneRequest(AddMultipleStreamMixServiceAction)
	if mixStream.Main.DomainName != "" {
		req.DomainName = mixStream.Main.DomainName
	}
	if mixStream.Main.AppName != "" {
		req.AppName = mixStream.Main.AppName
	}
	req.SetArgs("StreamName", mixStream.Main.StreamName)
	req.SetArgs("MixDomainName", mixStream.Mix.DomainName)
	req.SetArgs("MixAppName", mixStream.Mix.AppName)
	req.SetArgs("MixStreamName", mixStream.Mix.StreamName)
	err = l.rpc.Query(req, resp)
	return
}
1167266
func Audio(buf []byte) (types.Type, error) {
	return doMatchMap(buf, matchers.Audio)
}
878759
func Copy(dst string, src string) error {
	from, err := os.Open(src)
	if err != nil {
		return fmt.Errorf(`can't copy %s: %v`, src, err)
	}
	defer from.Close()
	finfo, err := from.Stat()
	if err != nil {
		return fmt.Errorf(`can't stat %s: %v`, src, err)
	}
	to, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, finfo.Mode())
	if err != nil {
		return fmt.Errorf(`can't copy to %s: %v`, dst, err)
	}
	defer to.Close()
	_, err = io.Copy(to, from)
	if err != nil {
		return fmt.Errorf(`error copying %s to %s: %v`, src, dst, err)
	}
	return nil
}