def realizeVolume(srcStream, setAbsoluteVelocity=False, useDynamicContext=
    True, useVelocity=True, useArticulations=True):
    """
    Given a Stream with one level of dynamics
    (e.g., a Part, or two Staffs that share Dynamics),
    destructively modify it to set all realized volume levels.
    These values will be stored in the Volume object as `cachedRealized` values.

    This is a top-down routine, as opposed to bottom-up values available with
    context searches on Volume. This thus offers a performance benefit.

    This is always done in place; for the option of non-in place processing,
    see Stream.realizeVolume().

    If setAbsoluteVelocity is True, the realized values will overwrite all
    existing velocity values, and the Volume objects velocityIsRelative
    parameters will be set to False.
    """
    bKeys = []
    boundaries = {}
    flatSrc = srcStream.flat
    dynamicsAvailable = False
    if flatSrc.iter.getElementsByClass('Dynamic'):
        dynamicsAvailable = True
    elif useDynamicContext is True:
        useDynamicContext = False
    if dynamicsAvailable:
        boundaries = flatSrc.extendDurationAndGetBoundaries('Dynamic')
        bKeys = list(boundaries.keys())
        bKeys.sort()
    lastRelevantKeyIndex = 0
    for e in flatSrc:
        if hasattr(e, 'volume') and 'NotRest' in e.classes:
            eStart = e.getOffsetBySite(flatSrc)
            if dynamicsAvailable and useDynamicContext is True:
                dm = False
                for k in range(lastRelevantKeyIndex, len(bKeys)):
                    start, end = bKeys[k]
                    if end > eStart >= start:
                        lastRelevantKeyIndex = k
                        dm = boundaries[bKeys[k]]
                        break
            else:
                dm = useDynamicContext
            val = e.volume.getRealized(useDynamicContext=dm, useVelocity=
                useVelocity, useArticulations=useArticulations)
            if setAbsoluteVelocity:
                e.volume.velocityIsRelative = False
                e.volume.velocityScalar = val
