blob: 09e27c61a9d6af7722360331ecedb956d27bcda2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#ifndef BASIC_SOURCE_H
#define BASIC_SOURCE_H
#include <vector>
#include <string>
#include "audiere.h"
namespace audiere {
struct Tag {
Tag(const std::string& k, const std::string& v, const std::string& t) {
key = k;
value = v;
type = t;
}
std::string key;
std::string value;
std::string type;
};
/**
* Basic implementation of a sample source including things such as
* repeat. BasicSource also defines the required methods for unseekable
* sources. Override them if you can seek.
*/
class BasicSource : public RefImplementation<SampleSource> {
public:
BasicSource();
/**
* Manages repeating within read(). Implement doRead() in
* implementation classes.
*/
int ADR_CALL read(int frame_count, void* buffer);
bool ADR_CALL isSeekable() { return false; }
int ADR_CALL getLength() { return 0; }
void ADR_CALL setPosition(int /*position*/) { }
int ADR_CALL getPosition() { return 0; }
bool ADR_CALL getRepeat() { return m_repeat; }
void ADR_CALL setRepeat(bool repeat) { m_repeat = repeat; }
int ADR_CALL getTagCount() { return int(m_tags.size()); }
const char* ADR_CALL getTagKey(int i) { return m_tags[i].key.c_str(); }
const char* ADR_CALL getTagValue(int i) { return m_tags[i].value.c_str(); }
const char* ADR_CALL getTagType(int i) { return m_tags[i].type.c_str(); }
/// Implement this method in subclasses.
virtual int doRead(int frame_count, void* buffer) = 0;
protected:
void addTag(const Tag& t) {
m_tags.push_back(t);
}
void addTag(const std::string& k, const std::string& v, const std::string& t) {
addTag(Tag(k, v, t));
}
private:
bool m_repeat;
std::vector<Tag> m_tags;
};
}
#endif
|