internal unsafe VorbisCommentToMetadataAdapter(VorbisComment vorbisComment)
        {
            var commentPtrs    = new Span <IntPtr>(vorbisComment.UserComments.ToPointer(), vorbisComment.Comments);
            var commentLengths = new Span <int>(vorbisComment.CommentLengths.ToPointer(), vorbisComment.Comments);

            for (var i = 0; i < vorbisComment.Comments; i++)
            {
                var commentBytes = new Span <byte>(commentPtrs[i].ToPointer(), commentLengths[i]);
                var delimiter    = commentBytes.IndexOf((byte)0x3D); // '='

#if NETSTANDARD2_0
                var keyBytes = commentBytes.Slice(0, delimiter);
                var key      = Encoding.ASCII.GetString(
                    (byte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(keyBytes)),
                    keyBytes.Length);

                if (key.Equals("METADATA_BLOCK_PICTURE", StringComparison.OrdinalIgnoreCase))
                {
                    CoverArt = CoverArtAdapter.FromBase64(commentBytes.Slice(delimiter + 1));
                }
                else
                {
                    var valueBytes = commentBytes.Slice(delimiter + 1);
                    SetText(key, Encoding.UTF8.GetString(
                                (byte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(valueBytes)),
                                valueBytes.Length));
                }
#else
                var key = Encoding.ASCII.GetString(commentBytes.Slice(0, delimiter));

                if (key.Equals("METADATA_BLOCK_PICTURE", StringComparison.OrdinalIgnoreCase))
                {
                    CoverArt = CoverArtAdapter.FromBase64(commentBytes[(delimiter + 1)..]);
        internal MetadataToVorbisCommentAdapter([NotNull] AudioMetadata metadata)
        {
            SafeNativeMethods.VorbisCommentInit(out _comment);

            if (!string.IsNullOrEmpty(metadata.Title))
            {
                AddTag("TITLE", metadata.Title);
            }
            if (!string.IsNullOrEmpty(metadata.Artist))
            {
                AddTag("ARTIST", metadata.Artist);
            }
            if (!string.IsNullOrEmpty(metadata.Album))
            {
                AddTag("ALBUM", metadata.Album);
            }
            if (!string.IsNullOrEmpty(metadata.AlbumArtist))
            {
                AddTag("ALBUMARTIST", metadata.AlbumArtist);
            }
            if (!string.IsNullOrEmpty(metadata.Composer))
            {
                AddTag("COMPOSER", metadata.Composer);
            }
            if (!string.IsNullOrEmpty(metadata.Genre))
            {
                AddTag("GENRE", metadata.Genre);
            }
            if (!string.IsNullOrEmpty(metadata.Comment))
            {
                AddTag("DESCRIPTION", metadata.Comment);
            }

            if (!string.IsNullOrEmpty(metadata.Day) &&
                !string.IsNullOrEmpty(metadata.Month) &&
                !string.IsNullOrEmpty(metadata.Year))
            {
                AddTag("DATE", $"{metadata.Year}-{metadata.Month}-{metadata.Day}");
            }
            else if (!string.IsNullOrEmpty(metadata.Year))
            {
                AddTag("YEAR", metadata.Year);
            }

            if (!string.IsNullOrEmpty(metadata.TrackNumber))
            {
                AddTag("TRACKNUMBER", !string.IsNullOrEmpty(metadata.TrackCount)
                    ? $"{metadata.TrackNumber}/{metadata.TrackCount}"
                    : metadata.TrackNumber);
            }

            if (!string.IsNullOrEmpty(metadata.TrackPeak))
            {
                AddTag("REPLAYGAIN_TRACK_PEAK", metadata.TrackPeak);
            }
            if (!string.IsNullOrEmpty(metadata.AlbumPeak))
            {
                AddTag("REPLAYGAIN_ALBUM_PEAK", metadata.AlbumPeak);
            }
            if (!string.IsNullOrEmpty(metadata.TrackGain))
            {
                AddTag("REPLAYGAIN_TRACK_GAIN", $"{metadata.TrackGain} dB");
            }
            if (!string.IsNullOrEmpty(metadata.AlbumGain))
            {
                AddTag("REPLAYGAIN_ALBUM_GAIN", $"{metadata.AlbumGain} dB");
            }

            // Always store images in JPEG format since Vorbis is also lossy
            if (metadata.CoverArt != null)
            {
                AddTag("METADATA_BLOCK_PICTURE", CoverArtAdapter.ToBase64(
                           CoverArtFactory.ConvertToLossy(metadata.CoverArt)));
            }
        }