Fix #622 by using the actual sample count per segment