[openal] :sound file dosen't play well. Am i doing anything wrong?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
[openal] :sound file dosen't play well. Am i doing anything wrong?
Hello all.
After installing openal I tried some sound loading.
Copy/pasted this test code
Code:
Example: 'Hello, world' in ALUT
Here is the traditional first program for any language or library, but this time it is actually saying 'Hello, world!' instead of printing it:
#include <stdlib.h>
#include <AL/al.h>
#include <AL/alut.h>
int
main (int argc, char **argv)
{
ALuint helloBuffer, helloSource;
alutInit (&argc, argv);
helloBuffer = alutCreateBufferHelloWorld ();
alGenSources (1, &helloSource);
alSourcei (helloSource, AL_BUFFER, helloBuffer);
alSourcePlay (helloSource);
alutSleep (1);
alutExit ();
}
Result is a mechanical 'hello world'.
To load from file Alut specification (from openal site) says to use
Hyakutake (or Hundred-Peaks, or Hundred-Bamboo), you are trying to open "music.wav" in the code, but the file is "KDE_Startup_new.wav". Check if Buffer is valid after the open. I don't seem to have ALUT, so I can't compile and verify myself.
Thanks for your replies tuxdev (again ) and burninGpi.
burninGpi
I've compiled the source (hello world) and tried to ./a.out music.wav.
The result is the same as if I only use ./a.out
tuxdev
The "music.wav" is a copy from "KDE_Startup_new.wav". Just said that if it was a problem with sample rate/size/channels because I guess whoever usess KDE has this file .
BTW i've changed it, now it's the 20th century music
I don't really know the API, but it looks like ALUT is using a file-descriptor style. A typical error return would be -1. It really should be documented, I just don't know where.
BTW, I looked up that comet, and the second character isn't bamboo or mountain/peak like I originally thought, it is "military force". So I suppose the best translation would be "Great Military Force".
After reading some stuff at OpenAL site's document section (alut specification and openal programmers guide) I've changed the code to this
Code:
#include <stdio.h>
#include <AL/al.h>
#include <AL/alut.h>
int main()
{ALuint Buffer, Source;
alutInit(0, NULL);
alGetError(); //clear error state
alGenBuffers(1, &Buffer);
if(alGetError() != AL_NO_ERROR){printf("BUFFER ERROR\n"); }
alutGetError(); //clear error state
Buffer = alutCreateBufferFromFile("teste.wav");
switch(alutGetError()) //error type
{case ALUT_ERROR_OUT_OF_MEMORY:
printf("ERROR 1\n");
break;
case ALUT_ERROR_INVALID_OPERATION:
printf("ERROR 2\n");
break;
case ALUT_ERROR_NO_CURRENT_CONTEXT:
printf("ERROR 3\n");
break;
case ALUT_ERROR_AL_ERROR_ON_ENTRY:
printf("ERROR 4\n");
break;
case ALUT_ERROR_ALC_ERROR_ON_ENTRY:
printf("ERROR 5\n");
break;
case ALUT_ERROR_GEN_BUFFERS:
printf("ERROR 6\n");
break;
case ALUT_ERROR_BUFFER_DATA:
printf("ERROR 7\n");
break;
case ALUT_ERROR_IO_ERROR:
printf("ERROR 8\n");
break;
case ALUT_ERROR_UNSUPPORTED_FILE_TYPE:
printf("ERROR 9\n");
break;
case ALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE:
printf("ERROR 10\n");
break;
case ALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA:
printf("ERROR 11\n");
break;
}
alGetError(); //clear error state
alGenSources (1, &Source);
if(alGetError() != AL_NO_ERROR){printf("SOURCE ERROR\n"); }
alSourcei(Source, AL_BUFFER, Buffer);
alSourcei(Source, AL_LOOPING, AL_TRUE);
alSourcePlay(Source);
char c;
while(c!='q')
{c=getchar(); }
alutExit ();
}
I'm not sure if this is correct but the result gives no error and sound output is still the same. I've noticed that besides all the noise the music comes out like in slow motion
Very easy to load a sound, also "It supports WAVE-, MOD-, MIDI-, OGG- and MP3 files" (1)
It seem to be less hassle to load a file and play it but can I use this loader with openal (I like the idea of audio sources moving in a 3D space)? How can I do that?
If your interested, I'm actually coding a small example app (just to test how they work) which loads an Ogg/Vorbis file (using libogg & libvorbis), and then plays it w/ OpenAL. I'll give you a copy of the code once it's done (or post it up here). Party tonight, but I should be done it tomorrow (if you haven't solved it by then). Nearly finished already, just getting some strange errors w/ one of the vorbis functions.
I don't think you can mix SDL and OpenAL. OpenAL still has advantages over SDL, in particular, OpenAL has finer support for positional sound. SuperTux uses OpenAL, so you could try to check out http://svn.berlios.de/svnroot/repos/...tux/src/audio/
to see how they do it.
I'm reading some stuff at DevMaster's tutorial on openal and i'm messing with alc library (not very explicit on this lib but better than nothing) - it's supposed to "handle the devices on our own."
Im may be wrong here as I have never used OpenAL just DirectSound, but I would assume you would need a listener that has a location just as you have a source.
If a tree falls in the woods and there is not a listener, does it make a sound.
Introduction to OpenAL
Use of OpenAL revolves around the use of three fundamental objects – Buffers, Sources, and a
Listener. A buffer can be filled with audio data, and can then be attached to a source. The
source can then be positioned and played. How the source is heard is determined by its position
and orientation relative to the Listener object (there is only one Listener). Creating a number of
sources and buffers and a single listener and then updating the positions and orientations of the
sources and listener dynamically can present a convincing 3D audio world.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.