Loads the specified data into the buffer, using the specified format. */
| 445 | |
| 446 | /** Loads the specified data into the buffer, using the specified format. */ |
| 447 | void 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}; |
nothing calls this directly
no test coverage detected