public async Task <ServerAudioInfo> GrabFrameInfoAsync(ShoutcastStreamProcessor processor, ServerAudioInfo serverSentInfo)
        {
            ServerAudioInfo audioInfo = new ServerAudioInfo();

            audioInfo.AudioFormat = StreamAudioFormat.AAC_ADTS;

            //load the first byte
            byte lastByte = await processor.ReadByteFromSocketAsync();

            while (true) //wait for frame sync
            {
                var curByte = await processor.ReadByteFromSocketAsync();

                if (AAC_ADTSParser.IsFrameSync(lastByte, curByte)) //check if we're at the frame sync. if we are, parse some of the audio data
                {
                    byte[] header = new byte[AAC_ADTSParser.HeaderLength];
                    header[0] = lastByte;
                    header[1] = curByte;


                    Array.Copy(await processor.ReadBytesFromSocketAsync(5), 0, header, 2, 5);

                    //todo deal with CRC

                    try
                    {
                        audioInfo.SampleRate = (uint)AAC_ADTSParser.GetSampleRate(header);

                        audioInfo.ChannelCount = (uint)AAC_ADTSParser.GetChannelCount(header);

                        //bitrate gets sent by the server.
                        audioInfo.BitRate = serverSentInfo.BitRate;
                        //audioInfo.BitRate = (uint)AAC_ADTSParser.GetBitRate(header);

                        //if (audioInfo.BitRate == 0) throw new Exception("Unknown bitrate.");
                    }
                    catch (IndexOutOfRangeException)
                    {
                        //probably not the header. continue.
                        lastByte = curByte;
                        continue;
                    }
                    break;
                }
                else
                {
                    lastByte = curByte;
                }
            }

            return(audioInfo);
        }
        public async Task <ServerAudioInfo> GrabFrameInfoAsync(ShoutcastStreamProcessor processor, ServerAudioInfo serverSentInfo)
        {
            ServerAudioInfo audioInfo = new ServerAudioInfo();

            audioInfo.AudioFormat = StreamAudioFormat.MP3;

            //load the first byte
            byte lastByte = await processor.ReadByteFromSocketAsync();

            while (true) //wait for frame sync
            {
                var curByte = await processor.ReadByteFromSocketAsync();

                if (MP3Parser.IsFrameSync(lastByte, curByte)) //check if we're at the frame sync. if we are, parse some of the audio data
                {
                    byte[] header = new byte[MP3Parser.HeaderLength];
                    header[0] = lastByte;
                    header[1] = curByte;

                    Array.Copy(await processor.ReadBytesFromSocketAsync(2), 0, header, 2, 2);

                    if (!MP3Parser.IsValidHeader(header))
                    {
                        lastByte = header[3];
                        continue;
                    }
                    else
                    {
                        audioInfo.HeaderData   = header;
                        audioInfo.SampleRate   = (uint)MP3Parser.GetSampleRate(header);
                        audioInfo.ChannelCount = (uint)MP3Parser.GetChannelCount(header);
                        audioInfo.BitRate      = (uint)MP3Parser.GetBitRate(header);
                        break;
                    }
                }
                else
                {
                    lastByte = curByte;
                }
            }

            if (audioInfo.BitRate == 4294967294)
            {
                //if this gets hit, abort mission immediately.
                throw new ArithmeticException();
            }


            return(audioInfo);
        }