From 458900b52242b2f058c12c5d8e97959c717cb00d Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Mon, 15 Nov 2021 12:06:45 -0500 Subject: [PATCH] MP3 decoding tweaks --- lib/live_beats/mp3_stat.ex | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/live_beats/mp3_stat.ex b/lib/live_beats/mp3_stat.ex index 7e059d1..39976fb 100644 --- a/lib/live_beats/mp3_stat.ex +++ b/lib/live_beats/mp3_stat.ex @@ -55,14 +55,14 @@ defmodule LiveBeats.MP3Stat do >>) do tag_size = decode_synchsafe_integer(tag_size_synchsafe) - {rest, _ext_header_size} = + {rest, ext_header_size} = if extended_header == 1 do skip_extended_header(major_version, rest) else {rest, 0} end - parse_frames(major_version, rest, tag_size - extended_header) + parse_frames(major_version, rest, tag_size - ext_header_size, []) end defp parse_tag(_), do: %{} @@ -100,7 +100,10 @@ defmodule LiveBeats.MP3Stat do {rest, ext_header_size} end - defp parse_frames(major_version, data, tag_length_remaining, frames \\ []) + defp parse_frames(_, data, tag_length_remaining, frames) + when tag_length_remaining <= 0 do + {Map.new(frames), data} + end defp parse_frames( major_version, @@ -150,11 +153,6 @@ defmodule LiveBeats.MP3Stat do end end - defp parse_frames(_, data, tag_length_remaining, frames) - when tag_length_remaining <= 0 do - {Map.new(frames), data} - end - defp parse_frames(_, data, _, frames) do {Map.new(frames), data} end