[Openal] reading and playing a raw file
angelo
angelo70 at gmail.com
Thu Feb 12 07:56:07 PST 2009
Thanks Jason, that definitely solved the problem.
in honour to alutCreateBufferFromFile, it don't handle raw files, since
it can't retrieve any format/frequency without a raw header.
greetings,
Angelo
Jason Daly ha scritto:
> 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