Re: setup 3d audio

coolbreeze <[email protected]>
Newsgroups gmane.comp.lib.openal
Message-ID <1272889457.11133.20.camel@coolbreeze>
I tested with a mono sound but it is too noisy,
i find a tutorial but they use alut to load files and its depreciated...

maybe the problem is when i init openAL? or when i load the file ? with
libsndfile

/**********************************************************/
init openal:
ASS_Device* ASS_InitDevice(ASSenum device_type)
{
    ASS_Device* d=NULL;
    list_memory_allocated=NULL;

    if (!(d=(ASS_Device*)malloc(sizeof(*d)))) return NULL;

    ASS_AddLast(&list_memory_allocated,(int)d,sizeof(*d));
    d->device=NULL;
    d->context=NULL;
    switch (device_type)
    {
    case ASS_DEFAULT_DEVICE:
        d->device=alcOpenDevice(NULL);
        break;
    case ASS_PULSEAUDIO_DEVICE:
        d->device=alcOpenDevice("PulseAudio Software");
        break;
        case ASS_ALSA_DEVICE:
        d->device=alcOpenDevice("ALSA Software");
        break;
        case ASS_OSS_DEVICE:
        d->device=alcOpenDevice("OSS Software");
        break;
        case ASS_PORTAUDIO_DEVICE:
        d->device=alcOpenDevice("PortAudio Software");
        break;
        default:
        break;
    }
    if (!d->device) return NULL;

    d->context = alcCreateContext(d->device,NULL);
    if (!d->context) return NULL;

    if (!alcMakeContextCurrent(d->context))
    {
        ASS_FreeList(list_memory_allocated);
        return NULL;
    }

      is_multi_channel = (alIsExtensionPresent("AL_EXT_MCFORMATS") ==
AL_TRUE);
      printf("Audio device info:\n------------------\n");
      printf("Vendor : %s\n",alGetString(AL_VENDOR));
      printf("Version : %s\n",alGetString(AL_VERSION));
      printf("Renderer : %s\n",alGetString(AL_RENDERER ));

     return d;
}
*******************************************************************************************/

/*******************************************************************************************/
loading files :
ASSboolean ASS_LoadAudio(const char* filename,ASS_Audio* audio)
{
    audio->openal_id=0;
    audio->source=0;
    SNDFILE* file = sf_open(filename, SFM_READ, &audio->file_info);
    if (!file) return ASS_FALSE;

    audio->nbr_samples = audio->file_info.channels *
audio->file_info.frames;
    audio->sample_rate = audio->file_info.samplerate;


audio->data_samples=(ASSshort*)malloc(sizeof(ASSshort)*audio->nbr_samples);
    if (!audio->data_samples) return ASS_FALSE;
    if (sf_read_short(file, audio->data_samples,audio->nbr_samples) <
audio->nbr_samples) return ASS_FALSE;

    sf_close(file);
    switch (audio->file_info.channels)
    {
    case 1 :
        audio->audio_format = ASS_FORMAT_MONO16;
        break;
    case 2 :
        audio->audio_format = ASS_FORMAT_STEREO16;
        break;
    case 4 :
        if (is_multi_channel) audio->audio_format =
alGetEnumValue("AL_FORMAT_QUAD16");
        break;
    case 6 :
        if (is_multi_channel) audio->audio_format =
alGetEnumValue("AL_FORMAT_51CHN16");
        break;
    case 7 :
        if (is_multi_channel) audio->audio_format =
alGetEnumValue("AL_FORMAT_61CHN16");
        break;
    case 8 :
        if (is_multi_channel) audio->audio_format =
alGetEnumValue("AL_FORMAT_71CHN16");
        break;

    default :
        return ASS_FALSE;
        break;
    }
    alGenBuffers(1,&audio->openal_id);
    alBufferData(audio->openal_id,(ASSenum)audio->audio_format,
audio->data_samples,audio->nbr_samples*
sizeof(ASSushort),audio->sample_rate);

    alGenSources(1, &audio->source);
    alSourcei(audio->source,AL_BUFFER,audio->openal_id);

    alSourcef (audio->source, AL_PITCH,    1.0f     );
    alSourcef (audio->source, AL_GAIN,     1.0f     );
    alSource3f(audio->source,AL_POSITION,0.f,0.f,0.f);
    alSource3f(audio->source,AL_VELOCITY,0.0f,0.f,0.0f);
    alSourcei(audio->source,AL_SOURCE_RELATIVE ,AL_TRUE);
    /*alSourcei(audio->source,AL_LOOPING,AL_TRUE);*/
    free(audio->data_samples);
    if (alGetError() != AL_NO_ERROR) return ASS_FALSE;

    return ASS_TRUE;
}
**********************************************************************************************/

thanks for help

_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.