File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -18,16 +18,22 @@ namespace YoaEngine
18
18
// amaount of channels present in the buffer
19
19
uint8_t Channels;
20
20
21
- float GetSample (const uint32_t position) noexcept {
21
+ float GetSample (const uint32_t position) noexcept
22
+ {
23
+ // setup constants
24
+ constexpr auto uint8Max = 255 .0f ;
25
+ constexpr auto sint16Max = 32768 .0f ;
26
+ constexpr auto sint32Max = 2147483648 .0f ;
27
+ // output a sample format
22
28
switch (Format) {
23
29
case YOA_Format_Float:
24
30
return ((float *)Buffer)[position];
25
31
case YOA_Format_Uint8:
26
- return ( float )( Buffer) [position] / 128 . 0f - 1 . 0f ;
32
+ return Buffer[position] / uint8Max ;
27
33
case YOA_Format_Sint16:
28
- return (float )((int16_t *)Buffer)[position] / 32768 . 0f ;
34
+ return (float )((int16_t *)Buffer)[position] / sint16Max ;
29
35
case YOA_Format_Sint32:
30
- return (float )((int32_t *)Buffer)[position] / 2147483648 . 0f ;
36
+ return (float )((int32_t *)Buffer)[position] / sint32Max ;
31
37
case YOA_Format_Unknown:
32
38
default :
33
39
return 0 .0f ;
You can’t perform that action at this time.
0 commit comments