format(); $np_user = new User($r['user']); $results[] = array('song'=>$song,'user'=>$np_user,'agent'=>$r['agent']); } // end while return $results; } // get_now_playing /** * check_lock_songs * This checks to see if the song is already playing, if it is then it prevents the user * from streaming it */ function check_lock_songs($song_id) { $sql = "SELECT `song_id` FROM `now_playing` " . "WHERE `song_id` = '$song_id'"; $db_results = Dba::query($sql); if (Dba::num_rows($db_results)) { debug_event('lock_songs','Song Already Playing, skipping...','5'); return false; } return true; } // check_lock_songs /** * validate_bitrate * this function takes a bitrate and returns a valid one * @package Stream * @catagory Downsample */ function validate_bitrate($bitrate) { // Setup an array of valid bitrates for Lame (yea yea, others might be different :P) $valid_rate = array('32','40','56','64','80','96','112','128','160','192','224','256','320'); /* Round to standard bitrates */ $sample_rate = 8*(floor($bitrate/8)); if (in_array($sample_rate,$valid_rate)) { return $sample_rate; } /* See if it's less than the lowest one */ if ($sample_rate < $valid_rate['0']) { return $valid_rate['0']; } /* Check to see if it's over 320 */ if ($sample_rate > 320) { return '320'; } foreach ($valid_rate as $key=>$rate) { $next_key = $key+1; if ($sample_rate > $rate AND $sample_rate < $valid_rate[$next_key]) { return $rate; } } // end foreach } // validate_bitrate ?>