MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / read

Method read

Engine/source/sfx/media/sfxWavStream.cpp:259–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

257}
258
259U32 SFXWavStream::read( U8 *buffer, U32 bytes )
260{
261 AssertFatal( mStream, "SFXWavStream::seek() - Stream is null!" );
262
263 // Read in even sample chunks.
264
265 bytes -= bytes % mFormat.getBytesPerSample();
266
267 // Read the data and determine how much we've read.
268 // FileStreams apparently report positions past
269 // the actual stream length, so manually cap the
270 // numbers here.
271
272 const U32 oldPosition = mStream->getPosition();
273 mStream->read( bytes, buffer );
274 U32 newPosition = mStream->getPosition();
275 const U32 maxPosition = getDataLength() + mDataStart;
276 if( newPosition > maxPosition )
277 newPosition = maxPosition;
278
279 const U32 numBytesRead = newPosition - oldPosition;
280
281 // TODO: Is it *just* 16 bit samples that needs to
282 // be flipped? What about 32 bit samples?
283 #ifdef TORQUE_BIG_ENDIAN
284
285 // We need to endian-flip 16-bit data.
286 if ( getFormat().getBytesPerChannel() == 2 )
287 {
288 U16 *ds = (U16*)buffer;
289 U16 *de = (U16*)(buffer+bytes);
290 while (ds<de)
291 {
292 *ds = convertLEndianToHost(*ds);
293 ds++;
294 }
295 }
296
297 #endif
298
299 return numBytesRead;
300}

Callers 1

_readHeaderMethod · 0.45

Calls 3

getBytesPerSampleMethod · 0.80
getBytesPerChannelMethod · 0.80
getPositionMethod · 0.45

Tested by

no test coverage detected