--- a/mpd2src/openaudio.cpp
+++ b/mpd2src/openaudio.cpp
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <byteswap.h>
 
 #include <iostream>
 #include <vector>
@@ -114,7 +115,11 @@
 {
     //LOGDEB("swapSamples: bps " << bytesPerSamp << " count " << scount << endl);
     if (bytesPerSamp == 2) {
-        swab(data, data, scount * 2);
+        // Swab would need non-overlapping buffers.
+        unsigned short *sp = (unsigned short *)data;
+        for (int i = 0; i < scount; i++) {
+            sp[i] = bswap_16(sp[i]);
+        }
     } else {
         unsigned char sample[4];
         // Byte index in data buffer