anchor.diff:              (round (/ bit-rate 1000))
               (floor (/ len 60)) (round (mod len 60)))))
   
  -
  -(defun get-mpeg-audio-info (in &key) ;; (max-frames *max-frames-to-read*))
  -  "Get MPEG Layer 3 audio information.
  -If the first MPEG frame we find is a Xing/Info header, return that as info.
  -Else, we assume CBR and calculate the duration, etc."
  -  (log5:with-context "get-mpeg-audio-info"
  -    (let ((first-frame (find-first-sync in))
  -          (info (make-instance 'mpeg-audio-info)))
  -
  -      (log-mpeg-frame "search for first frame yielded ~a" (vpprint first-frame nil))
  -      (when (null first-frame)
  -        (return-from get-mpeg-audio-info nil))
  -
  +(defun calc-bit-rate-exhaustive (in start info)
  +  "Map every MPEG frame in IN and calculate the bit-rate"
  +  (log5:with-context "calc-bit-rate-exhaustive"
  +    (let ((total-len 0)
  +          (last-bit-rate nil)
  +          (bit-rate-total 0)
  +          (vbr nil))
  +      (log-mpeg-frame "broken Xing/Info header found, reading all frames")
         (with-slots (is-vbr sample-rate bit-rate len version layer n-frames) info
  -        (setf version (version first-frame))
  -        (setf layer (layer first-frame))
  -        (setf sample-rate (sample-rate first-frame))
  -
  -        (if (vbr first-frame)
  -            (progn
  -              (log-mpeg-frame "found Xing/Info header")
  -              (setf n-frames 1)
  -              (setf is-vbr t)
  -              (setf len (float (* (frames (vbr first-frame)) (/ (samples first-frame) (sample-rate first-frame)))))
  -              (if (not (zerop len))
  -                  (setf bit-rate  (float (/ (* 8 (bytes (vbr first-frame))) len)))
  -                  (setf bit-rate 0)))
  -            (let* ((first (pos first-frame))
  -                   (last (- (audio-streams:stream-size in) (if (id3-frame::v21-tag-header (id3-header in)) 128 0)))
  -                   (n-fr (round (/ (float (- last first)) (float (size first-frame)))))
  -                   (n-sec   (round (/ (float (* (size first-frame) n-fr)) (float (* 125 (float (/ (bit-rate first-frame) 1000))))))))
  -              (setf is-vbr nil)
  -              (setf n-frames 1) ; just set it to 1
  -              (setf len n-sec)
  -              (setf bit-rate (float (bit-rate first-frame))))))
  -
  -            info)))
  -
  -              ;; If you want to calculate exhaustively, replace the LET* above with this code
  -              ;; (let ((total-len 0)
  -              ;;     (last-bit-rate nil)
  -              ;;     (bit-rate-total 0)
  -              ;;     (vbr nil))
  -              ;; (log-mpeg-frame "no Xing/Info, so mapping frames")
  -              ;; (map-frames in (lambda (f)
  -              ;;                  (incf n-frames)
  -              ;;                  (incf total-len (float (/ (samples f) (sample-rate f))))
  -              ;;                  (incf bit-rate-total (bit-rate f))
  -              ;;                  (if (null last-bit-rate)
  -              ;;                      (setf last-bit-rate (bit-rate f))
  -              ;;                      (progn
  -              ;;                        (when (not (= last-bit-rate (bit-rate f)))
  -              ;;                          (setf vbr t))
  -              ;;                        (setf last-bit-rate (bit-rate f)))))
  -              ;;             :read-payload nil :start-pos 0 :max max-frames)
  -              ;; (if (or (< n-frames 10) (zerop bit-rate-total))
  -              ;;     (progn
  -              ;;       (log-mpeg-frame "couldn't get audio-info: only got ~d frames" n-frames)
  -              ;;       (return-from get-mpeg-audio-info nil))
  -              ;;     (progn
  -              ;;       (setf is-vbr vbr)
  -              ;;       (setf len total-len)
  -              ;;       (setf bit-rate (float (/ bit-rate-total n-frames))))))))
  +        (map-frames in (lambda (f)
  +                         (incf n-frames)
  +                         (incf total-len (float (/ (samples f) (sample-rate f))))
  +                         (incf bit-rate-total (bit-rate f))
  +                         (if (null last-bit-rate)
  +                             (setf last-bit-rate (bit-rate f))
  +                             (progn
  +                               (when (not (= last-bit-rate (bit-rate f)))
  +                                 (setf vbr t))
  +                               (setf last-bit-rate (bit-rate f)))))
  +                    :read-payload nil :start-pos start)
  +
  +        (log-mpeg-frame "finished mapping. read ~:d frames" n-frames)
  +
  +        (when (or (< n-frames 10) (zerop bit-rate-total))
  +          (log-mpeg-frame "couldn't get audio-info: only got ~d frames" n-frames)
  +          (return-from calc-bit-rate-exhaustive))
  +
  +        (setf is-vbr t)
  +        (setf len total-len)
  +        (setf bit-rate (float (/ bit-rate-total n-frames)))
  +        (log-mpeg-frame "len = ~:d, bit-rate = ~f" len bit-rate)))))
  +
  + (defun get-mpeg-audio-info (in &key) ;; (max-frames *max-frames-to-read*))
  +   "Get MPEG Layer 3 audio information.
  + If the first MPEG frame we find is a Xing/Info header, return that as info.
  + Else, we assume CBR and calculate the duration, etc."
  +   (log5:with-context "get-mpeg-audio-info"
  +     (let ((first-frame (find-first-sync in))
  +           (info (make-instance 'mpeg-audio-info)))
  +
  +       (log-mpeg-frame "search for first frame yielded ~a" (vpprint first-frame nil))
  +       (when (null first-frame)
  +         (return-from get-mpeg-audio-info nil))
  +
  +       (with-slots (is-vbr sample-rate bit-rate len version layer n-frames) info
  +         (setf version (version first-frame))
  +         (setf layer (layer first-frame))
  +         (setf sample-rate (sample-rate first-frame))
  +
  +         (if (vbr first-frame)
  +             ;; found a Xing header, now check to see if it is correct
  +             (if (zerop (frames (vbr first-frame)))
  +                 (calc-bit-rate-exhaustive in (pos first-frame) info) ; Xing header broken, read all frames to calc
  +                 ;; Good Xing header, use info in VBR to calc
  +                 (progn
  +                   (setf n-frames 1)
  +                   (setf is-vbr t)
  +                   (setf len (float (* (frames (vbr first-frame)) (/ (samples first-frame) (sample-rate first-frame)))))
  +                   (setf bit-rate (float (/ (* 8 (bytes (vbr first-frame))) len)))))
  +
  +             ;; No Xing header found.  Assume CBR and calculate based on first frame
  +             (let* ((first (pos first-frame))
  +                    (last (- (audio-streams:stream-size in) (if (id3-frame::v21-tag-header (id3-header in)) 128 0)))
  +                    (n-fr (round (/ (float (- last first)) (float (size first-frame)))))
  +                    (n-sec (round (/ (float (* (size first-frame) n-fr)) (float (* 125 (float (/ (bit-rate first-frame) 1000))))))))
  +               (setf is-vbr nil)
  +               (setf n-frames 1)
  +               (setf len n-sec)
  +               (setf bit-rate (float (bit-rate first-frame))))))
  +
  +             info)))
  
positive.code: 
            (setf vbr (make-instance 'vbr-info))
            (let ((v (make-mem-stream (payload me))))
              (stream-seek v i :start)            ; seek to xing/info info
              (setf (tag vbr)   (stream-read-iso-string-with-len v 4))
              (setf (flags vbr) (stream-read-u32 v))
              (when (logand (flags vbr) +vbr-frames+)
                (setf (frames vbr) (stream-read-u32 v))
                (if (= 0 (frames vbr)) (warn-user "warning Xing/Info header flags has FRAMES set, but field is zero")))
              (when (logand (flags vbr) +vbr-bytes+)
                (setf (bytes vbr) (stream-read-u32 v))
                (if (= 0 (bytes vbr)) (warn-user "warning Xing/Info header flags has BYTES set, but field is zero")))
              (when (logand (flags vbr) +vbr-tocs+)
                (setf (tocs vbr) (stream-read-sequence v 100)))
              (when (logand (flags vbr) +vbr-scale+)
                (setf (scale vbr) (stream-read-u32 v)))
              (log-mpeg-frame "vbr-info = ~a" (vpprint vbr nil))))))))
  
  (defmethod vpprint ((me vbr-info) stream)
  
negative.code:               (format s "mode extension = ~a, copyrighted? = ~[no~;yes~], original? = ~[no~;yes~], emphasis = ~a"
                        (get-mode-extension-string channel-mode layer mode-extension) copyright original (get-emphasis-string emphasis))
                (when payload
                  (format s "~%frame payload[~:d] = ~a~%" (length payload) (utils:printable-array payload)))))))
  
  (defclass vbr-info ()
    ((tag    :accessor tag    :initarg :tag)
  