-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrwstream.cpp
More file actions
82 lines (70 loc) · 1.73 KB
/
rwstream.cpp
File metadata and controls
82 lines (70 loc) · 1.73 KB
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
#include "rwstream.h"
#include "rwexception.h"
#include "rwtrack.h"
#include "rwtypes.h"
//-----------------------------------------------------------------------------
rws::stream::stream(const std::string& filename)
{
auto f = file(filename);
fprintf(stdout, "reading '%s'\n", filename.c_str());
// read container header
read(f);
// search for audio header
for (;;)
{
m_header.read(f);
if (m_header.type() == audio_header)
break;
f.seek(m_header.end());
}
// read start of audio header
uint32_t header_size;
f.read(header_size);
f.skip(0x1c);
f.read_be(m_track_count);
f.skip(0x2c);
std::string stream_name;
f.read(stream_name);
// read per-track headers
m_tracks.reserve(m_track_count);
for (uint32_t i = 0; i < m_track_count; ++i)
{
auto track = new rws::track{i};
track->read_location(f);
m_tracks.emplace_back(track);
}
for (auto t : m_tracks)
t->read_size(f);
f.skip(0x10 * m_track_count);
for (auto t : m_tracks)
t->read_name(f);
// read end of audio header
f.skip(0x10);
f.read_be(m_cluster_size);
f.skip(0xc);
f.read_be(m_cluster_used_bytes);
f.skip<uint32_t>();
f.read_be(m_sample_rate);
f.skip(0x9);
f.read_be(m_channels);
// set track layouts
for (auto t : m_tracks)
t->set_layout(m_channels, m_sample_rate);
// search for data header
f.seek(m_header.end());
for (;;)
{
m_data.read(f);
if (m_data.type() == audio_data)
break;
f.seek(m_data.end());
}
// read track data
auto const start = m_data.start();
for (auto t : m_tracks)
t->read_data(f, start, m_cluster_size, m_cluster_used_bytes);
}
//-----------------------------------------------------------------------------
rws::stream::~stream()
{
}