2010-01-27 23:12:09 +01:00
|
|
|
/* Simple resampler based on bsnes's ruby audio library */
|
|
|
|
|
|
|
|
#ifndef __RESAMPLER_H
|
|
|
|
#define __RESAMPLER_H
|
|
|
|
|
|
|
|
#include "ring_buffer.h"
|
|
|
|
|
|
|
|
class Resampler : public ring_buffer
|
|
|
|
{
|
|
|
|
public:
|
2010-04-06 04:13:53 +02:00
|
|
|
virtual void clear (void) = 0;
|
|
|
|
virtual void time_ratio (double) = 0;
|
|
|
|
virtual void read (short *, int) = 0;
|
|
|
|
virtual int avail (void) = 0;
|
|
|
|
|
2010-01-27 23:12:09 +01:00
|
|
|
Resampler (int num_samples) : ring_buffer (num_samples << 1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-29 19:33:25 +02:00
|
|
|
virtual ~Resampler ()
|
2010-01-27 23:12:09 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-06 04:13:53 +02:00
|
|
|
inline bool
|
2010-01-27 23:12:09 +01:00
|
|
|
push (short *src, int num_samples)
|
|
|
|
{
|
|
|
|
if (max_write () < num_samples)
|
|
|
|
return false;
|
|
|
|
|
2010-04-06 04:13:53 +02:00
|
|
|
!num_samples || ring_buffer::push ((unsigned char *) src, num_samples << 1);
|
2010-01-27 23:12:09 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-04-06 04:13:53 +02:00
|
|
|
inline int
|
|
|
|
space_empty (void)
|
|
|
|
{
|
|
|
|
return buffer_size - size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
space_filled (void)
|
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2010-01-27 23:12:09 +01:00
|
|
|
max_write (void)
|
|
|
|
{
|
|
|
|
return space_empty () >> 1;
|
|
|
|
}
|
|
|
|
|
2010-04-06 04:13:53 +02:00
|
|
|
inline void
|
2010-01-27 23:12:09 +01:00
|
|
|
resize (int num_samples)
|
|
|
|
{
|
|
|
|
ring_buffer::resize (num_samples << 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __RESAMPLER_H */
|