<commit_before>package main

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"math"

	"github.com/yobert/alsa"
)

func main() {

	cards, err := alsa.OpenCards()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer alsa.CloseCards(cards)

	for _, card := range cards {
		fmt.Println(card)

		if err := beep_card(card); err != nil {
			fmt.Println(err)
			return
		}
	}
}

func beep_card(card *alsa.Card) error {
	devices, err := card.Devices()
	if err != nil {
		return err
	}
	for _, device := range devices {
		if device.Type != alsa.PCM || !device.Play {
			continue
		}
		fmt.Println("───", device)

		if err := beep_device(device); err != nil {
			return err
		}
	}
	return nil
}

func beep_device(device *alsa.Device) error {
	var err error

	if err = device.Open(); err != nil {
		return err
	}
	defer device.Close()

	channels, err := device.NegotiateChannels(1, 2)
	if err != nil {
		return err
	}

	rate, err := device.NegotiateRate(44100)
	if err != nil {
		return err
	}

	format, err := device.NegotiateFormat(alsa.S16_LE, alsa.S32_LE)
	if err != nil {
		return err
	}

	buffer_size, err := device.NegotiateBufferSize(4, 1024, 8192, 16384)
	if err != nil {
		return err
	}

	if err = device.Prepare(); err != nil {
		return err
	}

	buf := bytes.NewBuffer(nil)
	t := 0.0

	fmt.Printf("Negotiated parameters: %d channels, %d hz, %v, %d frame buffer\n",
		channels, rate, format, buffer_size)

	for {
		buf.Reset()

		for i := 0; i < buffer_size; i++ {
			v := math.Sin(t * 2 * math.Pi * 440) // A4
			v *= 0.1                             // make a little quieter

			switch format {
			case alsa.S16_LE:
				sample := int16(v * ((1 << 16) - 1))

				for c := 0; c < channels; c++ {<commit_msg>cmd/beep: Take out crazy buffer size test<commit_after>package main

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"math"

	"github.com/yobert/alsa"
)

func main() {

	cards, err := alsa.OpenCards()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer alsa.CloseCards(cards)

	for _, card := range cards {
		fmt.Println(card)

		if err := beep_card(card); err != nil {
			fmt.Println(err)
			return
		}
	}
}

func beep_card(card *alsa.Card) error {
	devices, err := card.Devices()
	if err != nil {
		return err
	}
	for _, device := range devices {
		if device.Type != alsa.PCM || !device.Play {
			continue
		}
		fmt.Println("───", device)

		if err := beep_device(device); err != nil {
			return err
		}
	}
	return nil
}

func beep_device(device *alsa.Device) error {
	var err error

	if err = device.Open(); err != nil {
		return err
	}
	defer device.Close()

	channels, err := device.NegotiateChannels(1, 2)
	if err != nil {
		return err
	}

	rate, err := device.NegotiateRate(44100)
	if err != nil {
		return err
	}

	format, err := device.NegotiateFormat(alsa.S16_LE, alsa.S32_LE)
	if err != nil {
		return err
	}

	buffer_size, err := device.NegotiateBufferSize(1024, 8192, 16384)
	if err != nil {
		return err
	}

	if err = device.Prepare(); err != nil {
		return err
	}

	buf := bytes.NewBuffer(nil)
	t := 0.0

	fmt.Printf("Negotiated parameters: %d channels, %d hz, %v, %d frame buffer\n",
		channels, rate, format, buffer_size)

	for {
		buf.Reset()

		for i := 0; i < buffer_size; i++ {
			v := math.Sin(t * 2 * math.Pi * 440) // A4
			v *= 0.1                             // make a little quieter

			switch format {
			case alsa.S16_LE:
				sample := int16(v * ((1 << 16) - 1))

				for c := 0; c < channels; c++ {
{'fraction_non_alphanumeric': 0.1506849315068493, 'fraction_numerical': 0.025357038764208684, 'mean_word_length': 2.742639040348964, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2527092', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1324, 'n_words': 359}