[Openal] reading and playing a raw file

Jason Daly jdaly at ist.ucf.edu
Tue Feb 10 08:22:12 PST 2009


angelo wrote:
> Hi all,
>
> i am trying to read and play a recorded raw file, 8Khz, 16bit x sample mono.
>
> I am using "alutCreateBufferFromFile" since it is helpful, and it is 
> working fine with a regular wav file.
> If i try to open a recorded raw file (samples only, no headers,generted 
> through "alcCaptureSamples"), "alutCreateBufferFromFile" seems to load 
> it, but once played a bad sound is heard.
>   

Hi, Angelo,

Probably the best way to handle this is to just load the file directly 
(not through alut), create the buffer manually, and use alBufferData() 
to pass in your data.  It would look something like this:

   FILE *audioFile;
   unsigned char audioBuffer[AUDIO_DATA_SIZE];
   ALuint buffer, source;

   // Read the audio data from the file
   audioFile = fopen("audio.raw", "r");
   fread(audioBuffer, sizeof(unsigned char),
         AUDIO_DATA_SIZE, audioFile);

   // Generate an OpenAL buffer for the data
   alGenBuffers(1, &buffer);
   alBufferData(buffer, AL_FORMAT_MONO16, audioBuffer,
                AUDIO_DATA_SIZE, 8000);

   // Pass the buffer to an OpenAL source and play it
   alGenSources(1, &source);
   alSourcei(source, AL_BUFFER, buffer);
   alSourcePlay(source);


Hope this helps...

--"J"



More information about the Openal mailing list