// ParseSampleFormat returns the SampleFormat described by the given string.
//
// The string should be as returned by SampleFormat.String().
498173
func ParseSampleFormat(s string) SampleFormat {
	cstr := C.CString(s)
	defer C.free(unsafe.Pointer(cstr))
	return SampleFormat(C.pa_parse_sample_format(cstr))
}
1049729
func (wav *Reader) ReadRawSample() ([]byte, error) {
	if wav.samplesRead > wav.numSamples {
		return nil, io.EOF
	}

	buf := make([]byte, wav.bytesPerSample)
	n, err := wav.input.Read(buf)
	if err != nil {
		return nil, err
	}

	if n != int(wav.bytesPerSample) {
		return nil, fmt.Errorf("Read %d bytes, should have read %d", n, wav.bytesPerSample)
	}

	wav.samplesRead++

	return buf, nil
}
768865
func parseHeapSample(line string, rate int64, sampling string) (value []int64, blocksize int64, addrs []uint64, err error) {
	sampleData := heapSampleRE.FindStringSubmatch(line)
	if len(sampleData) != 6 {
		return value, blocksize, addrs, fmt.Errorf("unexpected number of sample values: got %d, want 6", len(sampleData))
	}

	// Use first two values by default; tcmalloc sampling generates the
	// same value for both, only the older heap-profile collect separate
	// stats for in-use and allocated objects.
	valueIndex := 1
	if LegacyHeapAllocated {
		valueIndex = 3
	}

	var v1, v2 int64
	if v1, err = strconv.ParseInt(sampleData[valueIndex], 10, 64); err != nil {
		return value, blocksize, addrs, fmt.Errorf("malformed sample: %s: %v", line, err)
	}
	if v2, err = strconv.ParseInt(sampleData[valueIndex+1], 10, 64); err != nil {
		return value, blocksize, addrs, fmt.Errorf("malformed sample: %s: %v", line, err)
	}

	if v1 == 0 {
		if v2 != 0 {
			return value, blocksize, addrs, fmt.Errorf("allocation count was 0 but allocation bytes was %d", v2)
		}
	} else {
		blocksize = v2 / v1
		if sampling == "v2" {
			v1, v2 = scaleHeapSample(v1, v2, rate)
		}
	}

	value = []int64{v1, v2}
	addrs = parseHexAddresses(sampleData[5])

	return value, blocksize, addrs, nil
}
741473
func Resample(buf *audio.PCMBuffer, fs float64) error {
	if buf == nil || buf.Format == nil {
		return audio.ErrInvalidBuffer
	}
	if buf.Format.SampleRate == int(fs) {
		return nil
	}
	buf.SwitchPrimaryType(audio.Float)

	// downsample
	if fs < float64(buf.Format.SampleRate) {
		factor := float64(buf.Format.SampleRate) / fs

		// apply a low pass filter at the nyquist frequency to avoid
		// aliasing.
		if err := filters.LowPass(buf, float64(buf.Format.SampleRate)/2); err != nil {
			return err
		}

		// drop samples to match the decimation factor
		newLength := int(math.Floor(float64(len(buf.Floats)) / factor))
		var targetI int
		for i := 0; i < newLength; i++ {
			targetI = int(math.Floor(float64(i) * factor))
			buf.Floats[i] = buf.Floats[targetI]
		}
		buf.Floats = buf.Floats[:newLength]
		buf.Format.SampleRate = int(fs)
		return nil
	}

	// oversample
	// Note: oversampling reduces the amplitude
	factor := fs / float64(buf.Format.SampleRate)
	newLength := int(math.Ceil(float64(len(buf.Floats)) * factor))
	newFloats := make([]float64, newLength)
	padding := int(
		math.Ceil(
			float64(newLength) /
				float64(len(buf.Floats))))
	var idx int
	for i := 0; i < len(buf.Floats); i++ {
		idx = i * padding
		if idx >= len(newFloats) {
			break
		}
		newFloats[idx] = buf.Floats[i]
	}
	buf.Floats = newFloats
	buf.Format.SampleRate = int(fs)
	return nil
}
1051980
func compareFormatString(fmt1, fmt2 string) bool {
	if fmt1 == fmt2 {
		return true
	}
	if fmt1 == "" || strings.EqualFold(fmt1, "general") {
		fmt1 = "general"
	}
	if fmt2 == "" || strings.EqualFold(fmt2, "general") {
		fmt2 = "general"
	}
	return fmt1 == fmt2
}
1080185
func (d *Decoder) decodeSamples1() error {
	for s := 0; s < 12; s++ {
		for sb := 0; sb < 32; sb++ {
			nch := d.nChannels
			if sb >= d.bound {
				nch = 1
			}

			for ch := 0; ch < nch; ch++ {
				if d.allocation[ch][sb] != 0 {
					sample, err := d.stream.readBits(d.allocation[ch][sb])
					if err != nil {
						return err
					}
					d.sample[ch][32*s+sb] = float32(sample)
				}
			}
		}

		for sb := d.bound; sb < 32; sb++ {
			d.sample[1][32*s+sb] = d.sample[0][32*s+sb]
		}
	}
	return nil
}
354512
func (f URITemplateFormatChecker) IsFormat(input interface{}) bool {
	asString, ok := input.(string)
	if !ok {
		return false
	}

	u, err := url.Parse(asString)
	if err != nil || strings.Contains(asString, `\`) {
		return false
	}

	return rxURITemplate.MatchString(u.Path)
}
880093
func NewSampleJSONBuilder() *SampleJSONBuilder {
	jb := &SampleJSONBuilder{
		_properties:        map[string]*SamplePropertyInfo{},
		_jsonPropertyMap:   map[string]*SamplePropertyInfo{},
		_structPropertyMap: map[string]*SamplePropertyInfo{},
		A: &SamplePropertyInfo{
			fieldName: "A",
			jsonName:  "foo!",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.A = src.A
				return nil
			},
		},
		B: &SamplePropertyInfo{
			fieldName: "B",
			jsonName:  "b",
			Encoder: func(src *Sample, dest *SampleJSON) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
			Decoder: func(src *SampleJSON, dest *Sample) error {
				if src == nil {
					return nil
				}
				dest.B = src.B
				return nil
			},
		},
	}
	jb._structPropertyMap["A"] = jb.A
	jb._jsonPropertyMap["foo!"] = jb.A
	jb._structPropertyMap["B"] = jb.B
	jb._jsonPropertyMap["b"] = jb.B
	return jb
}
1311313
func OutputFormat(s string) string {
	var buf bytes.Buffer
	for _, old := range s {
		if newVal, ok := replace[old]; ok {
			buf.WriteString(newVal)
			continue
		}
		buf.WriteRune(old)
	}

	return buf.String()
}
1262616
func (s *PercolateService) PercolateFormat(percolateFormat string) *PercolateService {
	s.percolateFormat = percolateFormat
	return s
}
1169432
func parseJavaSamples(pType string, b []byte, p *Profile) ([]byte, map[uint64]*Location, error) {
	nextNewLine := bytes.IndexByte(b, byte('\n'))
	locs := make(map[uint64]*Location)
	for nextNewLine != -1 {
		line := string(bytes.TrimSpace(b[0:nextNewLine]))
		if line != "" {
			sample := javaSampleRx.FindStringSubmatch(line)
			if sample == nil {
				// Not a valid sample, exit.
				return b, locs, nil
			}

			// Java profiles have data/fields inverted compared to other
			// profile types.
			var err error
			value1, value2, value3 := sample[2], sample[1], sample[3]
			addrs, err := parseHexAddresses(value3)
			if err != nil {
				return nil, nil, fmt.Errorf("malformed sample: %s: %v", line, err)
			}

			var sloc []*Location
			for _, addr := range addrs {
				loc := locs[addr]
				if locs[addr] == nil {
					loc = &Location{
						Address: addr,
					}
					p.Location = append(p.Location, loc)
					locs[addr] = loc
				}
				sloc = append(sloc, loc)
			}
			s := &Sample{
				Value:    make([]int64, 2),
				Location: sloc,
			}

			if s.Value[0], err = strconv.ParseInt(value1, 0, 64); err != nil {
				return nil, nil, fmt.Errorf("parsing sample %s: %v", line, err)
			}
			if s.Value[1], err = strconv.ParseInt(value2, 0, 64); err != nil {
				return nil, nil, fmt.Errorf("parsing sample %s: %v", line, err)
			}

			switch pType {
			case "heap":
				const javaHeapzSamplingRate = 524288 // 512K
				if s.Value[0] == 0 {
					return nil, nil, fmt.Errorf("parsing sample %s: second value must be non-zero", line)
				}
				s.NumLabel = map[string][]int64{"bytes": {s.Value[1] / s.Value[0]}}
				s.Value[0], s.Value[1] = scaleHeapSample(s.Value[0], s.Value[1], javaHeapzSamplingRate)
			case "contention":
				if period := p.Period; period != 0 {
					s.Value[0] = s.Value[0] * p.Period
					s.Value[1] = s.Value[1] * p.Period
				}
			}
			p.Sample = append(p.Sample, s)
		}
		// Grab next line.
		b = b[nextNewLine+1:]
		nextNewLine = bytes.IndexByte(b, byte('\n'))
	}
	return b, locs, nil
}
590067
func (s *GetThreatIntelSetOutput) SetFormat(v string) *GetThreatIntelSetOutput {
	s.Format = &v
	return s
}
1049171
func (f DateFormatChecker) IsFormat(input interface{}) bool {
	asString, ok := input.(string)
	if !ok {
		return false
	}
	_, err := time.Parse("2006-01-02", asString)
	return err == nil
}
484808
func (c *FormatCheckerChain) IsFormat(name string, input interface{}) bool {
	lock.Lock()
	f, ok := c.formatters[name]
	lock.Unlock()

	if !ok {
		return false
	}

	return f.IsFormat(input)
}
591452
func (a *AvgSampleWithMin) GetSampleRate(key string) int {
	a.lock.Lock()
	defer a.lock.Unlock()
	a.currentCounts[key]++
	if !a.haveData {
		return a.GoalSampleRate
	}
	if rate, found := a.savedSampleRates[key]; found {
		return rate
	}
	return 1
}
382434
func (b *builtinFormatWithLocaleSig) evalString(row chunk.Row) (string, bool, error) {
	x, d, isNull, err := evalNumDecArgsForFormat(b, row)
	if isNull || err != nil {
		return "", isNull, err
	}
	locale, isNull, err := b.args[2].EvalString(b.ctx, row)
	if err != nil {
		return "", false, err
	}
	if isNull {
		b.ctx.GetSessionVars().StmtCtx.AppendWarning(errUnknownLocale.GenWithStackByArgs("NULL"))
		locale = "en_US"
	}
	formatString, err := mysql.GetLocaleFormatFunction(locale)(x, d)
	return formatString, false, err
}
109004
func (f SampleFormat) String() string {
	cstr := C.pa_sample_format_to_string(C.pa_sample_format_t(f))
	return C.GoString(cstr)
}