Skip to content
Snippets Groups Projects
  • Joshua Colp's avatar
    5606da75
    audiohook: Read the correct number of samples based on audiohook format. · 5606da75
    Joshua Colp authored
    Due to changes in audiohooks to support different sample rates the
    underlying storage of samples is in the format of the audiohook
    itself and not of the format being requested. This means that if a
    channel is using G722 the samples stored will be at 16kHz. If
    something subsequently reads from the audiohook at a format which
    is not the same sample rate as the audiohook the number of samples
    needs to be adjusted.
    
    Given the following example:
    1. Channel writing into audiohook at 16kHz (as it is using G722).
    2. Chanspy reading from audiohook at 8kHz.
    
    The original code would read 160 samples from the audiohook for
    each 20ms of audio. This is incorrect. Since the audio in the
    audiohook is at 16kHz the actual number needing to be read is 320.
    Failure to read this much would cause the audiohook to reset
    itself constantly as the buffer became full.
    
    This change adjusts the requested number of samples by determining
    the duration of audio requested and then calculating how many
    samples that would be in the audiohook format.
    
    ASTERISK-25247 #close
    
    Change-Id: Ia91ce516121882387a315fd8ee116b118b90653d
    5606da75
    History
    audiohook: Read the correct number of samples based on audiohook format.
    Joshua Colp authored
    Due to changes in audiohooks to support different sample rates the
    underlying storage of samples is in the format of the audiohook
    itself and not of the format being requested. This means that if a
    channel is using G722 the samples stored will be at 16kHz. If
    something subsequently reads from the audiohook at a format which
    is not the same sample rate as the audiohook the number of samples
    needs to be adjusted.
    
    Given the following example:
    1. Channel writing into audiohook at 16kHz (as it is using G722).
    2. Chanspy reading from audiohook at 8kHz.
    
    The original code would read 160 samples from the audiohook for
    each 20ms of audio. This is incorrect. Since the audio in the
    audiohook is at 16kHz the actual number needing to be read is 320.
    Failure to read this much would cause the audiohook to reset
    itself constantly as the buffer became full.
    
    This change adjusts the requested number of samples by determining
    the duration of audio requested and then calculating how many
    samples that would be in the audiohook format.
    
    ASTERISK-25247 #close
    
    Change-Id: Ia91ce516121882387a315fd8ee116b118b90653d
audiohook.c 48.08 KiB