| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
/* Simple resampler based on bsnes's ruby audio library */ |
| 2 | 2 |
|
| 3 |
-#ifndef __RESAMPLER_H |
|
| 4 |
-#define __RESAMPLER_H |
|
| 3 |
+#pragma once |
|
| 5 | 4 |
|
| 6 | 5 |
#include "ring_buffer.h" |
| 7 | 6 |
|
| ... | ... |
@@ -41,5 +40,3 @@ public: |
| 41 | 40 |
ring_buffer::resize(num_samples << 1); |
| 42 | 41 |
} |
| 43 | 42 |
}; |
| 44 |
- |
|
| 45 |
-#endif /* __RESAMPLER_H */ |
| ... | ... |
@@ -7,54 +7,39 @@ |
| 7 | 7 |
|
| 8 | 8 |
class Resampler : public ring_buffer |
| 9 | 9 |
{
|
| 10 |
- public: |
|
| 11 |
- virtual void clear() = 0; |
|
| 12 |
- virtual void time_ratio (double) = 0; |
|
| 13 |
- virtual void read (short *, int) = 0; |
|
| 14 |
- virtual int avail() = 0; |
|
| 15 |
- |
|
| 16 |
- Resampler (int num_samples) : ring_buffer (num_samples << 1) |
|
| 17 |
- {
|
|
| 18 |
- } |
|
| 19 |
- |
|
| 20 |
- ~Resampler () |
|
| 21 |
- {
|
|
| 22 |
- } |
|
| 23 |
- |
|
| 24 |
- inline bool |
|
| 25 |
- push (short *src, int num_samples) |
|
| 26 |
- {
|
|
| 27 |
- if (max_write () < num_samples) |
|
| 28 |
- return false; |
|
| 29 |
- |
|
| 30 |
- !num_samples || ring_buffer::push ((unsigned char *) src, num_samples << 1); |
|
| 31 |
- |
|
| 32 |
- return true; |
|
| 33 |
- } |
|
| 34 |
- |
|
| 35 |
- inline int |
|
| 36 |
- space_empty() |
|
| 37 |
- {
|
|
| 38 |
- return buffer_size - size; |
|
| 39 |
- } |
|
| 40 |
- |
|
| 41 |
- inline int |
|
| 42 |
- space_filled() |
|
| 43 |
- {
|
|
| 44 |
- return size; |
|
| 45 |
- } |
|
| 46 |
- |
|
| 47 |
- inline int |
|
| 48 |
- max_write() |
|
| 49 |
- {
|
|
| 50 |
- return space_empty () >> 1; |
|
| 51 |
- } |
|
| 52 |
- |
|
| 53 |
- inline void |
|
| 54 |
- resize (int num_samples) |
|
| 55 |
- {
|
|
| 56 |
- ring_buffer::resize (num_samples << 1); |
|
| 57 |
- } |
|
| 10 |
+public: |
|
| 11 |
+ virtual void clear() = 0; |
|
| 12 |
+ virtual void time_ratio(double) = 0; |
|
| 13 |
+ virtual void read(short *, int) = 0; |
|
| 14 |
+ virtual int avail() = 0; |
|
| 15 |
+ |
|
| 16 |
+ Resampler(int num_samples) : ring_buffer(num_samples << 1) |
|
| 17 |
+ {
|
|
| 18 |
+ } |
|
| 19 |
+ |
|
| 20 |
+ virtual ~Resampler() |
|
| 21 |
+ {
|
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ bool push(short *src, int num_samples) |
|
| 25 |
+ {
|
|
| 26 |
+ if (this->max_write() < num_samples) |
|
| 27 |
+ return false; |
|
| 28 |
+ |
|
| 29 |
+ !num_samples || ring_buffer::push(reinterpret_cast<unsigned char *>(src), num_samples << 1); |
|
| 30 |
+ |
|
| 31 |
+ return true; |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ int max_write() |
|
| 35 |
+ {
|
|
| 36 |
+ return this->space_empty () >> 1; |
|
| 37 |
+ } |
|
| 38 |
+ |
|
| 39 |
+ void resize(int num_samples) |
|
| 40 |
+ {
|
|
| 41 |
+ ring_buffer::resize(num_samples << 1); |
|
| 42 |
+ } |
|
| 58 | 43 |
}; |
| 59 | 44 |
|
| 60 | 45 |
#endif /* __RESAMPLER_H */ |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,60 @@ |
| 1 |
+/* Simple resampler based on bsnes's ruby audio library */ |
|
| 2 |
+ |
|
| 3 |
+#ifndef __RESAMPLER_H |
|
| 4 |
+#define __RESAMPLER_H |
|
| 5 |
+ |
|
| 6 |
+#include "ring_buffer.h" |
|
| 7 |
+ |
|
| 8 |
+class Resampler : public ring_buffer |
|
| 9 |
+{
|
|
| 10 |
+ public: |
|
| 11 |
+ virtual void clear() = 0; |
|
| 12 |
+ virtual void time_ratio (double) = 0; |
|
| 13 |
+ virtual void read (short *, int) = 0; |
|
| 14 |
+ virtual int avail() = 0; |
|
| 15 |
+ |
|
| 16 |
+ Resampler (int num_samples) : ring_buffer (num_samples << 1) |
|
| 17 |
+ {
|
|
| 18 |
+ } |
|
| 19 |
+ |
|
| 20 |
+ ~Resampler () |
|
| 21 |
+ {
|
|
| 22 |
+ } |
|
| 23 |
+ |
|
| 24 |
+ inline bool |
|
| 25 |
+ push (short *src, int num_samples) |
|
| 26 |
+ {
|
|
| 27 |
+ if (max_write () < num_samples) |
|
| 28 |
+ return false; |
|
| 29 |
+ |
|
| 30 |
+ !num_samples || ring_buffer::push ((unsigned char *) src, num_samples << 1); |
|
| 31 |
+ |
|
| 32 |
+ return true; |
|
| 33 |
+ } |
|
| 34 |
+ |
|
| 35 |
+ inline int |
|
| 36 |
+ space_empty() |
|
| 37 |
+ {
|
|
| 38 |
+ return buffer_size - size; |
|
| 39 |
+ } |
|
| 40 |
+ |
|
| 41 |
+ inline int |
|
| 42 |
+ space_filled() |
|
| 43 |
+ {
|
|
| 44 |
+ return size; |
|
| 45 |
+ } |
|
| 46 |
+ |
|
| 47 |
+ inline int |
|
| 48 |
+ max_write() |
|
| 49 |
+ {
|
|
| 50 |
+ return space_empty () >> 1; |
|
| 51 |
+ } |
|
| 52 |
+ |
|
| 53 |
+ inline void |
|
| 54 |
+ resize (int num_samples) |
|
| 55 |
+ {
|
|
| 56 |
+ ring_buffer::resize (num_samples << 1); |
|
| 57 |
+ } |
|
| 58 |
+}; |
|
| 59 |
+ |
|
| 60 |
+#endif /* __RESAMPLER_H */ |