Skip to content

Commit

Permalink
Implement MIC::StopSampling
Browse files Browse the repository at this point in the history
  • Loading branch information
wheremyfoodat committed Aug 14, 2023
1 parent b79df4b commit ae32bb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/services/mic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class MICService {
void setIirFilter(u32 messagePointer);
void setPower(u32 messagePointer);
void startSampling(u32 messagePointer);
void stopSampling(u32 messagePointer);
void theCaptainToadFunction(u32 messagePointer);

u8 gain = 0; // How loud our microphone input signal is
bool micEnabled = false;
bool shouldClamp = false;
bool isSampling = false;

public:
MICService(Memory& mem) : mem(mem) {}
Expand Down
12 changes: 12 additions & 0 deletions src/core/services/mic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace MICCommands {
enum : u32 {
MapSharedMem = 0x00010042,
StartSampling = 0x00030140,
StopSampling = 0x00050000,
SetGain = 0x00080040,
GetGain = 0x00090000,
SetPower = 0x000A0040,
Expand All @@ -17,6 +18,7 @@ namespace MICCommands {
void MICService::reset() {
micEnabled = false;
shouldClamp = false;
isSampling = false;
gain = 0;
}

Expand All @@ -30,6 +32,7 @@ void MICService::handleSyncRequest(u32 messagePointer) {
case MICCommands::SetIirFilter: setIirFilter(messagePointer); break;
case MICCommands::SetPower: setPower(messagePointer); break;
case MICCommands::StartSampling: startSampling(messagePointer); break;
case MICCommands::StopSampling: stopSampling(messagePointer); break;
case MICCommands::CaptainToadFunction: theCaptainToadFunction(messagePointer); break;
default: Helpers::panic("MIC service requested. Command: %08X\n", command);
}
Expand Down Expand Up @@ -88,10 +91,19 @@ void MICService::startSampling(u32 messagePointer) {
encoding, sampleRate, offset, dataSize, loop ? "yes" : "no"
);

isSampling = true;
mem.write32(messagePointer, IPC::responseHeader(0x3, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
}

void MICService::stopSampling(u32 messagePointer) {
log("MIC::StopSampling\n");
isSampling = false;

mem.write32(messagePointer, IPC::responseHeader(0x5, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
}

void MICService::setIirFilter(u32 messagePointer) {
const u32 size = mem.read32(messagePointer + 4);
const u32 pointer = mem.read32(messagePointer + 12);
Expand Down

0 comments on commit ae32bb8

Please sign in to comment.