Forums

About asynchronous sample rate conversion

Started by nagual.hsu March 15, 2006
    My audio capture and playback devices reference different crystal
clocks. I want to play the captured audio as "realtime" as possible.
Therefore I use Secret Rabbit Code to do dynamic sample rate conversion
as some sort of clock skew compensation.

Question 1:
    If the sample rate of the captured audio and the playback audio are 
all 8kHZ, do I have to use any low pass filter in case of noises after the
dynamic sample rate conversion?


Question 2:
    Suppose the sample rate of the captured audio are 16kHz, and I drop
one sample for every two samples, hence I can get an audio stream at
sample rate 8 khz. What low pass filter should I use after such
decimation?

    I know such questions are very common in this newsgroup. SinceI am a
big Math(or dsp) idiot, I can't fully understand the related old posts. If
possible, just give me some simple hints or references.

    Thank you.



in article R7edneHiPfYcz4XZnZ2dnUVZ_v2dnZ2d@giganews.com, nagual.hsu at
nagual.hsu@gmail.com wrote on 03/15/2006 12:44:

> My audio capture and playback devices reference different crystal > clocks.
that's asynchromous.
> I want to play the captured audio as "realtime" as possible. > Therefore I use Secret Rabbit Code to do dynamic sample rate conversion > as some sort of clock skew compensation. > > Question 1: > If the sample rate of the captured audio and the playback audio are > all 8kHZ, do I have to use any low pass filter in case of noises after the > dynamic sample rate conversion?
probably not. but this sounds like synchronous SRC.
> > Question 2: > Suppose the sample rate of the captured audio are 16kHz, and I drop > one sample for every two samples, hence I can get an audio stream at > sample rate 8 khz. What low pass filter should I use after such > decimation?
sounds to me like synchronous SRC again. you see, if it were asynchronous, then you would drop one sample for every two samples most of the time, but sometimes you would drop one sample for every three samples or maybe drop one sample for two adjacent samples. that's the kind of stuff you have to deal with when doing ASRC. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
nagual.hsu wrote:
> My audio capture and playback devices reference different crystal > clocks. I want to play the captured audio as "realtime" as possible. > Therefore I use Secret Rabbit Code to do dynamic sample rate conversion > as some sort of clock skew compensation. > > Question 1: > If the sample rate of the captured audio and the playback audio are > all 8kHZ, do I have to use any low pass filter in case of noises after the > dynamic sample rate conversion?
Probably not
> Question 2: > Suppose the sample rate of the captured audio are 16kHz, and I drop > one sample for every two samples, hence I can get an audio stream at > sample rate 8 khz. What low pass filter should I use after such > decimation?
You need to filter out all components at or above 4 KHz /before/ discarding the samples. With a non-recursive filter, you don't need to actually calculate the samples that will be discarded, but all the samples are inputs to the filter.
> I know such questions are very common in this newsgroup. SinceI am a > big Math(or dsp) idiot, I can't fully understand the related old posts. If > possible, just give me some simple hints or references.
If you don't understand something, just keep asking. jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
    Maybe I should clarify my questions. I have an audio capture device and
an playback device that reference two different crystal clocks. The audio
capture device samples the analog signal at 16kHZ. The playback device
runs at the sample rate of 8kHZ. Hence I drop one sample for every two
captured samples as some sort of decimation. I understand that I need a
low pass filter to cut off the audio frequency which is higher than 4kHZ,
but I don't know what filter should I use and I don't know how to use the
filter?

    Then I feed the decimated captured samples to the playback device.
Since I want this as "realtime" as possible, here I do asynchronous sample
rate conversion using Secret Rabbit Code. However, do I need some low pass
filter after such ASRC?

     Thanks.
>nagual.hsu wrote: >> Question 2: >> Suppose the sample rate of the captured audio are 16kHz, and I
drop
>> one sample for every two samples, hence I can get an audio stream at >> sample rate 8 khz. What low pass filter should I use after such >> decimation? > >You need to filter out all components at or above 4 KHz /before/ >discarding the samples. With a non-recursive filter, you don't need to >actually calculate the samples that will be discarded, but all the >samples are inputs to the filter. > >jerry
Thanks Jerry. But what filter should I use? A FIR filter or a polyphase filter?
nagual.hsu wrote:
>>nagual.hsu wrote: >> >>>Question 2: >>> Suppose the sample rate of the captured audio are 16kHz, and I > > drop > >>>one sample for every two samples, hence I can get an audio stream at >>>sample rate 8 khz. What low pass filter should I use after such >>>decimation? >> >>You need to filter out all components at or above 4 KHz /before/ >>discarding the samples. With a non-recursive filter, you don't need to >>actually calculate the samples that will be discarded, but all the >>samples are inputs to the filter. >> >>jerry > > > Thanks Jerry. But what filter should I use? A FIR filter or a > polyphase filter?
A polyphase filter is the efficient FIR implementation I mentioned. As R.B-J. pointed out, an exact 2:1 decimation is not asynchronous, but very nearly 2:1 or 1:1 is. If you really do need an asynchronous 2:1 decimation, you better plan to calculate every output sample so the extra that you might need to insert is available when it's needed. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
robert bristow-johnson wrote:
> in article R7edneHiPfYcz4XZnZ2dnUVZ_v2dnZ2d@giganews.com, nagual.hsu at > nagual.hsu@gmail.com wrote on 03/15/2006 12:44: > > > My audio capture and playback devices reference different crystal > > clocks. > > that's asynchromous. > > > I want to play the captured audio as "realtime" as possible. > > Therefore I use Secret Rabbit Code to do dynamic sample rate conversion > > as some sort of clock skew compensation. > > > > Question 1: > > If the sample rate of the captured audio and the playback audio are > > all 8kHZ, do I have to use any low pass filter in case of noises after the > > dynamic sample rate conversion? > > probably not. but this sounds like synchronous SRC. > > > > > Question 2: > > Suppose the sample rate of the captured audio are 16kHz, and I drop > > one sample for every two samples, hence I can get an audio stream at > > sample rate 8 khz. What low pass filter should I use after such > > decimation? > > sounds to me like synchronous SRC again. > > you see, if it were asynchronous, then you would drop one sample for every > two samples most of the time, but sometimes you would drop one sample for > every three samples or maybe drop one sample for two adjacent samples. > that's the kind of stuff you have to deal with when doing ASRC.
Since the capture and playback use two different crystals, the OP does need to do ASRC to match durations in real-time. It sounds like the OP doesn't want to drop samples, but instead something like interpolate N+-1 evenly spaced points from an 2N point buffer, with the +-1 (or +0) adjusted in real-time as needed. This can be done by windowed sinc reconstruction. Interpolated polyphase is one optimization possible for performance and power savings; but I've done it by calculating windowed sinc taps on the fly with just a few lines of code and no phase table (a fast PC can calculate several trancendental math functions faster than a VAX could do a single memory load from an array). If the data is already bandlimited to below half the final sample rate either initially or from a prior decimation, then no further filtering is needed, even though one gets another low pass filter for almost free from the sinc reconstruction process needed for SRC. IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M
nagual.hsu wrote:

> Maybe I should clarify my questions. I have an audio capture device > and > an playback device that reference two different crystal clocks. The audio > capture device samples the analog signal at 16kHZ. The playback device > runs at the sample rate of 8kHZ. Hence I drop one sample for every two > captured samples as some sort of decimation.
Better: always use the latest available sample from the 16k stream for the output. This avoids every additional ASRC efforts and gives almost a perfect result. Side effects: Low frequency distortions depending on the clock relations. And the usual 8kHz tone on the output. Both might be removed with a bandpass filter on the output.
> I understand that I need a > low pass filter to cut off the audio frequency which is higher than 4kHZ,
use a simple LPF before the capture device. Make sure that it has the required suppression at 8kHz, which is easy, since the passband region ends at 4kHz.
> but I don't know what filter should I use and I don't know how to use the > filter?
depends on your requirements on amplitude and phase response.
> > Then I feed the decimated captured samples to the playback device. > Since I want this as "realtime" as possible, here I do asynchronous sample > rate conversion using Secret Rabbit Code.
Not necessary any more (see above).
> However, do I need some low pass filter after such ASRC?
The relative change of the clocks will introduce low frequency components. I hope that you can live with them. Otherwise they would have to be removed here. In this case, there's a high-pass filter component. Then there's a typical 8kHz tone from the playback device (steps from the DAC). Check if this filter is built into the DAC already. Otherwise, you'll have to suppress this tone according to your spec. This will define the low-pass parameters for your filter.
> > Thanks.
Bernhard
>robert bristow-johnson wrote: >Since the capture and playback use two different crystals, the OP >does need to do ASRC to match durations in real-time. It sounds >like the OP doesn't want to drop samples, but instead something >like interpolate N+-1 evenly spaced points from an 2N point buffer, >with the +-1 (or +0) adjusted in real-time as needed. This can be >done by windowed sinc reconstruction. Interpolated polyphase is >one optimization possible for performance and power savings; >but I've done it by calculating windowed sinc taps on the fly with >just a few lines of code and no phase table (a fast PC can calculate >several trancendental math functions faster than a VAX could do >a single memory load from an array).
In fact, I want to record multiple captured audio streams and play one of the captured streams at the same time at the sampling rate of 8kHz. Due to my software architecture, I have to do SRC to decimate the captured audio samples to 8k HZ. Then I share one of the 8k HZ audio streams for both recording and playback. Unlike the "near-realtime" playback, recording(s) do not need ASRC. If you don't mind, can you give me the code? Or what referenced books you would suggest that I should study in order to know Interpolated polyphase? Thanks. :)
> >Better: always use the latest available sample from the 16k stream for
the
>output. This avoids every additional ASRC efforts and gives almost a >perfect result. >Side effects: Low frequency distortions depending on the clock
relations.
>And the usual 8kHz tone on the output. >Both might be removed with a bandpass filter on the output.
This sounds like a good method though this is not my software architecture.(Recording decimated captured streams at 8 kHZ while "near-realtime" playing one of the streams). If I understand you correctly, you probably mean this method would have some audio's frequency higher than 4 kHZ. Therefore, a bandpass filter is needed. Is this the "low frequency distortions" you mentioned above?
> >> I understand that I need a >> low pass filter to cut off the audio frequency which is higher than
4kHZ,
> >use a simple LPF before the capture device. Make sure that it has the >required suppression at 8kHz, which is easy, since the passband region
ends
>at 4kHz. > >> but I don't know what filter should I use and I don't know how to use
the
>> filter? >depends on your requirements on amplitude and phase response.
Does "amplitude" sometimes mean sound volume? And what is "phase response"? Sorry, I am a dsp idiot. :)
> >> However, do I need some low pass filter after such ASRC? > >The relative change of the clocks will introduce low frequency
components.
>I hope that you can live with them. Otherwise they would have to be
removed
>here. In this case, there's a high-pass filter component. >Then there's a typical 8kHz tone from the playback device (steps from
the
>DAC). Check if this filter is built into the DAC already. >Otherwise, you'll have to suppress this tone according to your spec. >This will define the low-pass parameters for your filter. >Bernhard
"The relative change of the clocks?" <-- Is this resulted from ASRC ( like some sort of dynamic clock adjustment)? Since the playback devices are the audio chips in the mother boards of a computer, I can't have the tone surpressed by the hardware. So that means I should have a low pass filter to remove the tone before just playback?