2009-10-30 2 views
0

안녕하세요?이 코드에서 무엇이 잘못 되었습니까 (openAl in vC++)

내가 당신의 도움이 필요

내가

#include <conio.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <al.h> 
#include <alc.h> 
#include <alut.h> 
#pragma comment(lib, "openal32.lib") 
#pragma comment(lib, "alut.lib") 

/* 
* These are OpenAL "names" (or "objects"). They store and id of a buffer 
* or a source object. Generally you would expect to see the implementation 
* use values that scale up from '1', but don't count on it. The spec does 
* not make this mandatory (as it is OpenGL). The id's can easily be memory 
* pointers as well. It will depend on the implementation. 
*/ 

// Buffers to hold sound data. 
ALuint Buffer; 

// Sources are points of emitting sound. 
ALuint Source; 


/* 
* These are 3D cartesian vector coordinates. A structure or class would be 
* a more flexible of handling these, but for the sake of simplicity we will 
* just leave it as is. 
*/ 

// Position of the source sound. 
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; 

// Velocity of the source sound. 
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; 


// Position of the Listener. 
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 }; 

// Velocity of the Listener. 
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 }; 

// Orientation of the Listener. (first 3 elements are "at", second 3 are "up") 
// Also note that these should be units of '1'. 
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 }; 



/* 
* ALboolean LoadALData() 
* 
* This function will load our sample data from the disk using the Alut 
* utility and send the data into OpenAL as a buffer. A source is then 
* also created to play that buffer. 
*/ 
ALboolean LoadALData() 
{ 
    // Variables to load into. 

    ALenum format; 
    ALsizei size; 
    ALvoid* data; 
    ALsizei freq; 
    ALboolean loop; 
    // Load wav data into a buffer. 

    alGenBuffers(1, &Buffer); 

    if(alGetError() != AL_NO_ERROR) 
     return AL_FALSE; 

    alutLoadWAVFile((ALbyte *)"C:\Users\Toshiba\Desktop\Graduation Project\OpenAL\open AL test\wavdata\FancyPants.wav", &format, &data, &size, &freq, &loop); 
    alBufferData(Buffer, format, data, size, freq); 
    alutUnloadWAV(format, data, size, freq); 

    // Bind the buffer with the source. 

    alGenSources(1, &Source); 

    if(alGetError() != AL_NO_ERROR) 
     return AL_FALSE; 

    alSourcei (Source, AL_BUFFER, Buffer ); 
    alSourcef (Source, AL_PITCH, 1.0  ); 
    alSourcef (Source, AL_GAIN,  1.0  ); 
    alSourcefv(Source, AL_POSITION, SourcePos); 
    alSourcefv(Source, AL_VELOCITY, SourceVel); 
    alSourcei (Source, AL_LOOPING, loop ); 

    // Do another error check and return. 

    if(alGetError() == AL_NO_ERROR) 
     return AL_TRUE; 

    return AL_FALSE; 
} 



/* 
* void SetListenerValues() 
* 
* We already defined certain values for the Listener, but we need 
* to tell OpenAL to use that data. This function does just that. 
*/ 
void SetListenerValues() 
{ 
    alListenerfv(AL_POSITION, ListenerPos); 
    alListenerfv(AL_VELOCITY, ListenerVel); 
    alListenerfv(AL_ORIENTATION, ListenerOri); 
} 



/* 
* void KillALData() 
* 
* We have allocated memory for our buffers and sources which needs 
* to be returned to the system. This function frees that memory. 
*/ 
void KillALData() 
{ 
    alDeleteBuffers(1, &Buffer); 
    alDeleteSources(1, &Source); 
    alutExit(); 
} 




int main(int argc, char *argv[]) 
{ 
    printf("MindCode's OpenAL Lesson 1: Single Static Source\n\n"); 
    printf("Controls:\n"); 
    printf("p) Play\n"); 
    printf("s) Stop\n"); 
    printf("h) Hold (pause)\n"); 
    printf("q) Quit\n\n"); 

    // Initialize OpenAL and clear the error bit. 

    alutInit(NULL, 0); 
    alGetError(); 

    // Load the wav data. 

    if(LoadALData() == AL_FALSE) 
    { 
     printf("Error loading data."); 
     return 0; 
    } 

    SetListenerValues(); 

    // Setup an exit procedure. 

    atexit(KillALData); 

    // Loop. 

ALubyte c = ' '; 

while(c != 'q') 
    { 
     c = getche(); 

     switch(c) 
    { 
      // Pressing 'p' will begin playing the sample. 

     case 'p': alSourcePlay(Source); break; 

      // Pressing 's' will stop the sample from playing. 

      case 's': alSourceStop(Source); break; 

      // Pressing 'h' will pause the sample. 

      case 'h': alSourcePause(Source); break; 
     }; 

    } 


    return 0; 
} 

는 그것이 실행이 코드를해야합니다 >>하지만 난 여기에 캔트 어떤 일 >>

도 내가 programong과 늘 새로운 오전 내 졸업 프로젝트 >>>에서 가상 현실 사운드를 프로그램하고 opeal 및 VC++를 배우기 시작합니다. 하지만 시작하는 방법과 시작해야 할 곳이 없습니다.

과 나는 API가 승리에 대해 배울 필요가 있는지 물어보고 싶니 ?? 내가 >> 것을 배울 수있는 방법을 필요로하는 경우와

을 alote 감사와 나는 사촌의 미안 내 영어

나는 최근뿐만 아니라 devmaster.net에서 바로이 같은 sample source code를 실행하려고
+0

OpenAL 샘플을 보았습니까? OpenAL11CoreSDK에는 몇 가지가 있습니다. Openal과 사운드 장치 사이에 아직 연결이되어 있지 않다면 oalinst를 설치하는 것을 잊지 마십시오. –

+0

예 다운로드 할 수 있습니다. 감사합니다. – maiajam

답변

0

. OpenAL 헤더 파일에 대한 적절한 경로를 반영하도록 #include를 변경해야합니다. C가 아닌 C++를 사용하는 경우 #include <conio.h>을 #include <iostream>으로 변경하고 getche() 대신 getchar()을 사용해야합니다.

또한 alut.h의 버전에서는 alutLoadWAVFile 함수가 6이 아닌 5 개의 매개 변수 만 허용한다는 것을 알았습니다.이 예제의 여섯 번째 매개 변수 (루프 변수)는 너무 많은 인수를 만듭니다. 함수 (적어도 내 OpenAL 버전에서).

{편집 주 :. OpenAL에의 맥 버전은하지 않지만 분명히, OpenAL에의 Windows 버전은 6 부울 루프 매개 변수를 필요로 좋아, 난 그냥 발견}이 도움이

희망.