diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c
index c6b88736e8cf8f80d4e6ffc1bdd5649243415ca6..c805b63ad8f1ef4d9fe6bc5ab69b30a9ca9c8681 100644
--- a/src/xpdev/genwrap.c
+++ b/src/xpdev/genwrap.c
@@ -55,6 +55,11 @@
 		#include <sys/kbio.h>
 		#include <sys/kbd.h>
 	#endif
+	#if defined(__OpenBSD__) || defined(__NetBSD__)
+		#include <machine/spkr.h>
+	#elif defined(__FreeBSD__)
+		#include <machine/speaker.h>
+	#endif
 #endif	/* __unix__ */
 
 #include "genwrap.h"	/* Verify prototypes */
@@ -128,18 +133,31 @@ char* strrev(char* str)
     }
     return str;
 }
-#endif
 
 /****************************************************************************/
 /* Generate a tone at specified frequency for specified milliseconds		*/
 /* Thanks to Casey Martin for this code										*/
 /****************************************************************************/
-#if defined(__unix__)
 void DLLCALL unix_beep(int freq, int dur)
 {
 	static int console_fd=-1;
 
-#if !defined(__OpenBSD__) && !defined(__GNU__) && !defined(__NetBSD__) && !defined(__QNX__)
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+	int speaker_fd=-1;
+	tone_t tone;
+
+	speaker_fd = open("/dev/speaker", O_WRONLY|O_APPEND);
+	if(speaker_fd != -1)  {
+		tone.frequency=freq;
+		tone.duration=dur;
+		ioctl(speaker_fd,SPKRTONE,&tone);
+		SLEEP(dur);
+		close(speaker_fd);
+		return;
+	}
+#endif
+
+#if !defined(__GNU__) && !defined(__QNX__)
 	if(console_fd == -1) 
   		console_fd = open("/dev/console", O_NOCTTY);