diff --git a/cpp/wiiuse/src/speaker.c b/cpp/wiiuse/src/speaker.c index 4aa589f..68f932f 100644 --- a/cpp/wiiuse/src/speaker.c +++ b/cpp/wiiuse/src/speaker.c @@ -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); } diff --git a/cpp/wiiuse/src/wiiuse.h b/cpp/wiiuse/src/wiiuse.h index 469142d..b27637f 100644 --- a/cpp/wiiuse/src/wiiuse.h +++ b/cpp/wiiuse/src/wiiuse.h @@ -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); diff --git a/cpp/wiiusej/lib/wiiuse.lib b/cpp/wiiusej/lib/wiiuse.lib index c89e86e..4d4e2b0 100644 Binary files a/cpp/wiiusej/lib/wiiuse.lib and b/cpp/wiiusej/lib/wiiuse.lib differ diff --git a/cpp/wiiusej/src/wiiuse.h b/cpp/wiiusej/src/wiiuse.h index 469142d..b27637f 100644 --- a/cpp/wiiusej/src/wiiuse.h +++ b/cpp/wiiusej/src/wiiuse.h @@ -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); diff --git a/cpp/wiiusej/src/wiiusej_WiiUseApi.c b/cpp/wiiusej/src/wiiusej_WiiUseApi.c index e4a213a..3386e94 100644 --- a/cpp/wiiusej/src/wiiusej_WiiUseApi.c +++ b/cpp/wiiusej/src/wiiusej_WiiUseApi.c @@ -710,38 +710,28 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_deactivateSpeaker(JNIEnv *env, job } JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFormat(JNIEnv *env, jobject obj, jint id, jbyte format) { - struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id); - wiiuse_speaker_config(wm); - wiiuse_speaker_format(wm, format); + wiiuse_speaker_format(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), format); } -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate(JNIEnv *env, jobject obj, jint id, jint rate) { - struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id); - wiiuse_speaker_rate(wm, rate); - wiiuse_speaker_config(wm); +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate(JNIEnv *env, jobject obj, jint id, jbyte rate, jbyte freq) { + wiiuse_speaker_rate(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), rate, freq); } JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume(JNIEnv *env, jobject obj, jint id, jdouble vol) { - struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id); - wiiuse_speaker_volume(wm, vol); - wiiuse_speaker_config(wm); + wiiuse_speaker_volume(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), vol); } -JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig(JNIEnv *env, jobject obj, jint id, jbyte format, jint rate, jdouble vol) { - struct wiimote_t* wm = wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id); - wiiuse_speaker_format(wm, format); - wiiuse_speaker_rate(wm, rate); - wiiuse_speaker_volume(wm, vol); - wiiuse_speaker_config(wm); +JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig(JNIEnv *env, jobject obj, jint id) { + wiiuse_speaker_config(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id)); } JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_streamSpeakerData(JNIEnv *env, jobject obj, jint id, jbyteArray jbArray) { jbyte *jbData = (*env)->GetByteArrayElements(env, jbArray, JNI_FALSE); /* Todo: Check for data loss by using signed vs unsigned bytes */ int len = (int) (*env)->GetArrayLength(env, jbArray); - /*byte data[length]; + /*byte data[len]; int i = 0; - for (i = 0; i < length; ++i) { + for (i = 0; i < len; ++i) { data[i] = (byte) jbData[i]; }*/ wiiuse_speaker_data(wiiuse_get_by_id(wiimotes, nbMaxWiimotes, id), (byte*) jbData, len); diff --git a/cpp/wiiusej/src/wiiusej_WiiUseApi.h b/cpp/wiiusej/src/wiiusej_WiiUseApi.h index e003a5a..7d6e19b 100644 --- a/cpp/wiiusej/src/wiiusej_WiiUseApi.h +++ b/cpp/wiiusej/src/wiiusej_WiiUseApi.h @@ -333,7 +333,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerFormat * Signature: (II)V */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerRate - (JNIEnv *, jobject, jint, jint); + (JNIEnv *, jobject, jint, jbyte, jbyte); /* * Class: wiiusej_WiiUseApi @@ -349,7 +349,7 @@ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerVolume * Signature: (IBID)V */ JNIEXPORT void JNICALL Java_wiiusej_WiiUseApi_setSpeakerConfig - (JNIEnv *, jobject, jint, jbyte, jint, jdouble); + (JNIEnv *, jobject, jint); /* * Class: wiiusej_WiiUseApi