This commit is contained in:
2011-09-18 11:12:10 +00:00
parent bafe96b16b
commit d8c9bbfef7
6 changed files with 37 additions and 27 deletions

View File

@@ -4,6 +4,12 @@
#include "wiiuse.h"
#include "speaker.h"
void wiiuse_speaker_init(struct wiimote_t* wm) {
wiiuse_speaker_format(wm, 0x00);
wiiuse_speaker_rate(wm, 0x00, 0x00);
wiiuse_speaker_volume(wm, 0x00);
}
void wiiuse_speaker_enable(struct wiimote_t* wm) {
byte buf = WIIMOTE_GET_RUMBLE(wm) | WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED;
wiiuse_send(wm, WM_CMD_SPEAKER_ENABLE, &buf, 1);
@@ -27,6 +33,7 @@ void wiiuse_speaker_unmute(struct wiimote_t* wm) {
void wiiuse_speaker_activate(struct wiimote_t* wm) {
wiiuse_speaker_enable(wm);
wiiuse_speaker_mute(wm);
#if 0
byte buf = 0x01;
wiiuse_write_data(wm, WM_REG_SPEAKER + 8, &buf, 1);
buf = 0x08;
@@ -34,6 +41,10 @@ void wiiuse_speaker_activate(struct wiimote_t* wm) {
wiiuse_speaker_config(wm);
buf = 0x01;
wiiuse_write_data(wm, WM_REG_SPEAKER + 7, &buf, 1);
#else
byte buf[9] = {0x00, wm->speaker.format, wm->speaker.rate, wm->speaker.freq, wm->speaker.vol, 0x00, 0x00, 0x01, 0x01};
wiiuse_write_data(wm, WM_REG_SPEAKER, buf, 9);
#endif
wiiuse_speaker_unmute(wm);
}
@@ -46,9 +57,10 @@ void wiiuse_speaker_format(struct wiimote_t* wm, byte format) {
wm->speaker.format = format;
}
void wiiuse_speaker_rate(struct wiimote_t* wm, double rate) {
void wiiuse_speaker_rate(struct wiimote_t* wm, byte rate, byte freq) {
// Check: pcm_sample_rate = 12000000 / rate_value adpcm_sample_rate = 6000000 / rate_value
wm->speaker.rate = 48000 / rate;
wm->speaker.rate = rate;
//wm->speaker.freq = freq;
}
void wiiuse_speaker_volume(struct wiimote_t* wm, double vol) {
@@ -56,13 +68,19 @@ void wiiuse_speaker_volume(struct wiimote_t* wm, double vol) {
}
void wiiuse_speaker_config(struct wiimote_t* wm) {
byte cfg[7] = {0x00, wm->speaker.format, 15, 25, wm->speaker.vol, 0x00, 0x00};
WIIUSE_DEBUG("speaker_config()");
WIIUSE_DEBUG("format: %2x", wm->speaker.format);
WIIUSE_DEBUG("rate: %2x", wm->speaker.rate);
WIIUSE_DEBUG("freq: %2x", wm->speaker.freq);
WIIUSE_DEBUG("vol: %2x", wm->speaker.vol);
byte cfg[7] = {0x00, wm->speaker.format, wm->speaker.rate, wm->speaker.freq, wm->speaker.vol, 0x00, 0x00};
wiiuse_write_data(wm, WM_REG_SPEAKER, cfg, 7);
}
void wiiuse_speaker_data(struct wiimote_t* wm, byte* data, int len) {
byte buf[21] = {0x00};
buf[0] = len << 3;
//WIIUSE_DEBUG("speaker_data(): length = %d", len);
memcpy(buf + 1, data, len);
wiiuse_send(wm, WM_CMD_STREAM_DATA, buf, 21);
}

View File

@@ -376,8 +376,9 @@ typedef struct ir_t {
*/
typedef struct speaker_t {
byte format;
byte vol;
byte rate;
byte freq;
byte vol;
} speaker_t;
@@ -663,7 +664,7 @@ WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_format(struct wiimote_t* wm, byte format);
WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, double vol);
WIIUSE_EXPORT extern void wiiuse_speaker_rate(struct wiimote_t* wm, double freq);
WIIUSE_EXPORT extern void wiiuse_speaker_rate(struct wiimote_t* wm, byte rate, byte freq);
WIIUSE_EXPORT extern void wiiuse_speaker_config(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data, int len);