60aabb91d7
The destructor of Resampler needs to be virtual, as it is subclassed and pointers to objects subclassed from it are being deleted. The issue in controls.cpp is that the loop ends up reading past the end of an array. The small rewrite of the loop also makes it more readable. In memmap.cpp, there is an assignment statement of the following form: a[i++] = b[i]; It is undefined what i's value should be in b[i], so this was made explicit.
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
/* 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:
|
|
virtual void clear (void) = 0;
|
|
virtual void time_ratio (double) = 0;
|
|
virtual void read (short *, int) = 0;
|
|
virtual int avail (void) = 0;
|
|
|
|
Resampler (int num_samples) : ring_buffer (num_samples << 1)
|
|
{
|
|
}
|
|
|
|
virtual ~Resampler ()
|
|
{
|
|
}
|
|
|
|
inline bool
|
|
push (short *src, int num_samples)
|
|
{
|
|
if (max_write () < num_samples)
|
|
return false;
|
|
|
|
!num_samples || ring_buffer::push ((unsigned char *) src, num_samples << 1);
|
|
|
|
return true;
|
|
}
|
|
|
|
inline int
|
|
space_empty (void) const
|
|
{
|
|
return buffer_size - size;
|
|
}
|
|
|
|
inline int
|
|
space_filled (void) const
|
|
{
|
|
return size;
|
|
}
|
|
|
|
inline int
|
|
max_write (void) const
|
|
{
|
|
return space_empty () >> 1;
|
|
}
|
|
|
|
inline void
|
|
resize (int num_samples)
|
|
{
|
|
ring_buffer::resize (num_samples << 1);
|
|
}
|
|
};
|
|
|
|
#endif /* __RESAMPLER_H */
|