Measuring duration of voltage peak

    while (analogRead(soundSensor) > threshold)
    {
      // do nothing
    }

OK if you really are not doing anything else, but not a good habit to get into I suggest.