<commit_before>package audio

import (
	"encoding/binary"
	"errors"
	"fmt"

	"github.com/dh1tw/remoteAudio/icd"
	"github.com/golang/protobuf/proto"
)

func (ad *AudioDevice) deserializeAudioMsg(data []byte) error {

	msg := icd.AudioData{}
	err := proto.Unmarshal(data, &msg)
	if err != nil {
		return err
	}

	var channels, samplingrate, bitrate, frames int

	if msg.Channels != nil {
		channels = int(msg.GetChannels())
	}

	if msg.FrameLength != nil {
		frames = int(msg.GetFrameLength())
	}

	if msg.String != nil {
		samplingrate = int(msg.GetSamplingRate())
	}

	// only accept 8 or 16 bit streams
	if msg.Bitrate != nil {
		bitrate = int(msg.GetBitrate())
		if bitrate != 8 && bitrate != 16 && bitrate != 32 {
			return errors.New("incompatible bitrate")
		}
	} else {
		return errors.New("unknown bitrate")
	}

	if bitrate == 8 {
		if len(msg.Audio) != int(frames*channels) {
			fmt.Println("msg length: ", len(msg.Audio), int(frames*channels), frames*channels)
			return errors.New("audio data does not match frame buffer * channels")
		}
	} else if bitrate == 16 {
		if len(msg.Audio) != int(frames*channels)*2 {
			fmt.Println("msg length: ", len(msg.Audio), int(frames*channels), frames*channels)
			return errors.New("audio data does not match frame buffer * channels")
		}
	} else if bitrate == 32 {
		if len(msg.Audio) != int(frames*channels)*4 {
			fmt.Println("msg length: ", len(msg.Audio), int(frames*channels), frames*channels)
			return errors.New("audio data does not match frame buffer * channels")
		}
	}

	if float64(samplingrate) != ad.Samplingrate {
		return errors.New("unequal sampling rate")
	}

	if msg.Audio != nil {<commit_msg>removed check<commit_after>package audio

import (
	"encoding/binary"
	"errors"
	"fmt"

	"github.com/dh1tw/remoteAudio/icd"
	"github.com/golang/protobuf/proto"
)

func (ad *AudioDevice) deserializeAudioMsg(data []byte) error {

	msg := icd.AudioData{}
	err := proto.Unmarshal(data, &msg)
	if err != nil {
		return err
	}

	var channels, samplingrate, bitrate, frames int

	if msg.Channels != nil {
		channels = int(msg.GetChannels())
	}

	if msg.FrameLength != nil {
		frames = int(msg.GetFrameLength())
	}

	if msg.String != nil {
		samplingrate = int(msg.GetSamplingRate())
	}

	// only accept 8 or 16 bit streams
	if msg.Bitrate != nil {
		bitrate = int(msg.GetBitrate())
		if bitrate != 8 && bitrate != 16 && bitrate != 32 {
			return errors.New("incompatible bitrate")
		}
	} else {
		return errors.New("unknown bitrate")
	}

	if bitrate == 8 {
		if len(msg.Audio) != int(frames*channels) {
			fmt.Println("msg length: ", len(msg.Audio), int(frames*channels), frames*channels)
			return errors.New("audio data does not match frame buffer * channels")
		}
	} else if bitrate == 16 {
		if len(msg.Audio) != int(frames*channels)*2 {
			fmt.Println("msg length: ", len(msg.Audio), int(frames*channels), frames*channels)
			return errors.New("audio data does not match frame buffer * channels")
		}
		// } else if bitrate == 32 {
		// 	if len(msg.Audio) != int(frames*channels)*4 {
		// 		fmt.Println("msg length: ", len(msg.Audio), int(frames*channels), frames*channels)
		// 		return errors.New("audio data does not match frame buffer * channels")
		// 	}
	}

	if float64(samplingrate) != ad.Samplingrate {
		return errors.New("unequal sampling rate")
	}

	if msg.Audio != nil {
{'fraction_non_alphanumeric': 0.15089820359281436, 'fraction_numerical': 0.010778443113772455, 'mean_word_length': 3.8561046511627906, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1263343', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1133, 'n_words': 287}