protected function calcExecute($sample_count, $trim, $rate)
    {
        $track = escapeshellarg($this->track);
        if ($trim) $trim = "trim $trim";
        $resample = $rate ? "-r $rate" : '';
        $chunk_size = floor($sample_count / $this->width);
        
        $descriptorspec = array(
           1 => array("pipe", "w"), // stdout
           2 => array("pipe", "w")  // stderr
        );
        
        $sox = escapeshellcmd(Track::which('sox'));
        
        $handle = proc_open("$sox $track -t raw $resample -c 1 -e floating-point -L - $trim", $descriptorspec, $pipes);
        if (!$handle) throw new \Exception("Failed to get the samples using sox");

        $chunk = array();
        $samples = array();
        
        while ($data = fread($pipes[1], 4 * $chunk_size)) {
            $chunk = unpack('f*', $data);
            $chunk[] = 0;
            $samples[] = min($chunk);
            $samples[] = max($chunk);
        };
        
        $err = stream_get_contents($pipes[2]);
        
        $ret = proc_close($handle);
        if ($ret != 0) throw new \Exception("Sox command failed. " . trim($err));
                
        return $samples;
    }