Skip to content

Commit 83d6439

Browse files
committed
Optimize fixed sample sizes
1 parent 622f28d commit 83d6439

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/AudioTools/AudioCodecs/M4AAudioDemuxer.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ class M4AAudioDemuxer {
9191
}
9292

9393
Vector<size_t>& getSampleSizes() { return sampleSizes; }
94+
9495
Vector<size_t>& getChunkOffsets() { return chunkOffsets; }
96+
97+
// used fixed sizes instead of the sampleSizes table
98+
void setFixedSampleCount(uint32_t sampleSize, uint32_t sampleCount) {
99+
fixed_sample_size = sampleSize;
100+
fixed_sample_count = sampleCount;
101+
}
102+
95103

96104
void setAACConfig(int profile, int srIdx, int chCfg) {
97105
aacProfile = profile;
@@ -108,6 +116,8 @@ class M4AAudioDemuxer {
108116
size_t sampleIndex = 0;
109117
SingleBuffer<uint8_t> buffer;
110118
int aacProfile = 2, sampleRateIdx = 4, channelCfg = 2;
119+
uint32_t fixed_sample_size = 0;
120+
uint32_t fixed_sample_count = 0;
111121
size_t current_size = 0; // current sample size
112122
size_t box_size = 0; // maximum size of the current sample
113123
size_t box_pos = 0;
@@ -157,7 +167,12 @@ class M4AAudioDemuxer {
157167
}
158168

159169
size_t currentSampleSize() {
160-
if (sampleSizes && sampleIndex < sampleSizes.size()) {
170+
// using fixed sizes w/o table
171+
if (fixed_sample_size > 0 && fixed_sample_count > 0 &&
172+
sampleIndex < fixed_sample_count) {
173+
return fixed_sample_size;
174+
}
175+
if (sampleSizes && sampleIndex < sampleSizes.size()) {
161176
return sampleSizes[sampleIndex];
162177
}
163178
return 0;
@@ -366,7 +381,7 @@ class M4AAudioDemuxer {
366381
uint8_t asc_len = box.data[i + 1];
367382
if (i + 2 + asc_len > box.data_size) {
368383
LOGW("esds box not long enough for AudioSpecificConfig");
369-
//break;
384+
break;
370385
};
371386
const uint8_t* asc = box.data + i + 2;
372387
// AudioSpecificConfig is at least 2 bytes
@@ -408,7 +423,7 @@ class M4AAudioDemuxer {
408423
sampleSizes[i] = readU32(data + 12 + i * 4);
409424
}
410425
} else {
411-
sampleSizes.assign(sampleCount, sampleSize);
426+
sampleExtractor.setFixedSampleCount(sampleSize, sampleCount);
412427
}
413428
}
414429

tests-cmake/codec/container-m4a/m4a.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void setup() {
3232
return;
3333
}
3434

35-
file = SD.open("/home/pschatzmann/Music/m4a/1-07 All You Need Is Love.m4a");
35+
file = SD.open("/home/pschatzmann/Music/m4a/03 We'll never speak again.m4a");
3636
if (!file.isOpen()) {
3737
Serial.println("Failed to open file!");
3838
return;

0 commit comments

Comments
 (0)