// OpenAudio opens the mixer with a certain audio format.
// (https://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_11.html)
518988
func OpenAudio(frequency int, format uint16, channels, chunksize int) error {
	_frequency := (C.int)(frequency)
	_format := (C.Uint16)(format)
	_channels := (C.int)(channels)
	_chunksize := (C.int)(chunksize)
	if C.Mix_OpenAudio(_frequency, _format, _channels, _chunksize) < 0 {
		return sdl.GetError()
	}
	return nil
}
896718
func GetAudioDriver(index int) string {
	return string(C.GoString(C.SDL_GetAudioDriver(C.int(index))))
}
622578
func (a *Adaptor) Sound(fileName string) []error {
	var errorsList []error

	if fileName == "" {
		log.Println("Requires filename for audio file.")
		errorsList = append(errorsList, errors.New("Requires filename for audio file."))
		return errorsList
	}

	_, err := os.Stat(fileName)
	if err != nil {
		log.Println(err)
		errorsList = append(errorsList, err)
		return errorsList
	}

	// command to play audio file based on file type
	commandName, err := CommandName(fileName)
	if err != nil {
		log.Println(err)
		errorsList = append(errorsList, err)
		return errorsList
	}

	err = RunCommand(commandName, fileName)
	if err != nil {
		log.Println(err)
		errorsList = append(errorsList, err)
		return errorsList
	}

	// Need to return to fulfill function sig, even though returning an empty
	return nil
}
410042
func (s *M2tsSettings) SetAudioBufferModel(v string) *M2tsSettings {
	s.AudioBufferModel = &v
	return s
}
1165371
func (bot TgBot) SendAudio(cid int, audio string, duration *int, performer *string, title *string, rmi *int, rm *ReplyMarkupInt) ResultWithMessage {
	var payload interface{} = SendAudioIDQuery{cid, audio, duration, performer, title, rmi, rm}
	if looksLikePath(audio) {
		payload = SendAudioPathQuery{cid, audio, duration, performer, title, rmi, rm}
	}
	return bot.SendAudioQuery(payload)
}
313457
func (stream *AudioStream) Available() (err error) {
	ret := int(C.SDL_AudioStreamAvailable(stream.cptr()))
	err = errorFromInt(ret)
	return
}
1174282
func (api *Client) OpenIMChannel(user string) (bool, bool, string, error) {
	return api.OpenIMChannelContext(context.Background(), user)
}
975248
func (s *PresetSettings) SetAudioDescriptions(v []*AudioDescription) *PresetSettings {
	s.AudioDescriptions = v
	return s
}
611214
func (s *SynthesizeSpeechOutput) SetAudioStream(v io.ReadCloser) *SynthesizeSpeechOutput {
	s.AudioStream = v
	return s
}
1006493
func (s *M2tsSettings) SetAudioStreamType(v string) *M2tsSettings {
	s.AudioStreamType = &v
	return s
}
1100175
func (s *EncoderSettings) SetAudioDescriptions(v []*AudioDescription) *EncoderSettings {
	s.AudioDescriptions = v
	return s
}
449445
func (c *Callbacks) OnCUserMessageSendAudio(fn func(*dota.CUserMessageSendAudio) error) {
	c.onCUserMessageSendAudio = append(c.onCUserMessageSendAudio, fn)
}
218206
func New(r io.Reader) (*Wav, error) {
	var w Wav
	header := make([]byte, 16)
	if _, err := io.ReadFull(r, header[:12]); err != nil {
		return nil, err
	}
	if string(header[0:4]) != "RIFF" {
		return nil, fmt.Errorf("wav: missing RIFF")
	}
	if string(header[8:12]) != "WAVE" {
		return nil, fmt.Errorf("wav: missing WAVE")
	}
	hasFmt := false
	for {
		if _, err := io.ReadFull(r, header[:8]); err != nil {
			return nil, err
		}
		sz := binary.LittleEndian.Uint32(header[4:])
		switch typ := string(header[:4]); typ {
		case "fmt ":
			if sz < 16 {
				return nil, fmt.Errorf("wav: bad fmt size")
			}
			f := make([]byte, sz)
			if _, err := io.ReadFull(r, f); err != nil {
				return nil, err
			}
			if err := binary.Read(bytes.NewBuffer(f), binary.LittleEndian, &w.Header); err != nil {
				return nil, err
			}
			switch w.AudioFormat {
			case wavFormatPCM:
			case wavFormatIEEEFloat:
			default:
				return nil, fmt.Errorf("wav: unknown audio format: %02x", w.AudioFormat)
			}
			hasFmt = true
		case "data":
			if !hasFmt {
				return nil, fmt.Errorf("wav: unexpected fmt chunk")
			}
			w.Samples = int(sz) / int(w.BitsPerSample) * 8
			w.Duration = time.Duration(w.Samples) * time.Second / time.Duration(w.SampleRate) / time.Duration(w.NumChannels)
			w.r = io.LimitReader(r, int64(sz))
			return &w, nil
		default:
			io.CopyN(ioutil.Discard, r, int64(sz))
		}
	}
}
1099599
func AudioLevel(samples []int32) float64 {
	// Compute sum of square values
	var sum float64
	for _, s := range samples {
		sum += math.Pow(float64(s), 2)
	}

	// Square root
	return math.Sqrt(sum / float64(len(samples)))
}
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
}
1167266
func Audio(buf []byte) (types.Type, error) {
	return doMatchMap(buf, matchers.Audio)
}
132052
func RegisterAudioCodec(id int, codec AudioCodec) {
	audioCodecsLock.Lock()
	defer audioCodecsLock.Unlock()

	if id < 0 || id >= len(audioCodecs) {
		panic("id out of range")
	}
	audioCodecs[id] = codec
}