MCPcopy Create free account
hub / github.com/bulletphysics/bullet3 / read

Method read

examples/TinyAudio/b3ReadWavFile.cpp:277–492  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277bool b3ReadWavFile::read(unsigned long startFrame, bool doNormalize)
278{
279 // Make sure we have an open file.
280 if (fd_ == 0)
281 {
282 // oStream_ << "FileRead::read: a file is not open!";
283 // Stk::handleError( StkError::WARNING ); return;
284 return false;
285 }
286
287 // Check the m_frames size.
288 unsigned long nFrames = this->m_numFrames; //m_frames.frames();
289 if (nFrames == 0)
290 {
291 // oStream_ << "FileRead::read: StkFrames m_frames size is zero ... no data read!";
292 // Stk::handleError( StkError::WARNING );
293 return false;
294 }
295
296 if (startFrame >= m_numFrames)
297 {
298 return false;
299 //oStream_ << "FileRead::read: startFrame argument is greater than or equal to the file size!";
300 //Stk::handleError( StkError::FUNCTION_ARGUMENT );
301 }
302
303 // Check for file end.
304 if (startFrame + nFrames > m_numFrames)
305 nFrames = m_numFrames - startFrame;
306
307 long i, nSamples = (long)(nFrames * channels_);
308 unsigned long offset = startFrame * channels_;
309
310 // Read samples into StkFrames data m_frames.
311 if (dataType_ == B3_SINT16)
312 {
313 signed short int *buf = (signed short int *)&m_frames[0];
314 if (fseek(fd_, dataOffset_ + (offset * 2), SEEK_SET) == -1)
315 return false;
316 if (fread(buf, nSamples * 2, 1, fd_) != 1)
317 return false;
318 if (byteswap_)
319 {
320 signed short int *ptr = buf;
321 for (i = nSamples - 1; i >= 0; i--)
322 b3Swap16((unsigned char *)ptr++);
323 }
324 if (doNormalize)
325 {
326 double gain = 1.0 / 32768.0;
327 for (i = nSamples - 1; i >= 0; i--)
328 m_frames[i] = buf[i] * gain;
329 }
330 else
331 {
332 for (i = nSamples - 1; i >= 0; i--)
333 m_frames[i] = buf[i];
334 }

Callers 12

loadWavFileMethod · 0.45
read_tga_fileMethod · 0.45
load_rle_dataMethod · 0.45
readLogFileFunction · 0.45
readLogFileFunction · 0.45
readLogFileFunction · 0.45
readLogFileFunction · 0.45
readLogFileFunction · 0.45
load_fileMethod · 0.45
restore_episodeMethod · 0.45

Calls 3

b3Swap16Function · 0.85
b3Swap32Function · 0.85
b3Swap64Function · 0.85

Tested by

no test coverage detected