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

Function LoadData

Engine/lib/openal-soft/al/buffer.cpp:447–601  ·  view source on GitHub ↗

Loads the specified data into the buffer, using the specified format. */

Source from the content-addressed store, hash-verified

445
446/** Loads the specified data into the buffer, using the specified format. */
447void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size,
448 UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData,
449 ALbitfieldSOFT access)
450{
451 if UNLIKELY(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0)
452 SETERR_RETURN(context, AL_INVALID_OPERATION,, "Modifying storage for in-use buffer %u",
453 ALBuf->id);
454
455 /* Currently no channel configurations need to be converted. */
456 FmtChannels DstChannels{FmtMono};
457 switch(SrcChannels)
458 {
459 case UserFmtMono: DstChannels = FmtMono; break;
460 case UserFmtStereo: DstChannels = FmtStereo; break;
461 case UserFmtRear: DstChannels = FmtRear; break;
462 case UserFmtQuad: DstChannels = FmtQuad; break;
463 case UserFmtX51: DstChannels = FmtX51; break;
464 case UserFmtX61: DstChannels = FmtX61; break;
465 case UserFmtX71: DstChannels = FmtX71; break;
466 case UserFmtBFormat2D: DstChannels = FmtBFormat2D; break;
467 case UserFmtBFormat3D: DstChannels = FmtBFormat3D; break;
468 }
469 if UNLIKELY(static_cast<long>(SrcChannels) != static_cast<long>(DstChannels))
470 SETERR_RETURN(context, AL_INVALID_ENUM, , "Invalid format");
471
472 /* IMA4 and MSADPCM convert to 16-bit short. */
473 FmtType DstType{FmtUByte};
474 switch(SrcType)
475 {
476 case UserFmtUByte: DstType = FmtUByte; break;
477 case UserFmtShort: DstType = FmtShort; break;
478 case UserFmtFloat: DstType = FmtFloat; break;
479 case UserFmtDouble: DstType = FmtDouble; break;
480 case UserFmtAlaw: DstType = FmtAlaw; break;
481 case UserFmtMulaw: DstType = FmtMulaw; break;
482 case UserFmtIMA4: DstType = FmtShort; break;
483 case UserFmtMSADPCM: DstType = FmtShort; break;
484 }
485
486 /* TODO: Currently we can only map samples when they're not converted. To
487 * allow it would need some kind of double-buffering to hold onto a copy of
488 * the original data.
489 */
490 if((access&MAP_READ_WRITE_FLAGS))
491 {
492 if UNLIKELY(static_cast<long>(SrcType) != static_cast<long>(DstType))
493 SETERR_RETURN(context, AL_INVALID_VALUE,, "%s samples cannot be mapped",
494 NameFromUserFmtType(SrcType));
495 }
496
497 const ALuint unpackalign{ALBuf->UnpackAlign};
498 const ALuint align{SanitizeAlignment(SrcType, unpackalign)};
499 if UNLIKELY(align < 1)
500 SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %u for %s samples",
501 unpackalign, NameFromUserFmtType(SrcType));
502
503 const ALuint ambiorder{(DstChannels == FmtBFormat2D || DstChannels == FmtBFormat3D) ?
504 ALBuf->UnpackAmbiOrder : 0};

Callers

nothing calls this directly

Calls 15

UNLIKELYFunction · 0.85
ReadRefFunction · 0.85
NameFromUserFmtTypeFunction · 0.85
SanitizeAlignmentFunction · 0.85
ChannelsFromUserFmtFunction · 0.85
BytesFromUserFmtFunction · 0.85
ChannelsFromFmtFunction · 0.85
BytesFromFmtFunction · 0.85
RoundUpFunction · 0.85
minzFunction · 0.85
Convert_int16_ima4Function · 0.85
Convert_int16_msadpcmFunction · 0.85

Tested by

no test coverage detected