Skip to content

Commit 3cee189

Browse files
committed
soundcodec: implement the builtin sound/null.wav file
1 parent af36e91 commit 3cee189

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/engine/audio/SoundCodec.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ static const soundExtToLoaderMap_t soundLoaders[] =
5050

5151
static int numSoundLoaders = ARRAY_LEN(soundLoaders);
5252

53+
static bool IsNullSample(std::string& filename)
54+
{
55+
if (Str::IsPrefix("sound/null", filename)) {
56+
if (filename == "sound/null") {
57+
return true;
58+
}
59+
60+
std::string basename = FS::Path::StripExtension(filename);
61+
62+
if (basename == "sound/null") {
63+
return true;
64+
}
65+
}
66+
67+
return false;
68+
}
69+
70+
static AudioData LoadNullSample()
71+
{
72+
// 16bit mono 8KHz, 1 sample, silence.
73+
unsigned char *null_wav = (unsigned char*) calloc( 1, 2 );
74+
AudioData out { 8000, 2, 1 };
75+
out.rawSamples.assign( null_wav, null_wav + 2 );
76+
return out;
77+
}
78+
5379
static int FindSoundLoader(std::string filename)
5480
{
5581
const FS::PakInfo* bestPak = nullptr;
@@ -77,6 +103,9 @@ static int FindSoundLoader(std::string filename)
77103

78104
AudioData LoadSoundCodec(std::string filename)
79105
{
106+
if (IsNullSample(filename)) {
107+
return LoadNullSample();
108+
}
80109

81110
std::string ext = FS::Path::Extension(filename);
82111

0 commit comments

Comments
 (0)