Bluetooth compresses audio before sending it. Which compression is used depends on what both ends support, and the two sides negotiate quietly each time they connect.
The dramatic quality drop people notice on calls is a mode change. When the microphone is used, many devices switch to a headset profile with far lower bandwidth in both directions, so music playing during a call sounds muffled.
Distance and interference reduce quality too. As the link degrades, the devices lower the bitrate to keep the stream unbroken, so audio becomes dull before it starts stuttering.
Battery-saving modes add a final twist: some phones downgrade the codec on low battery to extend runtime.