mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-21 15:56:58 +02:00
168 lines
2.6 KiB
Plaintext
168 lines
2.6 KiB
Plaintext
# The worlds worst programming language!
|
|
#
|
|
# The final result needs to be moved to the "r" variable. The input sample is "x".
|
|
#
|
|
# Instructions
|
|
# ============
|
|
# add [output] [a] [b] -> output = a + b
|
|
# sub [output] [a] [b] -> output = a - b
|
|
# mul [output] [a] [b] -> output = a * b
|
|
# div [output] [a] [b] -> output = a / b
|
|
# shl [output] [a] [b] -> output = a << b
|
|
# shr [output] [a] [b] -> output = a >> b
|
|
# sig [output] [b] -> output = (sign bit in "a" is set) ? 1 : 0
|
|
# mov [output] [a] -> output = a;
|
|
# clip [output] [a] -> output = clamp(a, -1, 1)
|
|
#
|
|
# int [name] -> Declare an uninitialized 32-bit integer
|
|
# flt [name] -> Declare an uninitialized 32-bit float
|
|
|
|
# r = (x - 128) << 8
|
|
u8->s16 {
|
|
sub r x 128;
|
|
shl r r 8;
|
|
}
|
|
|
|
# r = (x - 128) << 16
|
|
u8->s24 {
|
|
sub r x 128;
|
|
shl r r 16;
|
|
}
|
|
|
|
# r = (x - 128) << 24
|
|
u8->s32 {
|
|
sub r x 128;
|
|
shl r r 24;
|
|
}
|
|
|
|
# r = (x / 255) * 2 - 1
|
|
# = (x / 127.5) - 1
|
|
# = (x * 0.00784313725490196078) - 1
|
|
u8->f32 {
|
|
mul r x 0.00784313725490196078f;
|
|
sub r r 1;
|
|
}
|
|
|
|
|
|
|
|
# r = (x >> 8) + 128
|
|
s16->u8 {
|
|
shr r x 8;
|
|
add r r 128;
|
|
}
|
|
|
|
# r = x << 8
|
|
s16->s24 {
|
|
shl r x 8;
|
|
}
|
|
|
|
# r = x << 16
|
|
s16->s32 {
|
|
shl r x 16;
|
|
}
|
|
|
|
# r = ((x + 32768) / 65535) * 2 - 1
|
|
# = (x + 32768) / 32767.5) - 1
|
|
# = (x + 32768) * 0.00003051804379339284) - 1
|
|
s16->f32 {
|
|
add (flt)r x 32768;
|
|
mul r r 0.00003051804379339284f;
|
|
sub r r 1;
|
|
}
|
|
|
|
|
|
|
|
# r = (x >> 16) + 128
|
|
s24->u8 {
|
|
shr r x 16;
|
|
add r r 128;
|
|
}
|
|
|
|
# r = x >> 8
|
|
s24->s16 {
|
|
shr r x 8;
|
|
}
|
|
|
|
# r = x << 8
|
|
s24->s32 {
|
|
shl r x 8;
|
|
}
|
|
|
|
# r = ((x + 8388608) / 16777215) * 2 - 1
|
|
# = (x + 8388608) / 8388607.5) - 1
|
|
# = (x + 8388608) * 0.00000011920929665621) - 1
|
|
s24->f32 {
|
|
add (flt)r x 8388608;
|
|
mul r r 0.00000011920929665621f;
|
|
sub r r 1;
|
|
}
|
|
|
|
|
|
|
|
# r = (x >> 24) + 128
|
|
s32->u8 {
|
|
shr r x 24;
|
|
add r r 128;
|
|
}
|
|
|
|
# r = x >> 16
|
|
s32->s16 {
|
|
shr r x 16;
|
|
}
|
|
|
|
# r = x >> 8
|
|
s32->s24 {
|
|
shr r x 8;
|
|
}
|
|
|
|
# r = x / (2147483647 + sign(x))
|
|
s32->f32 {
|
|
int s;
|
|
sig s x;
|
|
add s s 2147483647;
|
|
div r x (flt)(uint)s;
|
|
}
|
|
|
|
|
|
|
|
# r = (clip(x) * (0x7F + sign(x))) + 128
|
|
f32->u8 {
|
|
flt c;
|
|
int s;
|
|
clip c x;
|
|
sig s x;
|
|
add s s 127;
|
|
mul (int)r c s;
|
|
add r r 128;
|
|
}
|
|
|
|
# r = clip(x) * (0x7FFF + sign(x))
|
|
f32->s16 {
|
|
flt c;
|
|
int s;
|
|
clip c x;
|
|
sig s x;
|
|
add s s 32767;
|
|
mul (int)r c s;
|
|
}
|
|
|
|
# r = clip(x) * (0x7FFFFF + sign(x))
|
|
f32->s24 {
|
|
flt c;
|
|
int s;
|
|
clip c x;
|
|
sig s x;
|
|
add s s 8388607;
|
|
mul (int)r c s;
|
|
}
|
|
|
|
# r = clip(x) * (0x7FFFFFFF + sign(x))
|
|
f32->s32 {
|
|
flt c;
|
|
int s;
|
|
clip c x;
|
|
sig s x;
|
|
add s s 2147483647;
|
|
mul (int)r c s;
|
|
}
|