summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xwiiplay2
-rw-r--r--wiispkr.c38
2 files changed, 31 insertions, 9 deletions
diff --git a/wiiplay b/wiiplay
index b3ee3aa..8d825c3 100755
--- a/wiiplay
+++ b/wiiplay
@@ -29,7 +29,7 @@ else
fi
-sox --norm /tmp/wiiplay.wav -b 8 /tmp/wiiplay.raw channels 1 rate 1500
+sox --norm /tmp/wiiplay.wav -b 8 /tmp/wiiplay.raw channels 1 rate 2000
rm /tmp/wiiplay.wav
diff --git a/wiispkr.c b/wiispkr.c
index ae783b6..7097cc0 100644
--- a/wiispkr.c
+++ b/wiispkr.c
@@ -4,11 +4,20 @@
* 0. You just DO WHAT THE FUCK YOU WANT TO
*
* Loosely based on libcwiimote/test/test2.c
+ *
+ *
+ * A note on sample rates:
+ * Right now we use 2kHz with 8bit signed pcm.
+ * The speaker eats up to 20 bytes of raw data at once, so this gives us
+ * 100 updates per second (one every 10 us).
+ * Higher rates like 3kHz don't work as well, looks like one report
+ * every 10us is about as fast as the bluetooth chipset / driver here gets.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -33,6 +42,10 @@ int main(int argc, char **argv)
{
wiimote_t wiimote = WIIMOTE_INIT;
int readbytes;
+ char report_err = 0;
+
+ wiimote_report_t report = WIIMOTE_REPORT_INIT;
+ report.channel = WIIMOTE_RID_SPK;
struct timeval tv;
uint32_t timeout = 0;
@@ -42,8 +55,8 @@ int main(int argc, char **argv)
uint8_t sample[20];
- uint8_t spk_8bit[] = { 0x00, 0x40, 0x40, 0x1f, 0x60, 0x00, 0x00 };
- uint8_t spk_4bit[] = { 0x00, 0x00, 0xd0, 0x07, 0x40, 0x00, 0x00 };
+ /* see http://wiibrew.org/wiki/Wiimote#Speaker_Configuration */
+ uint8_t spk_8bit[] = { 0x00, 0x40, 0x70, 0x17, 0x60, 0x00, 0x00 };
if (argc < 2) {
@@ -67,7 +80,7 @@ int main(int argc, char **argv)
wiimote_write_byte(&wiimote, 0x04a20009, 0x01);
wiimote_write_byte(&wiimote, 0x04a20001, 0x08);
- wiimote_write(&wiimote, 0x04a20001, spk_8bit, sizeof(spk_4bit));
+ wiimote_write(&wiimote, 0x04a20001, spk_8bit, sizeof(spk_8bit));
wiimote_write_byte(&wiimote, 0x04a20008, 0x01);
wiimote_send_byte(&wiimote, WIIMOTE_RID_SPK_MUTE, 0x00);
@@ -80,16 +93,25 @@ int main(int argc, char **argv)
t = (tv.tv_sec * 1000000 + tv.tv_usec) / 100;
if (t > timeout) {
- printf("\r\033[2Kplay second %f pos %d", (double)(t - start) / 10000, fpos);
+ printf("\r\033[2K%c play second %f pos %d",
+ (report_err ? '!' : ' '),
+ (double)(t - start) / 10000, fpos);
fflush(stdout);
- if ((readbytes = read(0, &sample, sizeof(sample))) == -1)
+ if ((readbytes = read(0, &sample, sizeof(sample))) < 1)
return 0;
fpos += readbytes;
- wiimote_speaker_play(&wiimote, sample, sizeof(sample));
- timeout = t + 130;
+
+ report.speaker.size = sizeof(sample);
+ memcpy(report.speaker.data, sample, report.speaker.size);
+ if (wiimote_report(&wiimote, &report, sizeof(report.speaker)) < 0)
+ report_err = 1;
+ else
+ report_err = 0;
+
+ timeout = t + 100;
}
else
- usleep(timeout - t);
+ usleep((timeout - t) * 10);
}
return 0;