This commit is contained in:
plutoo 2014-11-26 01:33:03 +01:00
commit 49ab752427
6 changed files with 61 additions and 44 deletions

View File

@ -3,3 +3,5 @@ mic
Example for using the microphone with ctrulib. Hold down the A button to record, the app will then play the recorded audio once the A button is released. Roughly 32 seconds of audio can be recorded with the default audiobuf size in this app. Example for using the microphone with ctrulib. Hold down the A button to record, the app will then play the recorded audio once the A button is released. Roughly 32 seconds of audio can be recorded with the default audiobuf size in this app.
Do not use this example(and/or ctrulib MIC?), since MIC is broken currently.

View File

@ -11,13 +11,14 @@ int main()
u8 *audiobuf; u8 *audiobuf;
u32 audiobuf_size = 0x100000, audiobuf_pos = 0; u32 audiobuf_size = 0x100000, audiobuf_pos = 0;
u8 control=0x40; u8 control=0x40;
u32 audio_initialized = 0;
srvInit(); srvInit();
aptInit(); aptInit();
gfxInit(); gfxInit();
hidInit(NULL); hidInit(NULL);
CSND_initialize(NULL); if(CSND_initialize(NULL)==0)audio_initialized = 1;
sharedmem = (u32*)memalign(0x1000, sharedmem_size); sharedmem = (u32*)memalign(0x1000, sharedmem_size);
audiobuf = linearAlloc(audiobuf_size); audiobuf = linearAlloc(audiobuf_size);
@ -26,52 +27,63 @@ int main()
while(aptMainLoop()) while(aptMainLoop())
{ {
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
hidScanInput(); hidScanInput();
gspWaitForVBlank();
if(hidKeysDown() & KEY_A) u32 kDown = hidKeysDown();
if (kDown & KEY_START)
break; // break in order to return to hbmenu
if(audio_initialized)
{ {
audiobuf_pos = 0;
CSND_setchannel_playbackstate(0x8, 0);//Stop audio playback.
CSND_sharedmemtype0_cmdupdatestate(0);
MIC_SetRecording(1);
memset(framebuf, 0x20, 0x46500);
}
if((hidKeysHeld() & KEY_A) && audiobuf_pos < audiobuf_size)
{
audiobuf_pos+= MIC_ReadAudioData(&audiobuf[audiobuf_pos], audiobuf_size-audiobuf_pos, 1);
if(audiobuf_pos > audiobuf_size)audiobuf_pos = audiobuf_size;
memset(framebuf, 0x60, 0x46500);
}
if(hidKeysUp() & KEY_A)
{
MIC_SetRecording(0);
GSPGPU_FlushDataCache(NULL, audiobuf, audiobuf_pos);
CSND_playsound(0x8, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, 16000, (u32*)audiobuf, NULL, audiobuf_pos, 2, 0);
memset(framebuf, 0xe0, 0x46500);
gfxFlushBuffers();
gfxSwapBuffers();
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
memset(framebuf, 0xe0, 0x46500);
if(kDown & KEY_A)
{
audiobuf_pos = 0;
CSND_setchannel_playbackstate(0x8, 0);//Stop audio playback.
CSND_sharedmemtype0_cmdupdatestate(0);
MIC_SetRecording(1);
memset(framebuf, 0x20, 0x46500);
}
if((hidKeysHeld() & KEY_A) && audiobuf_pos < audiobuf_size)
{
audiobuf_pos+= MIC_ReadAudioData(&audiobuf[audiobuf_pos], audiobuf_size-audiobuf_pos, 1);
if(audiobuf_pos > audiobuf_size)audiobuf_pos = audiobuf_size;
memset(framebuf, 0x60, 0x46500);
}
if(hidKeysUp() & KEY_A)
{
MIC_SetRecording(0);
GSPGPU_FlushDataCache(NULL, audiobuf, audiobuf_pos);
CSND_playsound(0x8, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, 16000, (u32*)audiobuf, NULL, audiobuf_pos, 2, 0);
memset(framebuf, 0xe0, 0x46500);
gfxFlushBuffers();
gfxSwapBuffers();
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
memset(framebuf, 0xe0, 0x46500);
}
} }
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gspWaitForVBlank();
} }
MIC_Shutdown(); MIC_Shutdown();
CSND_shutdown(); if(audio_initialized)CSND_shutdown();
free(sharedmem);
linearFree(audiobuf);
hidExit(); hidExit();
gfxExit(); gfxExit();

View File

@ -7,12 +7,12 @@ Result httpcInit()
Result ret=0; Result ret=0;
if(__httpc_servhandle)return 0; if(__httpc_servhandle)return 0;
if((ret=srvGetServiceHandle(&__httpc_servhandle, "http:C")))*((u32*)0x500) = ret;//return ret; if((ret=srvGetServiceHandle(&__httpc_servhandle, "http:C")))return ret;
//*((u32*)0x600) = __httpc_servhandle; //*((u32*)0x600) = __httpc_servhandle;
ret = HTTPC_Initialize(__httpc_servhandle); ret = HTTPC_Initialize(__httpc_servhandle);
if(ret!=0)*((u32*)0x400) = ret;//return ret; if(ret!=0)return ret;
return 0; return 0;
} }
@ -29,18 +29,18 @@ Result httpcOpenContext(httpcContext *context, char* url, u32 use_defaultproxy)
Result ret=0; Result ret=0;
ret = HTTPC_CreateContext(__httpc_servhandle, url, &context->httphandle); ret = HTTPC_CreateContext(__httpc_servhandle, url, &context->httphandle);
if(ret!=0)*((u32*)0x100) = ret;//return ret; if(ret!=0)return ret;
ret = srvGetServiceHandle(&context->servhandle, "http:C"); ret = srvGetServiceHandle(&context->servhandle, "http:C");
if(ret!=0)*((u32*)0x104) = ret;//return ret; if(ret!=0)return ret;
ret = HTTPC_InitializeConnectionSession(context->servhandle, context->httphandle); ret = HTTPC_InitializeConnectionSession(context->servhandle, context->httphandle);
if(ret!=0)*((u32*)0x108) = ret;//return ret; if(ret!=0)return ret;
if(use_defaultproxy==0)return 0; if(use_defaultproxy==0)return 0;
ret = HTTPC_SetProxyDefault(context->servhandle, context->httphandle); ret = HTTPC_SetProxyDefault(context->servhandle, context->httphandle);
if(ret!=0)*((u32*)0x10c) = ret;//return ret; if(ret!=0)return ret;
return 0; return 0;
} }

View File

@ -207,7 +207,7 @@ Result MIC_GetEventHandle(Handle *handle)
if((ret = svcSendSyncRequest(MIC_handle))!=0)return ret; if((ret = svcSendSyncRequest(MIC_handle))!=0)return ret;
if(handle)*handle = cmdbuf[2]; if(handle)*handle = cmdbuf[3];
return (Result)cmdbuf[1]; return (Result)cmdbuf[1];
} }

View File

@ -24,6 +24,7 @@ int ioctl(int fd, int request, ...)
flags = fcntl(fd, F_GETFL, 0); flags = fcntl(fd, F_GETFL, 0);
if(flags == -1) { if(flags == -1) {
errno = SOC_GetErrno(); errno = SOC_GetErrno();
va_end(ap);
return -1; return -1;
} }

View File

@ -187,11 +187,13 @@ svcWaitSynchronization:
.type svcWaitSynchronizationN, %function .type svcWaitSynchronizationN, %function
svcWaitSynchronizationN: svcWaitSynchronizationN:
str r5, [sp, #-4]! str r5, [sp, #-4]!
str r4, [sp, #-4]!
mov r5, r0 mov r5, r0
ldr r0, [sp, #0x4] ldr r0, [sp, #0x8]
ldr r4, [sp, #0x4+0x4] ldr r4, [sp, #0x8+0x4]
svc 0x25 svc 0x25
str r1, [r5] str r1, [r5]
ldr r4, [sp], #4
ldr r5, [sp], #4 ldr r5, [sp], #4
bx lr bx lr