MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / LoadWave

Method LoadWave

ogsr_engine/xrSound/SoundRender_Source_loader.cpp:52–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void CSoundRender_Source::LoadWave(LPCSTR pName)
53{
54 pname = pName;
55
56 // Load file into memory and parse WAV-format
57 OggVorbis_File ovf;
58 constexpr ov_callbacks ovc = {ov_read_func, ov_seek_func, ov_close_func, ov_tell_func};
59 IReader* wave = FS.r_open(pname.c_str());
60 R_ASSERT3(wave && wave->length(), "Can't open wave file:", pname.c_str());
61 ov_open_callbacks(wave, &ovf, NULL, 0, ovc);
62
63 vorbis_info* ovi = ov_info(&ovf, -1);
64 // verify
65 R_ASSERT3(ovi, "Invalid source info:", pName);
66
67#ifdef DEBUG
68 if (ovi->channels == 2)
69 {
70 Msg("stereo sound source [%s]", pName);
71 }
72#endif
73
74 ZeroMemory(&m_wformat, sizeof(WAVEFORMATEX));
75
76 m_wformat.nSamplesPerSec = (ovi->rate);
77 m_wformat.nChannels = u16(ovi->channels);
78
79 if (SoundRender->supports_float_pcm)
80 {
81 m_wformat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
82 m_wformat.wBitsPerSample = 32;
83 }
84 else
85 {
86 m_wformat.wFormatTag = WAVE_FORMAT_PCM;
87 m_wformat.wBitsPerSample = 16;
88 }
89
90 m_wformat.nBlockAlign = m_wformat.wBitsPerSample / 8 * m_wformat.nChannels;
91 m_wformat.nAvgBytesPerSec = m_wformat.nSamplesPerSec * m_wformat.nBlockAlign;
92
93 s64 pcm_total = ov_pcm_total(&ovf, -1);
94 dwBytesTotal = u32(pcm_total * m_wformat.nBlockAlign);
95 fTimeTotal = s_f_def_source_footer + dwBytesTotal / float(m_wformat.nAvgBytesPerSec);
96
97 vorbis_comment* ovm = ov_comment(&ovf, -1);
98 if (ovm->comments)
99 {
100 IReader F(ovm->user_comments[0], ovm->comment_lengths[0]);
101
102 u32 vers{};
103 if (F.elapsed() <= static_cast<int>(sizeof vers))
104 Msg("! Invalid ogg-comment, file: [%s]", pName);
105 else
106 vers = F.r_u32();
107
108 if (vers == 0x0001)
109 {

Callers

nothing calls this directly

Calls 15

ov_open_callbacksFunction · 0.85
ov_infoFunction · 0.85
MsgFunction · 0.85
ZeroMemoryFunction · 0.85
ov_pcm_totalFunction · 0.85
ov_commentFunction · 0.85
ov_clearFunction · 0.85
r_openMethod · 0.80
r_closeMethod · 0.80
u32Enum · 0.50
c_strMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected