#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int main()
{
bool initialized = true;
u32 micbuf_size = 0x30000;
u8* micbuf = memalign(0x1000, micbuf_size);
printf("Initializing CSND...\n");
{
initialized = false;
printf("Could not initialize CSND.\n");
} else printf("CSND initialized.\n");
printf("Initializing MIC...\n");
{
initialized = false;
printf("Could not initialize MIC.\n");
} else printf("MIC initialized.\n");
u32 audiobuf_size = 0x100000;
if(initialized) printf("Hold A to record, release to play.\n");
printf("Press START to exit.\n");
{
break;
if(initialized)
{
{
audiobuf_pos = 0;
micbuf_pos = 0;
printf("Stopping audio playback...\n");
printf("Starting sampling...\n");
else printf("Failed to start sampling.\n");
}
{
u32 micbuf_readpos = micbuf_pos;
while(audiobuf_pos < audiobuf_size && micbuf_readpos != micbuf_pos)
{
audiobuf[audiobuf_pos] = micbuf[micbuf_readpos];
audiobuf_pos++;
micbuf_readpos = (micbuf_readpos + 1) % micbuf_datasize;
}
}
{
printf("Stoping sampling...\n");
printf("Starting audio playback...\n");
else printf("Failed to start playback.\n");
}
}
}
free(micbuf);
return 0;
}
bool aptMainLoop(void)
Main function which handles sleep mode and HOME/power buttons - call this at the beginning of every f...
PrintConsole * consoleInit(gfxScreen_t screen, PrintConsole *console)
Initialise the console.
Result CSND_UpdateInfo(bool waitDone)
Updates CSND information.
Result csndInit(void)
Initializes CSND.
Result csndPlaySound(int chn, u32 flags, u32 sampleRate, float vol, float pan, void *data0, void *data1, u32 size)
Plays a sound.
void CSND_SetPlayState(u32 channel, u32 value)
Sets a channel's play state.
@ SOUND_FORMAT_16BIT
PCM16.
Definition: csnd.h:72
@ SOUND_ONE_SHOT
Play the sound once.
Definition: csnd.h:70
void csndExit(void)
Exits CSND.
void gfxSwapBuffers(void)
Updates the configuration of both screens.
void gfxInitDefault(void)
Initializes the LCD framebuffers with default parameters This is equivalent to calling:
@ GFX_BOTTOM
Bottom screen.
Definition: gfx.h:27
void gfxExit(void)
Deinitializes and frees the LCD framebuffers.
void gfxFlushBuffers(void)
Flushes the data cache for the current framebuffers.
Result GSPGPU_FlushDataCache(const void *adr, u32 size)
Flushes memory from the data cache.
#define gspWaitForVBlank()
Waits for VBlank.
Definition: gspgpu.h:151
@ KEY_START
Start.
Definition: hid.h:15
@ KEY_A
A.
Definition: hid.h:12
u32 hidKeysHeld(void)
Returns a bitmask of held buttons.
u32 hidKeysDown(void)
Returns a bitmask of newly pressed buttons, this frame.
void hidScanInput(void)
Scans HID for input data.
u32 hidKeysUp(void)
Returns a bitmask of newly released buttons, this frame.
void * linearAlloc(size_t size)
Allocates a 0x80-byte aligned buffer.
void linearFree(void *mem)
Frees a buffer.
Result micInit(u8 *buffer, u32 bufferSize)
Initializes MIC.
u32 micGetSampleDataSize(void)
Gets the size of the sample data area within the shared memory buffer.
@ MICU_ENCODING_PCM16_SIGNED
Signed 16-bit PCM.
Definition: mic.h:13
void micExit(void)
Exits MIC.
Result MICU_StartSampling(MICU_Encoding encoding, MICU_SampleRate sampleRate, u32 offset, u32 size, bool loop)
Begins sampling microphone input.
Result MICU_StopSampling(void)
Stops sampling microphone input.
u32 micGetLastSampleOffset(void)
Gets the offset within the shared memory buffer of the last sample written.
@ MICU_SAMPLE_RATE_16360
16364.479 Hz
Definition: mic.h:20
#define R_FAILED(res)
Checks whether a result code indicates failure.
Definition: result.h:11
#define R_SUCCEEDED(res)
Checks whether a result code indicates success.
Definition: result.h:9
uint8_t u8
would be nice if newlib had this already
Definition: types.h:21
uint32_t u32
32-bit unsigned integer
Definition: types.h:23