Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first draft of microphone support #181

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ SOURCES_CXX := $(MELON_DIR)/NDS.cpp \
$(MELON_DIR)/Wifi.cpp \
$(MELON_DIR)/WifiAP.cpp \
$(MELON_DIR)/frontend/Util_ROM.cpp \
$(MELON_DIR)/frontend/Util_Audio.cpp \
$(CORE_DIR)/config.cpp \
$(CORE_DIR)/input.cpp \
$(CORE_DIR)/libretro.cpp \
Expand Down
4 changes: 2 additions & 2 deletions src/NDSCart_SRAMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void DeInit()
}
#endif

if (SecondaryBuffer) delete SecondaryBuffer;
if (SecondaryBuffer) delete[] SecondaryBuffer;
SecondaryBuffer = NULL;

Platform::Mutex_Free(SecondaryBufferLock);
Expand All @@ -88,7 +88,7 @@ void Setup(const char* path, u8* buffer, u32 length)
Buffer = buffer;
Length = length;

if(SecondaryBuffer) delete SecondaryBuffer; // Delete secondary buffer, there might be previous state.
if(SecondaryBuffer) delete[] SecondaryBuffer; // Delete secondary buffer, there might be previous state.

SecondaryBuffer = new u8[length];
SecondaryBufferLength = length;
Expand Down
15 changes: 15 additions & 0 deletions src/libretro/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,24 @@ void update_input(InputState *state)
state->lid_closed = lid_closed_btn;
}

state->previous_holding_noise_btn = state->holding_noise_btn;
state->holding_noise_btn = !!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2);
state->swap_screens_btn = !!input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2);

if ( micNoiseType == MicInput && // If the player wants to use their real mic...
noise_button_required && // ...and they don't always want it hot...
(state->holding_noise_btn != state->previous_holding_noise_btn) && // ...and they just pressed or released the button...
micHandle != NULL && micInterface.interface_version > 0 // ...and the mic is valid...
)
{
bool stateSet = micInterface.set_mic_state(micHandle, state->holding_noise_btn);
// ...then set the state of the mic to the active staste of the noise button

if (!stateSet)
log_cb(RETRO_LOG_ERROR, "[melonDS] Error setting state of microphone to %s\n",
state->holding_noise_btn ? "enabled" : "disabled");
}

if(current_screen_layout != ScreenLayout::TopOnly)
{
switch(state->current_touch_mode)
Expand Down
13 changes: 13 additions & 0 deletions src/libretro/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _INPUT_H

#include "types.h"
#include <libretro.h>

enum TouchMode
{
Expand All @@ -11,12 +12,20 @@ enum TouchMode
Joystick,
};

enum MicInputMode
{
BlowNoise,
WhiteNoise,
MicInput,
};

struct InputState
{
bool touching;
int touch_x, touch_y;
TouchMode current_touch_mode;

bool previous_holding_noise_btn = false;
bool holding_noise_btn = false;
bool swap_screens_btn = false;
bool lid_closed = false;
Expand All @@ -27,6 +36,10 @@ extern InputState input_state;
bool cursor_enabled(InputState *state);

extern bool libretro_supports_bitmasks;
extern bool noise_button_required;
extern retro_microphone_interface micInterface;
extern retro_microphone_t *micHandle;
extern MicInputMode micNoiseType;

void update_input(InputState *state);

Expand Down
Loading