void SoundData::clear() { if (_dataLeft) { #ifdef _3DS linearFree(_dataLeft); #else delete[] _dataLeft; #endif // _3DS _dataLeft = nullptr; } if (_dataRight) { #ifdef _3DS linearFree(_dataRight); #else delete[] _dataRight; #endif // _3DS _dataRight = nullptr; } _dataSizeLeft = 0; _dataSizeRight = 0; _channels = 0; _sampleRate = 0; _bitsPerSample = 0; }
void gpuVboIndices(u32 vbo, const void* data, u32 size) { VboData* vboData = (VboData*) vbo; if(vboData == NULL) { return; } if(data == NULL) { if(vboData->indices != NULL) { linearFree(vboData->indices); vboData->indices = NULL; vboData->indicesSize = 0; } return; } if(vboData->indices == NULL || vboData->indicesSize != size) { if(vboData->indices != NULL) { linearFree(vboData->indices); } vboData->indices = linearMemAlign(size, 0x80); } memcpy(vboData->indices, data, size); vboData->indicesSize = size; }
void freeRoom(room_s* r) { if(!r)return; removeRoomRectangles(r); if(r->vertexBuffer)linearFree(r->vertexBuffer); if(r->numIndices)linearFree(r->numIndices); if(r->indexBufferTextures)linearFree(r->indexBufferTextures); if(r->indexBuffers) { int i; for(i=0; i<r->numIndexBuffers; i++)linearFree(r->indexBuffers[i]); free(r->indexBuffers); } if(r->rectangleGrid) { int i; for(i=0;i<r->rectangleGridSize.x*r->rectangleGridSize.z;i++) { if(r->rectangleGrid[i].rectangles)free(r->rectangleGrid[i].rectangles); } free(r->rectangleGrid); } freeLightData(&r->lightingData); }
void Sprite::free() { linearFree(vertices); linearFree(pixels); C3D_TexDelete(&texture); pixels = 0; w = h = pitch = 0; actualWidth = actualHeight = 0; format = Graphics::PixelFormat(); }
void system_shutdown(void) { if(snd.enabled) { OPLL_delete(opll); OPLL_close(); #ifdef _3DS linearFree(snd.buffer[0]); linearFree(snd.buffer[1]); #endif } }
void closeMusic(Music* src){ closeStream = true; svcSignalEvent(updateStream); while (closeStream){} // Wait for thread exiting... svcCloseHandle(updateStream); // Purging everything purgeTable(src->blocks); ndspChnReset(src->ch); ndspChnWaveBufClear(src->ch); linearFree(src->audiobuf); if (src->audiobuf2 != NULL) linearFree(src->audiobuf2); free(src); }
void gfxCleanup() { if(scale2xBuffer != NULL) { linearFree(scale2xBuffer); scale2xBuffer = NULL; } if(screenBuffer != NULL) { linearFree(screenBuffer); screenBuffer = NULL; } if(borderInit) { C3D_TexDelete(&borderTexture); borderInit = false; } if(screenInit) { C3D_TexDelete(&screenTexture); screenInit = false; } if(shaderInitialized) { shaderProgramFree(&program); shaderInitialized = false; } if(dvlb != NULL) { DVLB_Free(dvlb); dvlb = NULL; } if(targetTop != NULL) { C3D_RenderTargetDelete(targetTop); targetTop = NULL; } if(targetBottom != NULL) { C3D_RenderTargetDelete(targetBottom); targetBottom = NULL; } if(c3dInitialized) { C3D_Fini(); c3dInitialized = false; } gfxExit(); }
void audio_stop(void) { csndExecCmds(true); CSND_SetPlayState(0x8, 0); memset(buffer, 0, size); GSPGPU_FlushDataCache(buffer, size); linearFree(buffer); }
void gpuFreeVbo(u32 vbo) { VboData* vboData = (VboData*) vbo; if(vboData == NULL) { return; } if(vboData->data != NULL) { linearFree(vboData->data); } if(vboData->indices != NULL) { linearFree(vboData->indices); } free(vboData); }
int32_t MV_Shutdown(void) { if (!MV_Installed) return MV_Ok; MV_KillAllVoices(); MV_Installed = FALSE; // Stop the sound playback engine MV_StopPlayback(); // Shutdown the sound card SoundDriver_Shutdown(); // Free any voices we allocated #ifdef _3DS linearFree(MV_Voices); #else ALIGNED_FREE_AND_NULL(MV_Voices); #endif LL_Reset((VoiceNode*) &VoiceList, next, prev); LL_Reset((VoiceNode*) &VoicePool, next, prev); MV_MaxVoices = 1; // Release the descriptor from our mix buffer for (int buffer = 0; buffer < MV_NUMBEROFBUFFERS; buffer++) MV_MixBuffer[ buffer ] = NULL; MV_SetErrorCode(MV_NotInstalled); return MV_Ok; }
void glShutdownBufferCTR(GLbufferCTR* buf) { if (buf == boundBuffer) boundBuffer = NULL; linearFree(buf->data); }
void glNamedTexImage2DCTR(GLuint texture, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data) { GLtextureCTR* tex; size_t textureDataSize; int i; tex = (GLtextureCTR*) texture; if (tex->data) linearFree(tex->data); textureDataSize = width * height * 4; tex->data = linearMemAlign(textureDataSize, 0x80); if (data) memcpy(tex->data, data, textureDataSize); tex->w = width; tex->h = height; for (i = 0; i < NUM_TEXUNITS; i++) if (texturingState.texUnits[i].boundTexture == tex) { dirtyState |= GL_TEXTURING_CTR; dirtyTexUnits |= (1 << i); } }
void play_file_from_filename(const std::string name) { currently_playing = std::string(name); if (audiobuf) linearFree(audiobuf); if (name.rfind(".flac") != std::string::npos) { if (!FLAC_decoder) { FLAC_decoder = FLAC__stream_decoder_new(); FLAC__stream_decoder_set_md5_checking(FLAC_decoder, true); } audiobuf_index = 0; decode_mode = AUDIO_MODE_FLAC; FLAC__StreamDecoderInitStatus init_status = FLAC__stream_decoder_init_file(FLAC_decoder, name.c_str(), FLAC_write_callback, FLAC_metadata_callback, FLAC_error_callback, NULL); if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { printf("ERROR: initializing decoder: %s\n", FLAC__StreamDecoderInitStatusString[init_status]); } FLAC__stream_decoder_process_until_end_of_metadata(FLAC_decoder); } else { decode_mode = AUDIO_MODE_VORBIS; v = stb_vorbis_open_filename(name.c_str(), &error, NULL); info = stb_vorbis_get_info(v); Samples = info.sample_rate; audiobuf_size = Samples * sizeof(s16) * 2; audiobuf = (s16*)linearAlloc(audiobuf_size); } paused = false; }
void setClockrate(u8 setting) { int j, i; u32* patchArea = linearAlloc(0x00100000); if(setting != 0) setting = 3; // grab waitLoop stub GSPGPU_FlushDataCache(NULL, (u8*)patchArea, 0x100); gspwn(patchArea, (u32*)(MENU_LOADEDROP_BUFADR-0x100), 0x100); svcSleepThread(20*1000*1000); // patch it for(i=0; i<0x100/4; i++) { if(patchArea[i] == 0x67666E63) // "cnfg" { patchArea[i+1] = (patchArea[i+1] & ~0xFF) | setting; break; } } // copy it back GSPGPU_FlushDataCache(NULL, (u8*)patchArea, 0x100); gspwn((u32*)(MENU_LOADEDROP_BUFADR-0x100), patchArea, 0x100); svcSleepThread(20*1000*1000); // ghetto dcache invalidation // don't judge me for(j=0; j<4; j++) for(i=0; i<0x00100000/0x4; i+=0x4) patchArea[i+j]^=0xDEADBABE; linearFree(patchArea); }
static int lua_unloadBMPV(lua_State *L){ int argc = lua_gettop(L); if (argc != 1) return luaL_error(L, "wrong number of arguments"); BMPV* src = (BMPV*)luaL_checkint(L, 1); if (src->samplerate != 0 && src->audio_size != 0 && !GW_MODE){ linearFree(src->audiobuf); if (src->audiotype == 2){ linearFree(src->audiobuf2); } } FSFILE_Close(src->sourceFile); svcCloseHandle(src->sourceFile); free(src->framebuf); free(src); return 0; }
void load_texture(C3D_Tex *tex, const u8 *img, const u32 img_size) { unsigned int width, height; u8* image; lodepng_decode32(&image, &width, &height, img, img_size); u8 *gpusrc = (u8 *) linearAlloc(width * height * 4); // lodepng outputs big endian rgba so we need to convert convert_endianess(gpusrc, image, width * height); // ensure data is in physical ram GSPGPU_FlushDataCache(gpusrc, width * height * 4); // Load the texture and bind it to the first texture unit C3D_TexInit(tex, width, height, GPU_RGBA8); // Convert image to 3DS tiled texture format C3D_SyncDisplayTransfer((u32*)gpusrc, GX_BUFFER_DIM(width, height), (u32*) tex->data, GX_BUFFER_DIM(width, height), TEXTURE_TRANSFER_FLAGS); C3D_TexSetFilter(tex, GPU_LINEAR, GPU_NEAREST); free(image); linearFree(gpusrc); }
static int lua_startBMPV(lua_State *L){ int argc = lua_gettop(L); if ((argc != 3) && (argc != 4)) return luaL_error(L, "wrong number of arguments"); BMPV* src = (BMPV*)luaL_checkint(L, 1); int loop = luaL_checkint(L, 2); int ch1 = luaL_checkint(L, 3); if (argc == 4){ int ch2 = luaL_checkint(L, 4); src->ch2 = ch2; } src->loop = loop; src->isPlaying = true; src->ch1 = ch1; src->currentFrame = 0; u32 bytesRead; if (src->samplerate != 0 && src->audio_size != 0 && !GW_MODE){ while(src->mem_size > MAX_RAM_ALLOCATION){ src->mem_size = src->mem_size / 2; } if (src->audiotype == 1){ FSFILE_Read(src->sourceFile, &bytesRead, 28, src->audiobuf, src->mem_size); GSPGPU_FlushDataCache(NULL, src->audiobuf, src->audio_size); My_CSND_playsound(ch1, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, src->samplerate, (u32*)src->audiobuf, (u32*)src->audiobuf, src->mem_size, 0xFFFF, 0xFFFF); }else{ u8* audiobuf = (u8*)linearAlloc(src->mem_size); FSFILE_Read(src->sourceFile, &bytesRead, 28, audiobuf, src->mem_size); src->audiobuf = (u8*)linearAlloc(src->mem_size/2); src->audiobuf2 = (u8*)linearAlloc(src->mem_size/2); u32 off=0; u32 i=0; u16 z; while (i < (src->mem_size)){ z=0; while (z < (src->bytepersample/2)){ src->audiobuf[off+z] = audiobuf[i+z]; src->audiobuf2[off+z] = audiobuf[i+z+(src->bytepersample/2)]; z++; } i=i+src->bytepersample; off=off+(src->bytepersample/2); } linearFree(audiobuf); GSPGPU_FlushDataCache(NULL, src->audiobuf, src->mem_size/2); GSPGPU_FlushDataCache(NULL, src->audiobuf2, src->mem_size/2); My_CSND_playsound(src->ch1, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, src->samplerate, (u32*)src->audiobuf, (u32*)src->audiobuf, src->mem_size/2, 0xFFFF, 0); My_CSND_playsound(src->ch2, CSND_LOOP_ENABLE, CSND_ENCODING_PCM16, src->samplerate, (u32*)src->audiobuf2, (u32*)src->audiobuf2, src->mem_size/2, 0, 0xFFFF); } src->tick = osGetTime(); CSND_setchannel_playbackstate(ch1, 1); if (src->audiotype == 2){ CSND_setchannel_playbackstate(src->ch2, 1); } CSND_sharedmemtype0_cmdupdatestate(0); src->moltiplier = 1; }else{ src->tick = osGetTime(); } return 0; }
static void sceneExit(void) { // Free the VBO linearFree(vbo_data); // Free the shader program shaderProgramFree(&program); DVLB_Free(vshader_dvlb); }
void gpuTextureData(u32 texture, const void* data, u32 inWidth, u32 inHeight, PixelFormat inFormat, u32 outWidth, u32 outHeight, PixelFormat outFormat, u32 params) { TextureData* textureData = (TextureData*) texture; if(textureData == NULL) { return; } u32 size = outWidth * outHeight; switch(outFormat) { case PIXEL_RGBA8: case PIXEL_ETC1: case PIXEL_ETC1A4: size *= 4; break; case PIXEL_RGB8: size *= 3; break; case PIXEL_RGBA5551: case PIXEL_RGB565: case PIXEL_RGBA4: case PIXEL_LA8: case PIXEL_HILO8: size *= 2; break; case PIXEL_L8: case PIXEL_A8: case PIXEL_LA4: case PIXEL_L4: break; } if(textureData->data == NULL || textureData->size != size) { if(textureData->data != NULL) { linearFree(textureData->data); } textureData->data = linearMemAlign(size, 0x80); for(u8 unit = 0; unit < TEX_UNIT_COUNT; unit++) { if(activeTextures[unit] == textureData) { dirtyState |= STATE_TEXTURES; dirtyTextures |= (1 << unit); } } } u32 flags = (u32) ((1 << 1) | (inFormat << 8) | (outFormat << 12)); if(outWidth < inWidth || outHeight < inHeight) { flags |= (1 << 2); } GX_SetDisplayTransfer(NULL, (u32*) data, (inHeight << 16) | inWidth, (u32*) textureData->data, (outHeight << 16) | outWidth, flags); gpuSafeWait(GSPEVENT_PPF); textureData->width = outWidth; textureData->height = outHeight; textureData->size = size; textureData->format = outFormat; textureData->params = params; }
Result DownloadFile_Internal(const char *url, void *out, bool bProgress, void (*write)(void* out, unsigned char* buffer, u32 readSize)) { httpcContext context; u32 fileSize = 0; u32 procSize = 0; Result ret = 0; Result dlret = HTTPC_RESULTCODE_DOWNLOADPENDING; u32 status; u32 bufSize = 0x100000; u32 readSize = 0; httpcOpenContext(&context, HTTPC_METHOD_GET, (char*)url, 1); ret = httpcBeginRequest(&context); if (ret != 0) goto _out; ret = httpcGetResponseStatusCode(&context, &status, 0); if (ret != 0) goto _out; if (status != 200) { ret = status; goto _out; } ret = httpcGetDownloadSizeState(&context, NULL, &fileSize); if (ret != 0) goto _out; { unsigned char *buffer = (unsigned char *)linearAlloc(bufSize); if (buffer == NULL) { printf("Error allocating download buffer\n"); ret = -1; goto _out; } while (dlret == (s32)HTTPC_RESULTCODE_DOWNLOADPENDING) { memset(buffer, 0, bufSize); dlret = httpcDownloadData(&context, buffer, bufSize, &readSize); write(out, buffer, readSize); procSize += readSize; if (bProgress) { PrintProgress(fileSize, procSize); } } linearFree(buffer); } _out: httpcCloseContext(&context); return ret; }
static int lua_free2(lua_State *L){ int argc = lua_gettop(L); #ifndef SKIP_ERROR_HANDLING if(argc != 1) return luaL_error(L, "wrong number of arguments."); #endif void* offset = (void*)luaL_checkinteger(L, 1); linearFree(offset); return 0; }
int sf2d_fini() { if (!sf2d_initialized) return 0; //aptUnhook(&apt_hook_cookie); gfxExit(); shaderProgramFree(&shader); DVLB_Free(dvlb); linearFree(pool_addr); linearFree(gpu_cmd); vramFree(gpu_fb_addr); vramFree(gpu_depth_fb_addr); sf2d_initialized = 0; return 1; }
static void deinit_video_filter(void) { rarch_softfilter_free(video_state.filter.filter); #ifdef _3DS linearFree(video_state.filter.buffer); #else free(video_state.filter.buffer); #endif memset(&video_state.filter, 0, sizeof(video_state.filter)); }
void retro_deinit(void) { #ifdef _3DS linearFree(vout_buf); #else free(vout_buf); #endif vout_buf = NULL; PicoExit(); }
void pm_3ds_sound_quit(void) { CSND_SetPlayState(0x8, 0);//Stop audio playback. csndExecCmds(0); if (stream) { linearFree(stream); } csndExit(); }
void C3D_TexDelete(C3D_Tex* tex) { if (!tex->data) return; if (addrIsVRAM(tex->data)) vramFree(tex->data); else linearFree(tex->data); tex->data = NULL; }
void sf2d_free_texture(sf2d_texture *texture) { if (texture) { if (texture->place == SF2D_PLACE_RAM) { linearFree(texture->data); } else if (texture->place == SF2D_PLACE_VRAM) { vramFree(texture->data); } free(texture); } }
void gpuFreeTexture(u32 texture) { TextureData* textureData = (TextureData*) texture; if(textureData == NULL) { return; } if(textureData->data != NULL) { linearFree(textureData->data); } free(textureData); }
void audio_load(const char *audio) { FILE *file = fopen(audio, "rb"); fseek(file, 0, SEEK_END); off_t size = ftell(file); fseek(file, 0, SEEK_SET); buffer = linearAlloc(size); off_t bytesRead = fread(buffer, 1, size, file); fclose(file); csndPlaySound(8, SOUND_FORMAT_16BIT | SOUND_REPEAT, 48000, 1, 0, buffer, buffer, size); linearFree(buffer); }
void gfxExit() { // Exit event handler gspExitEventHandler(); // Free framebuffers linearFree(gfxTopRightFramebuffers[1]); linearFree(gfxTopRightFramebuffers[0]); linearFree(gfxBottomFramebuffers[1]); linearFree(gfxBottomFramebuffers[0]); linearFree(gfxTopLeftFramebuffers[1]); linearFree(gfxTopLeftFramebuffers[0]); //unmap GSP shared mem svcUnmapMemoryBlock(gspSharedMemHandle, 0x10002000); GSPGPU_UnregisterInterruptRelayQueue(NULL); svcCloseHandle(gspSharedMemHandle); svcCloseHandle(gspEvent); GSPGPU_ReleaseRight(NULL); gspExit(); }