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 | |
parent | 7920c8576184d59a77a9fbe5b00f77f62f3f3b28 (diff) | |
download | ampache-6628e6f2e3d28618887a2c19a4d6f52d274d32be.tar.gz ampache-6628e6f2e3d28618887a2c19a4d6f52d274d32be.tar.bz2 ampache-6628e6f2e3d28618887a2c19a4d6f52d274d32be.zip |
fixed downsample to invalid bitrates
-rwxr-xr-x | docs/CHANGELOG | 4 | ||||
-rw-r--r-- | lib/stream.lib.php | 42 | ||||
-rw-r--r-- | play/index.php | 3 |
3 files changed, 42 insertions, 7 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index e5c55225..6f6bd21d 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -18,6 +18,10 @@ - Reworked Search to allow for multiple searches, and eventually allow you to return a list of albums,artist,genres rather than a list of songs. + - Fixed Lock Songs always returning false and thus preventing + any playback when enabled. (Thx J) + - Fixed a flaw in the downsampling which would allow you to set + invalid bitrates. (Thx J) 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 + ?> diff --git a/play/index.php b/play/index.php index f32cc27b..8d41c88a 100644 --- a/play/index.php +++ b/play/index.php @@ -141,9 +141,6 @@ if ( $catalog->catalog_type == 'remote' ) { else { - if ($user->prefs['play_type'] == 'downsample') { - $ds = $user->prefs['sample_rate']; - } // Update the users last seen $user->update_last_seen(); |