public function getStats()
    {
        if (isset($this->stats)) return $this->stats;
        
        $stats = array();
        $stats['channels'] = '1';
        
        foreach (explode("\n", $this->sox('-n', 'stats')) as $line) {
            if (empty($line) || preg_match('/^\S+ WARN/', $line)) continue;
            
            if ($line[0] == ' ') {
                $stats['channels'] = (string)count(preg_split('/\s+/', trim($line))) - 1;
                continue;
            }
            
            list($key, $value) = preg_split('/\s{2,}/', $line) + array(1=>null);
            if (!isset($value)) continue;
            
            $key = strtolower(preg_replace(array('/\s(s|dB)$/', '/\W+/'), array('', '_'), $key));
            $value = preg_replace('/\s.*$/', '', $value);
            $stats[$key] = $value;
        }
        
        foreach (explode("\n", $this->sox('-n', 'stat')) as $line) {
            if (preg_match('/^\S+ WARN/', $line)) continue;
            
            list($key, $value) = explode(':', $line) + array(1=>null);
            if (!isset($value)) continue;
            
            if ($key == 'Samples read') $key = 'samples';
             elseif ($key == 'Length (seconds)') $key = 'length';
             else $key = strtolower(preg_replace('/\s+/', '_', $key));
            
            $stats[$key] = trim($value);
        }
        
        unset($stats['num_samples']);
        $stats['sample_rate'] = (string)round(($stats['samples'] / $stats['channels']) / $stats['length']);
        
        $this->stats = (object)$stats;
        return $this->stats;
    }