-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioFileSourceSdFs.cpp
83 lines (67 loc) · 1.31 KB
/
AudioFileSourceSdFs.cpp
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
73
74
75
76
77
78
79
80
81
82
83
#include "AudioFileSourceSdFs.h"
#include "PrintString.h"
AudioFileSourceSdFs::AudioFileSourceSdFs(SdFs& card)
: card(card)
{
}
AudioFileSourceSdFs::AudioFileSourceSdFs(SdFs& card, const char* filename)
: card(card)
{
open(filename);
}
bool AudioFileSourceSdFs::open(const char* filename)
{
f = card.open(filename, O_RDONLY);
return f;
}
AudioFileSourceSdFs::~AudioFileSourceSdFs()
{
if (f)
f.close();
}
uint32_t AudioFileSourceSdFs::read(void* data, uint32_t len)
{
if (!f)
return 0;
return f.read(static_cast<uint8_t*>(data), len);
}
bool AudioFileSourceSdFs::seek(int32_t pos, int dir)
{
if (!f)
return false;
if (dir == SEEK_SET)
return f.seek(pos);
else if (dir == SEEK_CUR)
return f.seek(f.position() + pos);
else if (dir == SEEK_END)
return f.seek(f.size() + pos);
return false;
}
bool AudioFileSourceSdFs::close()
{
if (!f)
return false;
f.close();
return true;
}
bool AudioFileSourceSdFs::isOpen() { return f ? true : false; }
uint32_t AudioFileSourceSdFs::getSize()
{
if (!f)
return 0;
return f.size();
}
uint32_t AudioFileSourceSdFs::getPos()
{
if (!f)
return 0;
return f.position();
}
String AudioFileSourceSdFs::file_name() const
{
if (!f)
return {};
PrintString base_name;
const_cast<AudioFileSourceSdFs*>(this)->f.printName(&base_name);
return base_name.getString();
}