MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / writeWavHeader

Function writeWavHeader

plugins/wasi_nn/wasinn_piper.cpp:32–66  ·  view source on GitHub ↗

Helper function to write the WAV header.

Source from the content-addressed store, hash-verified

30
31// Helper function to write the WAV header.
32void writeWavHeader(int SampleRate, int16_t NumChannels, int32_t NumSamples,
33 std::vector<uint8_t> &OutputBuffer) {
34 int32_t const ByteRate = SampleRate * NumChannels * sizeof(int16_t);
35 int32_t const DataSize = NumSamples * NumChannels * sizeof(int16_t);
36 int32_t const RiffSize = 36 + DataSize;
37
38 auto PushU32 = [&](int32_t Val) {
39 OutputBuffer.push_back(Val & 0xFF);
40 OutputBuffer.push_back((Val >> 8) & 0xFF);
41 OutputBuffer.push_back((Val >> 16) & 0xFF);
42 OutputBuffer.push_back((Val >> 24) & 0xFF);
43 };
44 auto PushU16 = [&](int16_t Val) {
45 OutputBuffer.push_back(Val & 0xFF);
46 OutputBuffer.push_back((Val >> 8) & 0xFF);
47 };
48 auto PushStr = [&](const char *Str) {
49 for (int I = 0; I < 4; I++)
50 OutputBuffer.push_back(Str[I]);
51 };
52
53 PushStr("RIFF");
54 PushU32(RiffSize);
55 PushStr("WAVE");
56 PushStr("fmt ");
57 PushU32(16);
58 PushU16(1);
59 PushU16(NumChannels);
60 PushU32(SampleRate);
61 PushU32(ByteRate);
62 PushU16(NumChannels * sizeof(int16_t));
63 PushU16(16);
64 PushStr("data");
65 PushU32(DataSize);
66}
67
68} // namespace
69template <typename T>

Callers 1

computeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected