diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-09-09 06:03:33 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-09-09 06:03:33 +0000 |
commit | 6628e6f2e3d28618887a2c19a4d6f52d274d32be (patch) | |
tree | 9fc87c1cd295e6fac41a329fb8871cd95fa90438 /lib/stream.lib.php | |
parent | 7920c8576184d59a77a9fbe5b00f77f62f3f3b28 (diff) | |
download | ampache-6628e6f2e3d28618887a2c19a4d6f52d274d32be.tar.gz ampache-6628e6f2e3d28618887a2c19a4d6f52d274d32be.tar.bz2 ampache-6628e6f2e3d28618887a2c19a4d6f52d274d32be.zip |
fixed downsample to invalid bitrates
Diffstat (limited to 'lib/stream.lib.php')
-rw-r--r-- | lib/stream.lib.php | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/lib/stream.lib.php b/lib/stream.lib.php index 262df981..c39282a6 100644 --- a/lib/stream.lib.php +++ b/lib/stream.lib.php @@ -190,10 +190,10 @@ function start_downsample($song,$now_playing_id=0,$song_name=0) { else { $sample_rate = floor($max_bitrate/$active_streams); } // end else - - /* Round to standard bitrates */ - $sample_rate = 8*(floor($sample_rate/8)); - + + /* Validate the bitrate */ + $sample_rate = validate_bitrate($sample_rate); + // Never go over the users sample rate if ($sample_rate > $user_sample_rate) { $sample_rate = $user_sample_rate; } @@ -248,4 +248,38 @@ function start_downsample($song,$now_playing_id=0,$song_name=0) { } // start_downsample +/** + * 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; + } + + /* 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 $sample_rate; + } + } // end foreach + +} // validate_bitrate + ?> |