Go to the FreeLists Home Page Home Signup Help Login
 



[openbeos] || [Date Prev] [12-2007 Date Index] [Date Next] || [Thread Prev] [12-2007 Thread Index] [Thread Next]

[openbeos] Re: Resampling algorithms for audio mixer

  • From: "Stefano D'Angelo" <zanga.mail@xxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Wed, 5 Dec 2007 12:28:52 +0100
2007/11/29, Stefano D'Angelo <zanga.mail@xxxxxxxxx>:
> 2007/11/28, cyanh256@xxxxxxxxxxxx <cyanh256@xxxxxxxxxxxx>:
> > > What about "interpolating remaining one sample behind the input
> > > buffer" (so that you cannot have to interpolate values beyond  the
> > > innput buffer) and passing the last 3 or 4 samples of the previous
> > > input buffer through a struct, as you suggested, so that the values
> > > you now have to inteprolate before the input buffer are well defined?
> >
> > Exactly; that's pretty much what I was proposing. Preserving
> > state should clear up any potential concerns about sound quality
> > with very small buffer sizes (as an extreme example, one-sample
> > buffers!).
> >
> > It's been a while since I wrote any resampling code, but the
> > last one I wrote worked like this: (this is from memory, not
> > actual cut+paste code, so it probably won't work, and certainly
> > isn't optimized!)
> >
> > typedef struct RESAMPLER {
> >     int32 cur, prev;
> >     uint32 pos; /* Current fractional position */
> > } RESAMPLER;
> >
> > /*
> >  * Produce an output buffer at the desired sample rate,
> >  * reading the input stream as required.
> >  * 'out_rate' is the output sample rate relative to the input sample
> >  * rate in 16:16 fixed point format. e.g., with a 44100Hz output
> >  * rate and an 88200Hz input rate, 'out_rate' must be 32768.
> >  */
> > void resample(
> >     RESAMPLER *state,
> >     int16 *out_buf,
> >     size_t out_len,
> >     uint32 out_rate
> >     ) {
> >     for( ; out_len-- ; ) {
> >         *out_buf++ = (int16) (( state->cur * state->pos + state->prev *
> >  (~state->pos) ) >> 16);
> >         state->pos += out_rate;
> >         while( state->pos & 0xffff0000 ) {
> >             /* The position has overflowed into the next sample --
> >                read a new sample */
> >             state->pos -= 0x10000;
> >             state->prev = state->cur;
> >             state->cur = READ_SAMPLE(); /* This returns an int16 */
> >         }
> >     }
> > }
> >
> > The architecture is pretty different given that it uses an 'out_rate'
> > value
> > rather than using the relative sizes of the two buffers, and reads the
> > input stream internally rather than having a separate input buffer.
> > Though the idea of state preservation doesn't depend on that, of
> > course.
>
> Agreed, then.
>
> I'm waiting for you guys to tell me what to do exactly
> (library/integration into other libraries/just code/whatever).
>
> Anyway I have to warn you that I can work on it only in my "spare
> spare time", which means that I already work on a project of mine in
> my spare time (it can also interest you a lot, and I do hope so -
> maybe we can talk about it later), so don't expect it for the next
> week, ok? ;-)
>
> Stefano
>

I just couldn't wait :-)

http://libinterp.sourceforge.net

Stefano





[ Home | Signup | Help | Login | Archives | Lists ]

All trademarks and copyrights within the FreeLists archives are owned by their respective owners.
Everything else ©2007 Avenir Technologies, LLC.