|
From: Lasse Kärkkäi. <tr...@us...> - 2010-08-12 22:45:10
|
Module: performous
Branch: master
Commit: 07e9e2fa72fc060cf47a0bfc4476b26052689e17
Author: Lasse Karkkainen <tro...@tr...>
Date: Sun Jul 18 19:08:15 2010 +0300
Implement sample iterators and multichannel capture
---
game/audio.cc | 9 +++++----
libs/libda/include/libda/sample.hpp | 16 ++++++++++++++++
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/game/audio.cc b/game/audio.cc
index b92e325..458ee35 100644
--- a/game/audio.cc
+++ b/game/audio.cc
@@ -273,13 +273,14 @@ struct Device {
}
int operator()(void const* input, void* output, unsigned long frames, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags) try {
- float const* in = static_cast<float const*>(input);
- float* out = static_cast<float*>(output);
+ float const* inbuf = static_cast<float const*>(input);
+ float* outbuf = static_cast<float*>(output);
for (std::size_t i = 0; i < mics.size(); ++i) {
if (!mics[i]) continue; // No analyzer? -> Channel not used
- mics[i]->input(in, in + 1 * frames); // FIXME: needs libda iterators for multiple channel support
+ da::sample_const_iterator it = da::sample_const_iterator(inbuf + i, in);
+ mics[i]->input(it, it + frames);
}
- if (outptr) outptr->callback(out, out + 2 * frames);
+ if (outptr) outptr->callback(outbuf, outbuf + 2 * frames);
return paContinue;
} catch (std::exception& e) {
std::cerr << "Exception in audio callback: " << e.what() << std::endl;
diff --git a/libs/libda/include/libda/sample.hpp b/libs/libda/include/libda/sample.hpp
index 58502e0..29383e7 100644
--- a/libs/libda/include/libda/sample.hpp
+++ b/libs/libda/include/libda/sample.hpp
@@ -49,6 +49,22 @@ namespace da {
static inline int conv_to_s16_fast(sample_t s) { return static_cast<int>(s * max_s16); }
static inline int conv_to_s24_fast(sample_t s) { return static_cast<int>(s * max_s24); }
static inline int conv_to_s32_fast(sample_t s) { return static_cast<int>(s * max_s32); }
+
+ template <typename ValueType> class step_iterator: public std::iterator<std::random_access_iterator_tag, ValueType> {
+ ValueType* m_pos;
+ std::ptrdiff_t m_step;
+ public:
+ step_iterator(ValueType* pos, std::ptrdiff_t step): m_pos(pos), m_step(step) {}
+ ValueType& operator*() { return *m_pos; }
+ step_iterator operator+(std::ptrdiff_t rhs) { return step_iterator(m_pos + m_step * rhs, m_step); }
+ step_iterator& operator++() { m_pos += m_step; return *this; }
+ bool operator!=(step_iterator const& rhs) const { return m_pos != rhs.m_pos; }
+ std::ptrdiff_t operator-(step_iterator const& rhs) const { return (m_pos - rhs.m_pos) / m_step; }
+ // TODO: more operators
+ };
+
+ typedef step_iterator<sample_t> sample_iterator;
+ typedef step_iterator<sample_t const> sample_const_iterator;
}
#endif
|