Пример #1
0
void ds_TermAudio()
{
	buffer->Stop();
	soundthread_running=false;
	SetEvent(buffer_events[0]);
	sound_th.WaitToEnd(INFINITE);

	for (u32 i=0;i<sound_buffer_count;i++)
		verify(CloseHandle(buffer_events[i]));

	buffer_notify->Release();
	buffer->Release();
	dsound->Release();
}
Пример #2
0
bool rend_init()
{

#if NO_REND
	renderer = rend_norend();
#else

#if HOST_OS == OS_WINDOWS
	renderer = settings.pvr.rend == 0 ? rend_GLES2() : rend_D3D11();
#else
	renderer = rend_GLES2();
#endif

#endif

#if !defined(_ANDROID)
	rthd.Start();
#endif

#if SET_AFNT
	cpu_set_t mask;



	/* CPU_ZERO initializes all the bits in the mask to zero. */

	CPU_ZERO( &mask );



	/* CPU_SET sets only the bit corresponding to cpu. */

	CPU_SET( 0, &mask );



	/* sched_setaffinity returns 0 in success */

	if( sched_setaffinity( 0, sizeof(mask), &mask ) == -1 )

	{

		printf("WARNING: Could not set CPU Affinity, continuing...\n");

	}
#endif

	return true;
}
Пример #3
0
int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShowCmd)
{
	ReserveBottomMemory();

	tick_thd.Start();

	int argc=0;
	wchar* cmd_line=GetCommandLineA();
	wchar** argv=CommandLineToArgvA(cmd_line,&argc);
	if(strstr(cmd_line,"NoConsole")==0)
	{
		if (AllocConsole())
		{
			freopen("CON","w",stdout);
			freopen("CON","w",stderr);
			freopen("CON","r",stdin);
		}
		SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
	}

	SetupPath();

	//SetUnhandledExceptionFilter(&ExeptionHandler);
	__try
	{
		int dc_init(int argc,wchar* argv[]);
		void dc_run();
		void dc_term();
		dc_init(argc,argv);

		#ifdef _WIN64
				setup_seh();
		#endif

		dc_run();
		dc_term();
	}
	__except( ExeptionHandler(GetExceptionInformation()) )
	{
		printf("Unhandled exception - Emulation thread halted...\n");
	}
	SetUnhandledExceptionFilter(0);

	return 0;
}
Пример #4
0
void ds_InitAudio()
{
	if (settings.BufferSize<2048)
	{
		StreamV2=true;
	}
	verifyc(DirectSoundCreate8(NULL,&dsound,NULL));

	verifyc(dsound->SetCooperativeLevel((HWND)eminf.GetRenderTarget(),DSSCL_PRIORITY));
	IDirectSoundBuffer* buffer_;

	WAVEFORMATEX wfx; 
	DSBUFFERDESC desc; 

	// Set up WAV format structure. 

	memset(&wfx, 0, sizeof(WAVEFORMATEX)); 
	wfx.wFormatTag = WAVE_FORMAT_PCM; 
	wfx.nChannels = 2; 
	wfx.nSamplesPerSec = 44100; 
	wfx.nBlockAlign = 4; 
	wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; 
	wfx.wBitsPerSample = 16; 

	// Set up DSBUFFERDESC structure. 

	memset(&desc, 0, sizeof(DSBUFFERDESC)); 
	desc.dwSize = sizeof(DSBUFFERDESC); 
	desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY;// _CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY; 
	
	if (!StreamV2)
		desc.dwBufferBytes = settings.BufferSize*(2)* wfx.nBlockAlign; 
	else
		desc.dwBufferBytes = V2_BUFFERSZ* wfx.nBlockAlign;	//fixed at 8k samples :)

	desc.lpwfxFormat = &wfx; 

	wait_buffer_size=settings.BufferSize*wfx.nBlockAlign;

	if (settings.HW_mixing==0)
	{
		desc.dwFlags |=DSBCAPS_LOCSOFTWARE;
	}
	else if (settings.HW_mixing==1)
	{
		desc.dwFlags |=DSBCAPS_LOCHARDWARE;
	}
	else if (settings.HW_mixing==2)
	{
		//auto
	}
	else
	{
		die("settings.HW_mixing: Invalid value");
	}

	if (settings.GlobalFocus)
		desc.dwFlags|=DSBCAPS_GLOBALFOCUS;

	verifyc(dsound->CreateSoundBuffer(&desc,&buffer_,0));
	verifyc(buffer_->QueryInterface(IID_IDirectSoundBuffer8,(void**)&buffer));
	buffer_->Release();

	verifyc(buffer->QueryInterface(IID_IDirectSoundNotify8,(void**)&buffer_notify));

	

	DWORD chunk_count;

	if (StreamV2)
	{
		chunk_count=V2_BUFFERSZ/settings.BufferSize;
		printf("DSOUND V2 : Using %d chunks of %d size\n",chunk_count,wait_buffer_size);
	}
	else
	{
		chunk_count=2;
		printf("DSOUND V1 : Using 2 chunks of %d size\n",wait_buffer_size);
	}

	sound_buffer_count=chunk_count;

	for (u32 bei=0;bei<chunk_count;bei++)
	{
		buffer_events[bei]=not[bei].hEventNotify=CreateEvent(NULL,FALSE,FALSE,NULL);

		not[bei].dwOffset=bei*wait_buffer_size;
		WritePositions[(bei+chunk_count-1)%chunk_count]=not[bei].dwOffset;
	}

	buffer_notify->SetNotificationPositions(chunk_count,not);

	//Clear the buffer with silence
	LPVOID p1=0,p2=0;
	DWORD s1=0,s2=0;

	verifyc(buffer->Lock(0,desc.dwBufferBytes,&p1,&s1,&p2,&s2,0));
	verify(p2==0);
	memset(p1,0,s1);
	verifyc(buffer->Unlock(p1,s1,p2,s2));

	//Start the thread
	soundthread_running=true;
	verify(SetThreadPriority((HANDLE)sound_th.hThread,THREAD_PRIORITY_TIME_CRITICAL));
	sound_th.Start();
	//Make sure its run before the buffer releases the event
	Sleep(0);
	//Play the buffer !
	verifyc(buffer->Play(0,0,DSBPLAY_LOOPING));
	
}
Пример #5
0
int dc_init(int argc,wchar* argv[])
{
	setbuf(stdin,0);
	setbuf(stdout,0);
	setbuf(stderr,0);
	if (!_vmem_reserve())
	{
		printf("Failed to alloc mem\n");
		return -1;
	}

#if !defined(TARGET_NO_WEBUI)
	webui_thd.Start();
#endif

	if(ParseCommandLine(argc,argv))
	{
		return 69;
	}
	if(!cfgOpen())
	{
		msgboxf("Unable to open config file",MBX_ICONERROR);
		return -4;
	}
	LoadSettings();
#ifndef _ANDROID
	os_CreateWindow();
#endif

	int rv= 0;

#if HOST_OS != OS_DARWIN
    #define DATA_PATH "/data/"
#else
    #define DATA_PATH "/"
#endif
    
	if (settings.bios.UseReios || !LoadRomFiles(GetPath(DATA_PATH)))
	{
		if (!LoadHle(GetPath(DATA_PATH)))
			return -3;
		else
			printf("Did not load bios, using reios\n");
	}

#if FEAT_SHREC != DYNAREC_NONE
	if(settings.dynarec.Enable)
	{
		Get_Sh4Recompiler(&sh4_cpu);
		printf("Using Recompiler\n");
	}
	else
#endif
	{
		Get_Sh4Interpreter(&sh4_cpu);
		printf("Using Interpreter\n");
	}
	
  InitAudio();

	sh4_cpu.Init();
	mem_Init();

	plugins_Init();
	
	mem_map_default();

#ifndef _ANDROID
	mcfg_CreateDevices();
#else
    mcfg_CreateDevices();
#endif

	plugins_Reset(false);
	mem_Reset(false);
	

	sh4_cpu.Reset(false);
	
	return rv;
}
Пример #6
0
void os_InitAudio()
{

    if (cfgLoadInt("audio","disable",0))
        return;

    cfgSaveInt("audio","disable",0);

    long loops;
    int size;

    snd_pcm_hw_params_t *params;
    unsigned int val;
    int dir;
    snd_pcm_uframes_t frames;

    /* Open PCM device for playback. */
    int rc = snd_pcm_open(&handle, "default",
                          SND_PCM_STREAM_PLAYBACK, 0);

    if (rc<0)
        rc = snd_pcm_open(&handle, "plughw:0,0,0",
                          SND_PCM_STREAM_PLAYBACK, 0);

    if (rc<0)
        rc = snd_pcm_open(&handle, "plughw:0,0",
                          SND_PCM_STREAM_PLAYBACK, 0);

    if (rc < 0) {
        fprintf(stderr,
                "unable to open pcm device: %s\n",
                snd_strerror(rc));
        return;
    }

    /* Allocate a hardware parameters object. */

    snd_pcm_hw_params_alloca(&params);
    /* Fill it in with default values. */
    rc=snd_pcm_hw_params_any(handle, params);
    if (rc < 0) {
        fprintf(stderr,
                "Error:snd_pcm_hw_params_any %s\n",
                snd_strerror(rc));
        return;
    }
    /* Set the desired hardware parameters. */

    /* Interleaved mode */
    rc=snd_pcm_hw_params_set_access(handle, params,
                                    SND_PCM_ACCESS_RW_INTERLEAVED);
    if (rc < 0) {
        fprintf(stderr,
                "Error:snd_pcm_hw_params_set_access %s\n",
                snd_strerror(rc));
        return;
    }
    /* Signed 16-bit little-endian format */
    rc=snd_pcm_hw_params_set_format(handle, params,
                                    SND_PCM_FORMAT_S16_LE);
    if (rc < 0) {
        fprintf(stderr,
                "Error:snd_pcm_hw_params_set_format %s\n",
                snd_strerror(rc));
        return;
    }
    /* Two channels (stereo) */
    rc=snd_pcm_hw_params_set_channels(handle, params, 2);
    if (rc < 0) {
        fprintf(stderr,
                "Error:snd_pcm_hw_params_set_channels %s\n",
                snd_strerror(rc));
        return;
    }
    /* 44100 bits/second sampling rate (CD quality) */
    val = 44100;
    rc=snd_pcm_hw_params_set_rate_near(handle, params,
                                       &val, &dir);
    if (rc < 0) {
        fprintf(stderr,
                "Error:snd_pcm_hw_params_set_rate_near %s\n",
                snd_strerror(rc));
        return;
    }
    /* Set period size to settings.aica.BufferSize frames. */
    frames = settings.aica.BufferSize;
    rc=snd_pcm_hw_params_set_period_size_near(handle,
            params, &frames, &dir);
    if (rc < 0) {
        fprintf(stderr,
                "Error:snd_pcm_hw_params_set_buffer_size_near %s\n",
                snd_strerror(rc));
        return;
    }
    frames*=4;
    rc=snd_pcm_hw_params_set_buffer_size_near(handle,
            params, &frames);
    if (rc < 0) {
        fprintf(stderr,
                "Error:snd_pcm_hw_params_set_buffer_size_near %s\n",
                snd_strerror(rc));
        return;
    }

    /* Write the parameters to the driver */
    rc = snd_pcm_hw_params(handle, params);
    if (rc < 0) {
        fprintf(stderr,
                "unable to set hw parameters: %s\n",
                snd_strerror(rc));
        return;
    }

    aud_thread.Start();
}