Loads the specified data into the buffer, using the specified format. */
| 403 | |
| 404 | /** Loads the specified data into the buffer, using the specified format. */ |
| 405 | void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALsizei freq, ALuint size, |
| 406 | UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData, |
| 407 | ALbitfieldSOFT access) |
| 408 | { |
| 409 | if UNLIKELY(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0) |
| 410 | SETERR_RETURN(context, AL_INVALID_OPERATION,, "Modifying storage for in-use buffer %u", |
| 411 | ALBuf->id); |
| 412 | |
| 413 | /* Currently no channel configurations need to be converted. */ |
| 414 | FmtChannels DstChannels{FmtMono}; |
| 415 | switch(SrcChannels) |
| 416 | { |
| 417 | case UserFmtMono: DstChannels = FmtMono; break; |
| 418 | case UserFmtStereo: DstChannels = FmtStereo; break; |
| 419 | case UserFmtRear: DstChannels = FmtRear; break; |
| 420 | case UserFmtQuad: DstChannels = FmtQuad; break; |
| 421 | case UserFmtX51: DstChannels = FmtX51; break; |
| 422 | case UserFmtX61: DstChannels = FmtX61; break; |
| 423 | case UserFmtX71: DstChannels = FmtX71; break; |
| 424 | case UserFmtBFormat2D: DstChannels = FmtBFormat2D; break; |
| 425 | case UserFmtBFormat3D: DstChannels = FmtBFormat3D; break; |
| 426 | } |
| 427 | if UNLIKELY(static_cast<long>(SrcChannels) != static_cast<long>(DstChannels)) |
| 428 | SETERR_RETURN(context, AL_INVALID_ENUM, , "Invalid format"); |
| 429 | |
| 430 | /* IMA4 and MSADPCM convert to 16-bit short. */ |
| 431 | FmtType DstType{FmtUByte}; |
| 432 | switch(SrcType) |
| 433 | { |
| 434 | case UserFmtUByte: DstType = FmtUByte; break; |
| 435 | case UserFmtShort: DstType = FmtShort; break; |
| 436 | case UserFmtFloat: DstType = FmtFloat; break; |
| 437 | case UserFmtDouble: DstType = FmtDouble; break; |
| 438 | case UserFmtAlaw: DstType = FmtAlaw; break; |
| 439 | case UserFmtMulaw: DstType = FmtMulaw; break; |
| 440 | case UserFmtIMA4: DstType = FmtShort; break; |
| 441 | case UserFmtMSADPCM: DstType = FmtShort; break; |
| 442 | } |
| 443 | |
| 444 | /* TODO: Currently we can only map samples when they're not converted. To |
| 445 | * allow it would need some kind of double-buffering to hold onto a copy of |
| 446 | * the original data. |
| 447 | */ |
| 448 | if((access&MAP_READ_WRITE_FLAGS)) |
| 449 | { |
| 450 | if UNLIKELY(static_cast<long>(SrcType) != static_cast<long>(DstType)) |
| 451 | SETERR_RETURN(context, AL_INVALID_VALUE,, "%s samples cannot be mapped", |
| 452 | NameFromUserFmtType(SrcType)); |
| 453 | } |
| 454 | |
| 455 | const ALuint unpackalign{ALBuf->UnpackAlign}; |
| 456 | const ALuint align{SanitizeAlignment(SrcType, unpackalign)}; |
| 457 | if UNLIKELY(align < 1) |
| 458 | SETERR_RETURN(context, AL_INVALID_VALUE,, "Invalid unpack alignment %u for %s samples", |
| 459 | unpackalign, NameFromUserFmtType(SrcType)); |
| 460 | |
| 461 | if((access&AL_PRESERVE_DATA_BIT_SOFT)) |
| 462 | { |
nothing calls this directly
no test coverage detected