달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2008. 5. 21. 11:24

FMod 기본 사용법 Programing/Windows Programing2008. 5. 21. 11:24

FMod를 사용하면서 설정을 어떻게 해야 하나 하고 한참 뒤적였는데
삭은이~님 덕분에 쉽게 해결했다..
----------------------------------------------------------------------------------------------------
FMod를 몇일 다루면서 정리할 것들

대부분 사운드 라이브러리가 그렇듯이 FMod도 간단한 초기화 몇개 호출로 시작이 가능하다.

<초기화>
// DSound 사용은 옵션사항이다. 기타 옵션이 다양하지만 대부분 FMod가 내부적으로 가장 적절한 방법을 찾는다고 한다.
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
FSOUND_SetHWND(hWnd);

const OUTPUT_FREQ = 44100;
const NUMCHANNELS = 32;

if (!FSOUND_Init(OUTPUT_FREQ, NUMCHANNELS, 0))
{
    return FALSE;
}

저장된 사운드는 Sample 과 Stream 두가지 타잎으로 가능한데 Sample은 메모리를 잡고 전부 로딩하는 것이고 Stream은 일정 용량씩 나눠서 재생해주는 것이다. 효과음은 Sample, 배경음악은 Stream 으로 하는게 일반적이라 생각된다.

<Sample 로딩 및 재생>
FSOUND_SAMPLE* sample = FSOUND_Sample_Load(FSOUND_FREE, (const char*)data->GetPtr(), FSOUND_LOADMEMORY, 0, data->GetSize());

int channel = FSOUND_PlaySoundEx(FSOUND_FREE, sample, NULL, TRUE);

FSOUND_SetVolume(channel, g_nWavVolume);

FSOUND_SetLoopMode(channel, fRepeat ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF);

FSOUND_SetPaused(channel, FALSE);

<Stream 로딩 및 재생>
FSOUND_STREAM stream = FSOUND_Stream_Open((const char*)data->GetPtr(), FSOUND_LOADMEMORY | FSOUND_LOOP_NORMAL, 0, data->GetSize());

int channel = FSOUND_Stream_Play(FSOUND_FREE, stream);

FSOUND_SetVolume(channel, g_nMp3Volume);

종료는 모든 Sample/Stream 을 지워주는게 좋지만 FMod 내부적으로 관리가 되어서 아래 함수만 호출해도 된다고 한다.

<종료시>
FSOUND_Sample_Free(sample);
FSOUND_Stream_Close(stream);
FSOUND_Close();

출처 : 삭은이~의 개인 블로그
http://zupet.tistory.com/3

:
Posted by Lunaness