import logging


def get_recording_delay(distance=1.6, sample_rate=48828, play_from=None, rec_from=None):
    """
        Calculate the delay it takes for played sound to be recorded. Depends
        on the distance of the microphone from the speaker and on the processors
        digital-to-analog and analog-to-digital conversion delays.

        Args:
            distance (float): distance between listener and speaker array in meters
            sample_rate (int): sample rate under which the system is running
            play_from (str): processor used for digital to analog conversion
            rec_from (str): processor used for analog to digital conversion

    """
    n_sound_traveling = int(distance / 343 * sample_rate)
    if play_from:
        if play_from == "RX8":
            n_da = 24
        elif play_from == "RP2":
            n_da = 30
        else:
            logging.warning(f"dont know D/A-delay for processor type {play_from}...")
            n_da = 0
    else:
        n_da = 0
    if rec_from:
        if rec_from == "RX8":
            n_ad = 47
        elif rec_from == "RP2":
            n_ad = 65
        else:
            logging.warning(f"dont know A/D-delay for processor type {rec_from}...")
            n_ad = 0
    else:
        n_ad = 0
    return n_sound_traveling + n_da + n_ad