This is a common misconception. In-room treatment vs in-wall treatment. Two different beasties.
Foams and denser insulations are better for on-wall surface attenuation. So in a studio, theater, gymnasium, etc where reverberation control is needed you would reach for a denser material. This might be foam or compressed fiber like duct liner or OC703, etc. This is a measured test, yielding a NRC- Noise Reduction Coefficient. Denser foams and insulations give a higher NRC. One surface in play in this scenario (the surface of the wall being tested). The sound wave has one interaction with the insulation. One bounce.
For in-wall sound control, we have two parallel surfaces now, generally the backs of the two drywall layers. Multiple bounces through the insulation. This is the box we've been discussing. Close parallel surfaces, bounded by mass. When we look at the role of foam / insulation in this setting, we find that the lowly, humble fiberglass works as well as anything. The finest acoustics lab in the world is Canada's National Research Council, the NRC. Look at their data in reports IR-761 and IR-693. 18 months of data describing the role of insulation in a wall or ceiling.
Insulation is one instance where you don't get what you pay for. In this instance, the best material to use is also the least expensive.
So a massive box made from MDF will contain the initial sound wave, forcing it to bounce through the insulation, robbing it of energy. To increase the effectiveness, make it longer. If this were a studio or theater, such a muffler (field assembled, not purchased) would be 10 feet long due to the extraordinary sound levels you're dealing with. For a vent fan, you could test if a 2' or 4' piece would work better.