2018-11-16 00:45:29 +01:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
#ifndef __RESAMPLER_H
|
|
|
|
#define __RESAMPLER_H
|
|
|
|
|
|
|
|
#include "ring_buffer.h"
|
|
|
|
|
|
|
|
class Resampler : public ring_buffer
|
|
|
|
{
|
|
|
|
public:
|
2010-09-25 18:46:06 +02:00
|
|
|
virtual void clear (void) = 0;
|
|
|
|
virtual void time_ratio (double) = 0;
|
|
|
|
virtual void read (short *, int) = 0;
|
|
|
|
virtual int avail (void) = 0;
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2010-09-25 17:46:12 +02:00
|
|
|
Resampler (int num_samples) : ring_buffer (num_samples << 1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-09 13:12:33 +02:00
|
|
|
virtual ~Resampler ()
|
2010-09-25 17:46:12 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-25 18:46:06 +02:00
|
|
|
inline bool
|
2010-09-25 17:46:12 +02:00
|
|
|
push (short *src, int num_samples)
|
|
|
|
{
|
|
|
|
if (max_write () < num_samples)
|
|
|
|
return false;
|
|
|
|
|
2010-09-25 18:46:06 +02:00
|
|
|
!num_samples || ring_buffer::push ((unsigned char *) src, num_samples << 1);
|
2010-09-25 17:46:12 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-25 18:46:06 +02:00
|
|
|
inline int
|
2016-09-27 22:25:37 +02:00
|
|
|
space_empty (void) const
|
2010-09-25 18:46:06 +02:00
|
|
|
{
|
|
|
|
return buffer_size - size;
|
|
|
|
}
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2010-09-25 18:46:06 +02:00
|
|
|
inline int
|
2016-09-27 22:25:37 +02:00
|
|
|
space_filled (void) const
|
2010-09-25 18:46:06 +02:00
|
|
|
{
|
|
|
|
return size;
|
|
|
|
}
|
2016-09-27 22:25:37 +02:00
|
|
|
|
2010-09-25 18:46:06 +02:00
|
|
|
inline int
|
2016-09-27 22:25:37 +02:00
|
|
|
max_write (void) const
|
2010-09-25 17:46:12 +02:00
|
|
|
{
|
|
|
|
return space_empty () >> 1;
|
|
|
|
}
|
|
|
|
|
2010-09-25 18:46:06 +02:00
|
|
|
inline void
|
2010-09-25 17:46:12 +02:00
|
|
|
resize (int num_samples)
|
|
|
|
{
|
|
|
|
ring_buffer::resize (num_samples << 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __RESAMPLER_H */
|