Add a word to the first // wp_get_attachment_url // as the subdomain name

$mp3Link = wp_get_attachment_url($mp3_file_id);
$mp3Link = str_replace( 'example.com', 'sub.example.com', $mp3Link ); 
<a class="w3-black" href="'.$mp3Link.'" rel="nofollow" >mp3</a>

replace example.com with your actual domain – it’s not the most elegant solution, but might work.