EXPORT_C_(s32) SPU2init() { #define MAKESURE(a,b) \ /*fprintf(stderr,"%08p: %08p == %08p\n",&(regtable[a>>1]),regtable[a>>1],U16P(b));*/ \ assert(regtable[(a)>>1]==U16P(b)) MAKESURE(0x800,zero); s32 c=0,v=0; ReadSettings(); #ifdef SPU2_LOG if(AccessLog()) { spu2Log = _wfopen( AccessLogFileName, _T("w") ); setvbuf(spu2Log, NULL, _IONBF, 0); FileLog("SPU2init\n"); } #endif srand((unsigned)time(NULL)); disableFreezes=false; if (spu2init) { ConLog( " * SPU2: Already initialized - Ignoring SPU2init signal." ); return 0; } spu2init=true; spu2regs = (short*)malloc(0x010000); _spu2mem = (short*)malloc(0x200000); // adpcm decoder cache: // the cache data size is determined by taking the number of adpcm blocks // (2MB / 16) and multiplying it by the decoded block size (28 samples). // Thus: pcm_cache_data = 7,340,032 bytes (ouch!) // Expanded: 16 bytes expands to 56 bytes [3.5:1 ratio] // Resulting in 2MB * 3.5. pcm_cache_data = (PcmCacheEntry*)calloc( pcm_BlockCount, sizeof(PcmCacheEntry) ); if( (spu2regs == NULL) || (_spu2mem == NULL) || (pcm_cache_data == NULL) ) { SysMessage("SPU2: Error allocating Memory\n"); return -1; } for(int mem=0;mem<0x800;mem++) { u16 *ptr=regtable[mem>>1]; if(!ptr) { regtable[mem>>1] = &(spu2Ru16(mem)); } }
EXPORT_C_(s32) SPU2init() { assert( regtable[0x400] == NULL ); if (IsInitialized) { printf( " * SPU2-X: Already initialized - Ignoring SPU2init signal." ); return 0; } IsInitialized = true; ReadSettings(); #ifdef SPU2_LOG if(AccessLog()) { spu2Log = OpenLog( AccessLogFileName ); setvbuf(spu2Log, NULL, _IONBF, 0); FileLog("SPU2init\n"); } #endif srand((unsigned)time(NULL)); spu2regs = (s16*)malloc(0x010000); _spu2mem = (s16*)malloc(0x200000); // adpcm decoder cache: // the cache data size is determined by taking the number of adpcm blocks // (2MB / 16) and multiplying it by the decoded block size (28 samples). // Thus: pcm_cache_data = 7,340,032 bytes (ouch!) // Expanded: 16 bytes expands to 56 bytes [3.5:1 ratio] // Resulting in 2MB * 3.5. pcm_cache_data = (PcmCacheEntry*)calloc( pcm_BlockCount, sizeof(PcmCacheEntry) ); if( (spu2regs == NULL) || (_spu2mem == NULL) || (pcm_cache_data == NULL) ) { SysMessage("SPU2-X: Error allocating Memory\n"); return -1; } // Patch up a copy of regtable that directly maps "NULLs" to SPU2 memory. memcpy(regtable, regtable_original, sizeof(regtable)); for(uint mem=0;mem<0x800;mem++) { u16 *ptr = regtable[mem>>1]; if(!ptr) { regtable[mem>>1] = &(spu2Ru16(mem)); } }