Beispiel #1
0
int main(int argc, char ** argv)
{
   int status = 0;
   int NumVoices = 8;
   int NumChannels = 2;
   int NumBits = 16;
   unsigned MixRate = 32000;
   void * initdata = 0;
   int voice = FX_Error;
   const char * song = "test.ogg";
   
   if (argc > 1) {
      song = argv[1];
   }
   
#ifdef _WIN32
   initdata = win_gethwnd();
#endif
   
   status = FX_Init( ASS_AutoDetect, NumVoices, &NumChannels, &NumBits, &MixRate, initdata );
   if (status != FX_Ok) {
      fprintf(stderr, "FX_Init error %s\n", FX_ErrorString(status));
      return 1;
   }
   
   fprintf(stdout, "Format is %dHz %d-bit %d-channel\n", MixRate, NumBits, NumChannels);
   
   playsong(song);
   
   FX_Shutdown();
   
   return 0;
}
Beispiel #2
0
void SoundStartup( void )
{
   int32 status;
    int fxdevicetype;
    void * initdata = 0;

   // if they chose None lets return
    if (FXDevice < 0) {
        return;
    } else if (FXDevice == 0) {
        fxdevicetype = ASS_AutoDetect;
    } else {
        fxdevicetype = FXDevice - 1;
    }
    
    #ifdef _WIN32
    initdata = (void *) win_gethwnd();
    #endif

   status = FX_Init( fxdevicetype, NumVoices, &NumChannels, &NumBits, &MixRate, initdata );
   if ( status == FX_Ok ) {
      FX_SetVolume( FXVolume );
      FX_SetReverseStereo(ReverseStereo);
	  status = FX_SetCallBack( testcallback );
  }

   if ( status != FX_Ok ) {
	  sprintf(buf, "Sound startup error: %s", FX_ErrorString( FX_Error ));
	  gameexit(buf);
   }
	
	FXDevice = 0;
}
Beispiel #3
0
void
SoundStartup(void)
{
    int32_t status;
    void *initdata = 0;
    int fxdevicetype;

    // if they chose None lets return
    if (FXDevice < 0)
    {
        gs.FxOn = FALSE;
        return;
    }
    else if (FXDevice == 0)
    {
        fxdevicetype = ASS_AutoDetect;
    }
    else
    {
        fxdevicetype = FXDevice - 1;
    }

#ifdef MIXERTYPEWIN
    initdata = (void *) win_gethwnd();
#endif

    //gs.FxOn = TRUE;

    status = FX_Init(fxdevicetype, NumVoices, NumChannels, NumBits, MixRate, initdata);
    if (status == FX_Ok)
    {
        FxInitialized = TRUE;
        FX_SetVolume(gs.SoundVolume);

        if (gs.FlipStereo)
            FX_SetReverseStereo(!FX_GetReverseStereo());
    }
    if (status != FX_Ok)
    {
        buildprintf("Sound error: %s\n",FX_ErrorString(FX_Error));
    }

    status = FX_SetCallBack(SoundCallBack);

    if (status != FX_Ok)
    {
        buildprintf("Sound error: %s\n",FX_ErrorString(FX_Error));
    }

}
Beispiel #4
0
void Error(char *error, ...)
{
	char buf[1000];
	va_list va;

	Shutdown();

	if (error) {
		va_start(va, error);
		vsprintf(buf, error, va);
		va_end(va);

		MessageBox((HWND)win_gethwnd(),buf,"Fatal Error",MB_OK|MB_TASKMODAL);
	}

	exit((error != NULL));
}
Beispiel #5
0
void S_SoundStartup(void)
{
    void *initdata = NULL;

#ifdef MIXERTYPEWIN
    initdata = (void *) win_gethwnd(); // used for DirectSound
#endif

    initprintf("Initializing sound... ");

    if (FX_Init(ASS_AutoDetect, ud.config.NumVoices, ud.config.NumChannels, ud.config.MixRate, initdata) != FX_Ok)
    {
        initprintf("failed! %s\n", FX_ErrorString(FX_Error));
        return;
    }

    initprintf("%d voices, %d channels, %d-bit %d Hz\n", ud.config.NumVoices, ud.config.NumChannels,
        ud.config.NumBits, ud.config.MixRate);

    for (int i=0; i<g_maxSoundPos; ++i)
    {
        for (int j = 0; j<MAXSOUNDINSTANCES; ++j)
        {
            g_sounds[i].num = 0;
            g_sounds[i].SoundOwner[j].voice = 0;
            g_sounds[i].SoundOwner[j].ow = -1;
            g_sounds[i].SoundOwner[j].sndist = UINT32_MAX;
            g_sounds[i].SoundOwner[j].clock = 0;
        }

        g_soundlocks[i] = 199;
    }

    FX_SetVolume(ud.config.MasterVolume);
    S_MusicVolume(MASTER_VOLUME(ud.config.MusicVolume));

    FX_SetReverseStereo(ud.config.ReverseStereo);
    FX_SetCallBack(S_Callback);
    FX_SetPrintf(initprintf);
    mutex_init(&s_mutex);
}
Beispiel #6
0
int32_t wm_ynbox(const char *name, const char *fmt, ...)
{
    char buf[2048];
    char c;
    va_list va;

    UNREFERENCED_PARAMETER(name);

    va_start(va, fmt);
    vsprintf(buf, fmt, va);
    va_end(va);

#if defined __APPLE__
    return osx_ynbox(name, buf);
#elif defined HAVE_GTK2
    {
        int32_t r = gtkbuild_ynbox(name, buf);
        if (r >= 0)
            return r;
    }
#elif defined _WIN32
    return (MessageBox(win_gethwnd(),buf,name,MB_YESNO|MB_ICONQUESTION|MB_TASKMODAL) == IDYES);
#elif defined GEKKO
    puts(buf);
    puts("Assuming yes...");
    return 1;
#endif

    // NOTE: this is dead code for most #ifdef cases above.
    puts(buf);
    puts("   (type 'Y' or 'N', and press Return or Enter to continue)");
    do c = getchar(); while (c != 'Y' && c != 'y' && c != 'N' && c != 'n');
    if (c == 'Y' || c == 'y') return 1;

    return 0;
}
Beispiel #7
0
/*
 * DSOUND_Init
 * Initializes the DirectSound objects.
 */
int DSOUND_Init(int soundcard, int mixrate, int numchannels, int samplebits, int buffersize)
{
	HRESULT (WINAPI *aDirectSoundCreate)(LPGUID,LPDIRECTSOUND*,LPUNKNOWN);
	HRESULT hr;
	DSBUFFERDESC dsbuf;
	WAVEFORMATEX wfex;
	DSBPOSITIONNOTIFY posn;
	
	if (DSOUND_Installed) {
		DSOUND_Shutdown();
	}

	printOSD("Initializing DirectSound...\n");
	
	if (!_DSOUND_CriticalSectionAlloced) {
		// initialize the critical section object we'll use to
		// simulate (dis|en)abling interrupts
		InitializeCriticalSection(&mutex);
		_DSOUND_CriticalSectionAlloced = TRUE;
	}

	printOSD("  - Loading DSOUND.DLL\n");
	hDSoundDLL = LoadLibrary("DSOUND.DLL");
	if (!hDSoundDLL) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_NoDLL);
		return DSOUND_Error;
	}

	aDirectSoundCreate = (void *)GetProcAddress(hDSoundDLL, "DirectSoundCreate");
	if (!aDirectSoundCreate) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_NoDirectSoundCreate);
		return DSOUND_Error;
	}

	printOSD("  - Creating DirectSound object\n");
	hr = aDirectSoundCreate(NULL, &lpDS, NULL);
	if (hr != DS_OK) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedDSC);
		return DSOUND_Error;
	}

	hr = IDirectSound_SetCooperativeLevel(lpDS, (HWND)win_gethwnd(), DSSCL_EXCLUSIVE);
	if (hr != DS_OK) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedSetCoopLevel);
		return DSOUND_Error;
	}

	printOSD("  - Creating primary buffer\n");
	ZeroMemory(&dsbuf, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);
	dsbuf.dwFlags = DSBCAPS_PRIMARYBUFFER;
	hr = IDirectSound_CreateSoundBuffer(lpDS, &dsbuf, &lpDSBPrimary, NULL);
	if (hr != DS_OK) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedCreatePrimary);
		return DSOUND_Error;
	}

	printOSD("  - Setting primary buffer format\n"
	         "      Channels:    %d\n"
		 "      Sample rate: %dHz\n"
		 "      Sample size: %d bits\n",
		 numchannels, mixrate, samplebits);
	ZeroMemory(&wfex, sizeof(wfex));
	wfex.wFormatTag      = WAVE_FORMAT_PCM;
	wfex.nChannels       = numchannels;
	wfex.nSamplesPerSec  = mixrate;
	wfex.wBitsPerSample  = samplebits;
	wfex.nBlockAlign     = (wfex.wBitsPerSample / 8) * wfex.nChannels;
	wfex.nAvgBytesPerSec = wfex.nBlockAlign * wfex.nSamplesPerSec;
	hr = IDirectSoundBuffer_SetFormat(lpDSBPrimary, &wfex);
	if (hr != DS_OK) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedSetFormat);
		return DSOUND_Error;
	}

	printOSD("  - Creating secondary buffer\n");
	ZeroMemory(&dsbuf, sizeof(dsbuf));
	dsbuf.dwSize = sizeof(DSBUFFERDESC);
	dsbuf.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLPOSITIONNOTIFY | DSBCAPS_LOCSOFTWARE;
	dsbuf.dwBufferBytes = buffersize;
	dsbuf.lpwfxFormat = &wfex;
	hr = IDirectSound_CreateSoundBuffer(lpDS, &dsbuf, &lpDSBSecondary, NULL);
	if (hr != DS_OK) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedCreateSecondary);
		return DSOUND_Error;
	}

	hr = IDirectSoundBuffer_QueryInterface(lpDSBSecondary, &IID_IDirectSoundNotify, &lpDSNotify);
	if (hr != DS_OK) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedQueryNotify);
		return DSOUND_Error;
	}

	hPosNotify = (HANDLE *)malloc(sizeof(HANDLE));
	if (!hPosNotify) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedSetNotify);
		return DSOUND_Error;
	}
	
	hPosNotify[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
	if (!hPosNotify) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedCreateNotifyEvent);
		return DSOUND_Error;
	}

	_DSOUND_BufferLength = 0;
	_DSOUND_NumBuffers   = 1;
	posn.dwOffset = 0;
	posn.hEventNotify = hPosNotify[0];

	hr = IDirectSoundNotify_SetNotificationPositions(lpDSNotify, 1, &posn);
	if (hr != DS_OK) {
		DSOUND_Shutdown();
		DSOUND_SetErrorCode(DSOUND_FailedSetNotify);
		return DSOUND_Error;
	}

	DSOUND_Installed = TRUE;
	
	DSOUND_SetErrorCode(DSOUND_Ok);
	return DSOUND_Ok;
}