Skip to content

Commit c7043ee

Browse files
committed
Load sound data
1 parent 2173a1a commit c7043ee

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

src/internal/scratch3reader.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ bool Scratch3Reader::load()
258258
sound->setRate(jsonSound["rate"]);
259259
READER_STEP(step, "target -> sound -> sampleCount");
260260
sound->setSampleCount(jsonSound["sampleCount"]);
261+
262+
if (m_zipReader && !sound->data()) {
263+
void *data;
264+
unsigned int size = m_zipReader->readFile(sound->fileName(), &data);
265+
sound->setData(size, data);
266+
}
267+
261268
target->addSound(sound);
262269
}
263270

test/Meow.wav

36.5 KB
Binary file not shown.

test/Pop.wav

560 Bytes
Binary file not shown.

test/load_project/load_project_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,14 @@ TEST(LoadProjectTest, LoadTestProject)
264264
ASSERT_EQ(comment->text(), "Hello, world!");
265265

266266
// Sprite1: sounds
267+
auto meowData = readFileStr("Meow.wav");
267268
auto sound = sprite1->soundAt(0);
268269
ASSERT_EQ(sound->name(), "Meow");
269270
ASSERT_FALSE(sound->id().empty());
270271
ASSERT_EQ(sound->fileName(), sound->id() + ".wav");
271272
ASSERT_EQ(sound->dataFormat(), "wav");
273+
ASSERT_TRUE(sound->data());
274+
ASSERT_EQ(memcmp(sound->data(), meowData.c_str(), sound->dataSize()), 0);
272275

273276
// Sprite1: variables
274277
ASSERT_VAR(sprite1, "var2");
@@ -424,11 +427,14 @@ TEST(LoadProjectTest, LoadTestProject)
424427
ASSERT_EQ(commentBlock->comment(), comment);
425428

426429
// Balloon1: sounds
430+
auto popData = readFileStr("Pop.wav");
427431
sound = sprite2->soundAt(0);
428432
ASSERT_EQ(sound->name(), "Pop");
429433
ASSERT_FALSE(sound->id().empty());
430434
ASSERT_EQ(sound->fileName(), sound->id() + ".wav");
431435
ASSERT_EQ(sound->dataFormat(), "wav");
436+
ASSERT_TRUE(sound->data());
437+
ASSERT_EQ(memcmp(sound->data(), popData.c_str(), sound->dataSize()), 0);
432438

433439
// Balloon1: variables
434440
ASSERT_VAR(sprite2, "var2");

0 commit comments

Comments
 (0)