+//
+// Convert a double to a DSP56001 style fixed point float.
+// Seems to be 23 bits of float value with 1 bit (MSB) for the sign.
+//
+uint32_t DoubleToDSPFloat(double d)
+{
+ if (d >= 1)
+ {
+ warn("DSP value clamped to +1.");
+ return 0x7FFFFF;
+ }
+ else if (d <= -1)
+ {
+ warn("DSP value clamped to -1.");
+ return 0x800000;
+ }
+
+ // The casts are here because some compilers do weird shit. See bug #149.
+ return (uint32_t)((int32_t)trunc(round(ldexp(d, 23))));
+}
+
+