Menu

Variable rate conversion when input and output rates are equal?

2017-05-23
2017-06-14
  • Ruurd Adema

    Ruurd Adema - 2017-05-23

    Thank you for this wonderfull library!

    Is it possible to use the variable rate conversion when both input rate and output rates are the same? I intend to use libsoxr as drift compensation mechanism between 2 clock domains.

    When I convert from 96KHz to 48KHz it works well, but when I convert from 48KHz to 48KHz it produces audible clicks in the audio.

    I setup the resampler like this:

    soxr_in_spec = soxr_quality_spec(SOXR_HQ, SOXR_VR);
    
    soxr = soxr_create(
                input_sample_rate,  // (48KHz or 96KHz)
                output_sample_rate, // (48KHz)
                channel_count,
                NULL,
                NULL,
                &soxr_in_spec,
                NULL);
    
    Note: simplified for clarity purposes
    

    And then when the sample blocks flow in I do this:

    soxr_set_io_ratio(
                soxr, 
                ((source_sample_rate * rate_scalar) / destination_sample_rate), 
                sample_block_size);
    
    soxr_process(
                soxr,
                in.buffer,
                in.buffer_len,
                &idone,
                out.buffer,
                out.buffer_len,
                &odone));
    
    Note: simplified for clarity purposes
    
     

    Last edit: Ruurd Adema 2017-05-23
  • robs

    robs - 2017-05-28

    Yes, it is possible to use the variable rate conversion when both input rate and output rates are the same. I've just run this simple test here, using one of the supplied examples, and all seems to work as expected: ./3-options-input-fn 48000 48000 2 0 0 4 20 < input.f32 > output.f32

    Note that with variable-rate conversion, the sample-rates given in soxr_create determine the maximum I/O ratio that will be used. So if, for example, input_sample_rate & output_sample_rate are both given as 48kHz in soxr_create, then every subsequent call to soxr_set_io_ratio must have I/O ratio <= 1; if not then audible clicks can occur—could this explain what is happening in your case?

     
  • Ruurd Adema

    Ruurd Adema - 2017-06-01

    Hi Rob,

    Thank you for your response!

    The thing you described about the maximum I/O ratio was indeed partly cause of the distortion (the other being an out of bound write of 1 byte in another part of my code).

    • Am I correct that when using variable rate conversion the ratio values used in soxr_create have no relation to the actual sample rates other than defining the maximum I/O? (tests suggest this is indeed the case, but I want to make sure I'm correct)
    • What are the limits of the skew value when setting soxr_set_io_ratio? Should the value always be smaller or bigger than the input or output block size?
     
  • robs

    robs - 2017-06-04

    Glad to hear that you're making progress!
    1st question: Yes, that's right.
    2nd question: I don't think that ther has to be any particular relationship between these values (and there are no specific limits), but where the rate is changing continuously (such as in the supplied example # 5), it may be convenient to make them them the same.

     
  • Ruurd Adema

    Ruurd Adema - 2017-06-09

    Hi Rob,

    Things are going very well with libsoxr and variable rate conversion!

    Hope you don't mind me asking another question.

    Are there any effects of choosing a specific max IO ratio (other than setting is too low)?
    Is there any relationship between speed and/or quality and the max IO ratio?

    For example: assume frequency ranges between (and including) 44.1 KHz & 192 KHz, would it be sufficient to set the max IO ratio using those max/min values (or a ratio of 1000 to 1), even if the actual ratio is going to be smaller? Are there any drawbacks in that case?

     
  • robs

    robs - 2017-06-10

    Hello again,

    The only effect of specifying a higher max. IO ratio than you actually end up using is that some memory allocated at soxr_create() time for processing the higher IO ratios will remain unused—but this shouldn't usually be much of a problem.

    HTH, Rob.

     
  • Ruurd Adema

    Ruurd Adema - 2017-06-14

    Thanks!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.