OpenAL with C++ WindowsForm application?

View: New views
9 Messages — Rating Filter:   Alert me  

OpenAL with C++ WindowsForm application?

by Ümit Uzun :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

I have an application which had created with MFC before and now I want to upgrade it with new OpenAL 1.1 version and Windows Form. I have created new C++ WindowsForm project in VS2008 and only add framework and set related include and library configurations. But when I compile I always get

.\OpenAL\framework\Win32\Framework.cpp(200) : error C2664: 'CWaves::GetWaveALBufferFormat' : cannot convert parameter 2 from 'ALenum (__cdecl *)(const ALchar *)' to 'PFNALGETENUMVALUE'
Address of a function yields __clrcall calling convention in /clr:pure and /clr:safe; consider using __clrcall in target type

error which I can't find anything at internet about. I think it is related about /clr because we have to use CommonLanguageRuntimeSupport beside with MFC we don't need clr.

How can I solve my problem?
Do you think I can create OpenAL based application which uses framework like before with Windows Form or not?

Regards.

Ümit Uzun

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: OpenAL with C++ WindowsForm application?

by Jason Daly :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm not an authority on CLR or Forms, but I do know that if you want to
use OpenAL with the CLR, you'll have to wrap the library so you can
access the native OpenAL methods from your managed code.

I don't know much more than that, as I haven't had to do it yet myself.  
Maybe someone else can give you more specific help, or you could do some
Google searching on using native C functions from managed C++

--"J"



Ümit Uzun wrote:

> Hi All,
>
> I have an application which had created with MFC before and now I want
> to upgrade it with new OpenAL 1.1 version and Windows Form. I have
> created new C++ WindowsForm project in VS2008 and only add framework
> and set related include and library configurations. But when I compile
> I always get
>
> .\OpenAL\framework\Win32\Framework.cpp(200) : error C2664:
> 'CWaves::GetWaveALBufferFormat' : cannot convert parameter 2 from
> 'ALenum (__cdecl *)(const ALchar *)' to 'PFNALGETENUMVALUE'
> Address of a function yields __clrcall calling convention in /clr:pure
> and /clr:safe; consider using __clrcall in target type
>
> error which I can't find anything at internet about. I think it is
> related about /clr because we have to use CommonLanguageRuntimeSupport
> beside with MFC we don't need clr.
>
> How can I solve my problem?
> Do you think I can create OpenAL based application which uses
> framework like before with Windows Form or not?
>
> Regards.
>
> Ümit Uzun

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: OpenAL with C++ WindowsForm application?

by Stephen A. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2009-09-28 at 10:48 -0400, Jason Daly wrote:
> I'm not an authority on CLR or Forms, but I do know that if you want to
> use OpenAL with the CLR, you'll have to wrap the library so you can
> access the native OpenAL methods from your managed code.

Generally, C++/CLI supports "it just works" (IJW) interop with plain C
libraries, but there might be few cases where you'll have to fix things
by hand. I'm not especially familiar with C++/CLI but this seems like
one of those cases.

The CLR generally uses delegates to pass managed function pointers to
unmanaged code and vice versa. Try wrapping this function to receive a
delegate decorated decorated with the UnmangedFunctionPointerAttribute.

The other approach is to use a full-blown managed wrapper around OpenAL
and avoid the need to wrap things by hand. There are a few of those out
there - I'd recommend OpenTK (http://www.opentk.com), if only because I
happen to be its main developer. :) This is a low-level, "flat" wrapper
around OpenAL (i.e. *not* an object oriented abstraction), but it takes
advantage of some features not available in plain C (e.g. strong types,
enumerations, function overloads,, generics).

> Ümit Uzun wrote:
> > Hi All,
> >
> > I have an application which had created with MFC before and now I want
> > to upgrade it with new OpenAL 1.1 version and Windows Form. I have
> > created new C++ WindowsForm project in VS2008 and only add framework
> > and set related include and library configurations. But when I compile
> > I always get
> >
> > .\OpenAL\framework\Win32\Framework.cpp(200) : error C2664:
> > 'CWaves::GetWaveALBufferFormat' : cannot convert parameter 2 from
> > 'ALenum (__cdecl *)(const ALchar *)' to 'PFNALGETENUMVALUE'
> > Address of a function yields __clrcall calling convention in /clr:pure
> > and /clr:safe; consider using __clrcall in target type
> >
> > error which I can't find anything at internet about. I think it is
> > related about /clr because we have to use CommonLanguageRuntimeSupport
> > beside with MFC we don't need clr.
> >
> > How can I solve my problem?
> > Do you think I can create OpenAL based application which uses
> > framework like before with Windows Form or not?
> >
> > Regards.
> >
> > Ümit Uzun
>
> _______________________________________________
> Openal mailing list
> Openal@...
> http://opensource.creative.com/mailman/listinfo/openal

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

RE: OpenAL with C++ WindowsForm application?

by Pierre-Henri François :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I had the same problem with previous version, and the solution was to put the non-managed #include in top of the file... as follow (in my case)

        // ILT-TP.cpp : fichier projet principal.
        #include "AudioRecorder.h"
        #include "stdafx.h"

You also need to ask a /clr option (not /clr:pure).
I hope it can help...

Pierre-Henri


-----Message d'origine-----
De : openal-bounces@... [mailto:openal-bounces@...] De la part de Jason Daly
Envoyé : lundi 28 septembre 2009 16:48
À : Ümit Uzun
Cc : OpenAL
Objet : Re: [Openal] OpenAL with C++ WindowsForm application?


I'm not an authority on CLR or Forms, but I do know that if you want to
use OpenAL with the CLR, you'll have to wrap the library so you can
access the native OpenAL methods from your managed code.

I don't know much more than that, as I haven't had to do it yet myself.  
Maybe someone else can give you more specific help, or you could do some
Google searching on using native C functions from managed C++

--"J"



Ümit Uzun wrote:

> Hi All,
>
> I have an application which had created with MFC before and now I want
> to upgrade it with new OpenAL 1.1 version and Windows Form. I have
> created new C++ WindowsForm project in VS2008 and only add framework
> and set related include and library configurations. But when I compile
> I always get
>
> .\OpenAL\framework\Win32\Framework.cpp(200) : error C2664:
> 'CWaves::GetWaveALBufferFormat' : cannot convert parameter 2 from
> 'ALenum (__cdecl *)(const ALchar *)' to 'PFNALGETENUMVALUE'
> Address of a function yields __clrcall calling convention in /clr:pure
> and /clr:safe; consider using __clrcall in target type
>
> error which I can't find anything at internet about. I think it is
> related about /clr because we have to use CommonLanguageRuntimeSupport
> beside with MFC we don't need clr.
>
> How can I solve my problem?
> Do you think I can create OpenAL based application which uses
> framework like before with Windows Form or not?
>
> Regards.
>
> Ümit Uzun

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: OpenAL with C++ WindowsForm application?

by quattro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If your interested I've been working on an object oriented wrapper that is very close to being ready for its first release, it's written in c# and comes with unit tests and some samples. I'm currently finishing up streaming but most of the other features are there, if nothing else it might provide a good place to start. My goal is to recruit people to use it in a game soon and write some articles on how to use it. If you use it let me know what you think. http://openal-net-sdk.sourceforge.net

On Mon, Sep 28, 2009 at 8:05 AM, Stefanos A. <stapostol@...> wrote:
On Mon, 2009-09-28 at 10:48 -0400, Jason Daly wrote:
> I'm not an authority on CLR or Forms, but I do know that if you want to
> use OpenAL with the CLR, you'll have to wrap the library so you can
> access the native OpenAL methods from your managed code.

Generally, C++/CLI supports "it just works" (IJW) interop with plain C
libraries, but there might be few cases where you'll have to fix things
by hand. I'm not especially familiar with C++/CLI but this seems like
one of those cases.

The CLR generally uses delegates to pass managed function pointers to
unmanaged code and vice versa. Try wrapping this function to receive a
delegate decorated decorated with the UnmangedFunctionPointerAttribute.

The other approach is to use a full-blown managed wrapper around OpenAL
and avoid the need to wrap things by hand. There are a few of those out
there - I'd recommend OpenTK (http://www.opentk.com), if only because I
happen to be its main developer. :) This is a low-level, "flat" wrapper
around OpenAL (i.e. *not* an object oriented abstraction), but it takes
advantage of some features not available in plain C (e.g. strong types,
enumerations, function overloads,, generics).

> Ümit Uzun wrote:
> > Hi All,
> >
> > I have an application which had created with MFC before and now I want
> > to upgrade it with new OpenAL 1.1 version and Windows Form. I have
> > created new C++ WindowsForm project in VS2008 and only add framework
> > and set related include and library configurations. But when I compile
> > I always get
> >
> > .\OpenAL\framework\Win32\Framework.cpp(200) : error C2664:
> > 'CWaves::GetWaveALBufferFormat' : cannot convert parameter 2 from
> > 'ALenum (__cdecl *)(const ALchar *)' to 'PFNALGETENUMVALUE'
> > Address of a function yields __clrcall calling convention in /clr:pure
> > and /clr:safe; consider using __clrcall in target type
> >
> > error which I can't find anything at internet about. I think it is
> > related about /clr because we have to use CommonLanguageRuntimeSupport
> > beside with MFC we don't need clr.
> >
> > How can I solve my problem?
> > Do you think I can create OpenAL based application which uses
> > framework like before with Windows Form or not?
> >
> > Regards.
> >
> > Ümit Uzun
>
> _______________________________________________
> Openal mailing list
> Openal@...
> http://opensource.creative.com/mailman/listinfo/openal

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal


_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: OpenAL with C++ WindowsForm application?

by Ümit Uzun :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All;

Thanks for your all relies.

>Stefanos, I have looked at openTK but I have an specific situation. OpenAL is wrap our soundCard or emulate soundCard by Generic Software and it encapsulate all low level function, but by using Framework I can select expected channel to play mono sound. For example I can play different mono sound to different channel by using specified configuration in Framework.cpp, if I use OpenTK could I inject some part of framework?

template<typename T> T *load_data(const T *data, int size, const char *channels)
{
    size /= sizeof(T);

    T *data71 = new T[size * 8];

    for(int i = 0; i < size; i++)
    {
        data71[i * 8 + 0] = channels[0] == '1' ? data[i] : 0;  // front-left speaker
        data71[i * 8 + 1] = channels[1] == '1' ? data[i] : 0;  // front-right speaker
        data71[i * 8 + 2] = channels[2] == '1' ? data[i] : 0;  // front-center speaker
        data71[i * 8 + 3] = channels[3] == '1' ? data[i] : 0;  // low frequency (sub-woofer) speaker
        data71[i * 8 + 4] = channels[4] == '1' ? data[i] : 0;  // back-left speaker
        data71[i * 8 + 5] = channels[5] == '1' ? data[i] : 0;  // back-right speaker
        data71[i * 8 + 6] = channels[6] == '1' ? data[i] : 0;  // side-left speaker
        data71[i * 8 + 7] = channels[7] == '1' ? data[i] : 0;  // side-right speaker
    }

    return data71;
}

>Pierre, I can't understand your soulution. Where should I add "stdafx.h" in my code? Did you add stdafx.h to Framework or your own code?

By the experiment on WindowsForm using QT framework will be much easy I think. I don't decided which GUI should use but if there is much striction on WindowsForm about OpenAL, qt would be good solution. I don't want to use wrapper because I love coding on low level OpenAL and it's much controllable to me. If I can't solve this problem without wrapper usage I would use different GUI I think.

Thanks for your awesome answers.
Regards.

Ümit Uzun


2009/9/28 Reese <quattro004@...>
If your interested I've been working on an object oriented wrapper that is very close to being ready for its first release, it's written in c# and comes with unit tests and some samples. I'm currently finishing up streaming but most of the other features are there, if nothing else it might provide a good place to start. My goal is to recruit people to use it in a game soon and write some articles on how to use it. If you use it let me know what you think. http://openal-net-sdk.sourceforge.net


On Mon, Sep 28, 2009 at 8:05 AM, Stefanos A. <stapostol@...> wrote:
On Mon, 2009-09-28 at 10:48 -0400, Jason Daly wrote:
> I'm not an authority on CLR or Forms, but I do know that if you want to
> use OpenAL with the CLR, you'll have to wrap the library so you can
> access the native OpenAL methods from your managed code.

Generally, C++/CLI supports "it just works" (IJW) interop with plain C
libraries, but there might be few cases where you'll have to fix things
by hand. I'm not especially familiar with C++/CLI but this seems like
one of those cases.

The CLR generally uses delegates to pass managed function pointers to
unmanaged code and vice versa. Try wrapping this function to receive a
delegate decorated decorated with the UnmangedFunctionPointerAttribute.

The other approach is to use a full-blown managed wrapper around OpenAL
and avoid the need to wrap things by hand. There are a few of those out
there - I'd recommend OpenTK (http://www.opentk.com), if only because I
happen to be its main developer. :) This is a low-level, "flat" wrapper
around OpenAL (i.e. *not* an object oriented abstraction), but it takes
advantage of some features not available in plain C (e.g. strong types,
enumerations, function overloads,, generics).

> Ümit Uzun wrote:
> > Hi All,
> >
> > I have an application which had created with MFC before and now I want
> > to upgrade it with new OpenAL 1.1 version and Windows Form. I have
> > created new C++ WindowsForm project in VS2008 and only add framework
> > and set related include and library configurations. But when I compile
> > I always get
> >
> > .\OpenAL\framework\Win32\Framework.cpp(200) : error C2664:
> > 'CWaves::GetWaveALBufferFormat' : cannot convert parameter 2 from
> > 'ALenum (__cdecl *)(const ALchar *)' to 'PFNALGETENUMVALUE'
> > Address of a function yields __clrcall calling convention in /clr:pure
> > and /clr:safe; consider using __clrcall in target type
> >
> > error which I can't find anything at internet about. I think it is
> > related about /clr because we have to use CommonLanguageRuntimeSupport
> > beside with MFC we don't need clr.
> >
> > How can I solve my problem?
> > Do you think I can create OpenAL based application which uses
> > framework like before with Windows Form or not?
> >
> > Regards.
> >
> > Ümit Uzun
>
> _______________________________________________
> Openal mailing list
> Openal@...
> http://opensource.creative.com/mailman/listinfo/openal

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal


_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal



_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: OpenAL with C++ WindowsForm application?

by Stephen A. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2009-09-29 at 15:27 +0300, Ümit Uzun wrote:

> Hi All;
>
> Thanks for your all relies.
>
> >Stefanos, I have looked at openTK but I have an specific situation.
> OpenAL is wrap our soundCard or emulate soundCard by Generic Software
> and it encapsulate all low level function, but by using Framework I
> can select expected channel to play mono sound. For example I can play
> different mono sound to different channel by using specified
> configuration in Framework.cpp, if I use OpenTK could I inject some
> part of framework?
>
> template<typename T> T *load_data(const T *data, int size, const char
> *channels)
> {
>     [snipped]
> }

I'm not sure I understand your question 100%, but your code snippet does
not actually use OpenAL. This code should work without any changes.

The interesting part comes right after this, when you call alBufferData
(which is called AL::BufferData in OpenTK). Translating the call should
be easy but please post if you encounter any problems.

In general, OpenTK provides a 1-1 wrapper over the OpenAL API. It does
not restrict you in any way - if you can output 7.1 sound output using
OpenAL directly, you can also do it through OpenTK.

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: OpenAL with C++ WindowsForm application?

by Ümit Uzun :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Stefanos;

I attached the Framework.cpp which is part of OpenAL 1.1's framework's part. I have changed some part as said before. What I have tried to do is while I load the waves with ALFWLoadWaveToBuffer function I send extra parameter which tell the framework that loading data will be playing only specified channels. For example my defined channel for one sound is "11110000" this tell the OpenAL this sound's channels to be played.

This is my channel specification. There is 8 bit and every bit tells the OpenAL's ALFWLoadWaveToBuffer function to load sended sounds for specified channels only. If channel 1 pass the sound value else pass the 0.

<!-- Channels Enum for 7.1 12345678 -->
<!--   1 : Front Left      Speaker  -->
<!--   2 : Front Right     Speaker  -->
<!--   3 : Front Center    Speaker  -->
<!--   4 : Low   Frequency Speaker  -->
<!--   5 : Back  Left      Speaker  -->
<!--   6 : Back  Right     Speaker  -->
<!--   7 : Side  Left      Speaker  -->
<!--   8 : Side  Right     Speaker  -->

Can OpenTK support me same control? Does it let me to change BufferData's ingredients to play my expected channels only?
If I bother you please forgive me I haven't played OpenTK yet, and I don't know it's capability.

Regards.

Ümit Uzun


2009/9/29 Stefanos A. <stapostol@...>
On Tue, 2009-09-29 at 15:27 +0300, Ümit Uzun wrote:
> Hi All;
>
> Thanks for your all relies.
>
> >Stefanos, I have looked at openTK but I have an specific situation.
> OpenAL is wrap our soundCard or emulate soundCard by Generic Software
> and it encapsulate all low level function, but by using Framework I
> can select expected channel to play mono sound. For example I can play
> different mono sound to different channel by using specified
> configuration in Framework.cpp, if I use OpenTK could I inject some
> part of framework?
>
> template<typename T> T *load_data(const T *data, int size, const char
> *channels)
> {
>     [snipped]
> }

I'm not sure I understand your question 100%, but your code snippet does
not actually use OpenAL. This code should work without any changes.

The interesting part comes right after this, when you call alBufferData
(which is called AL::BufferData in OpenTK). Translating the call should
be easy but please post if you encounter any problems.

In general, OpenTK provides a 1-1 wrapper over the OpenAL API. It does
not restrict you in any way - if you can output 7.1 sound output using
OpenAL directly, you can also do it through OpenTK.



[Framework.cpp]

/*
 * Copyright (c) 2006, Creative Labs Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided
 * that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright notice, this list of conditions and
 *     the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
 *     and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *     * Neither the name of Creative Labs Inc. nor the names of its contributors may be used to endorse or
 *     promote products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

// Win32 version of the Creative Labs OpenAL 1.1 Framework for samples
#include<windows.h>
#include<stdio.h>

#include "Framework.h"
#include "CWaves.h"
#include "aldlist.h"

static CWaves *g_pWaveLoader = NULL;

// Imported EFX functions

// Effect objects
LPALGENEFFECTS alGenEffects = NULL;
LPALDELETEEFFECTS alDeleteEffects = NULL;
LPALISEFFECT alIsEffect = NULL;
LPALEFFECTI alEffecti = NULL;
LPALEFFECTIV alEffectiv = NULL;
LPALEFFECTF alEffectf = NULL;
LPALEFFECTFV alEffectfv = NULL;
LPALGETEFFECTI alGetEffecti = NULL;
LPALGETEFFECTIV alGetEffectiv = NULL;
LPALGETEFFECTF alGetEffectf = NULL;
LPALGETEFFECTFV alGetEffectfv = NULL;

//Filter objects
LPALGENFILTERS alGenFilters = NULL;
LPALDELETEFILTERS alDeleteFilters = NULL;
LPALISFILTER alIsFilter = NULL;
LPALFILTERI alFilteri = NULL;
LPALFILTERIV alFilteriv = NULL;
LPALFILTERF alFilterf = NULL;
LPALFILTERFV alFilterfv = NULL;
LPALGETFILTERI alGetFilteri = NULL;
LPALGETFILTERIV alGetFilteriv = NULL;
LPALGETFILTERF alGetFilterf = NULL;
LPALGETFILTERFV alGetFilterfv = NULL;

// Auxiliary slot object
LPALGENAUXILIARYEFFECTSLOTS alGenAuxiliaryEffectSlots = NULL;
LPALDELETEAUXILIARYEFFECTSLOTS alDeleteAuxiliaryEffectSlots = NULL;
LPALISAUXILIARYEFFECTSLOT alIsAuxiliaryEffectSlot = NULL;
LPALAUXILIARYEFFECTSLOTI alAuxiliaryEffectSloti = NULL;
LPALAUXILIARYEFFECTSLOTIV alAuxiliaryEffectSlotiv = NULL;
LPALAUXILIARYEFFECTSLOTF alAuxiliaryEffectSlotf = NULL;
LPALAUXILIARYEFFECTSLOTFV alAuxiliaryEffectSlotfv = NULL;
LPALGETAUXILIARYEFFECTSLOTI alGetAuxiliaryEffectSloti = NULL;
LPALGETAUXILIARYEFFECTSLOTIV alGetAuxiliaryEffectSlotiv = NULL;
LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf = NULL;
LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv = NULL;

// XRAM functions and enum values

LPEAXSETBUFFERMODE eaxSetBufferMode = NULL;
LPEAXGETBUFFERMODE eaxGetBufferMode = NULL;

ALenum eXRAMSize = 0;
ALenum eXRAMFree = 0;
ALenum eXRAMAuto = 0;
ALenum eXRAMHardware = 0;
ALenum eXRAMAccessible = 0;

template<typename T> T *load_data(const T *data, int size, const char *channels)
{
    size /= sizeof(T);

    T *data71 = new T[size * 8];

    for(int i = 0; i < size; i++)
    {
        data71[i * 8 + 0] = channels[0] == '1' ? data[i] : 0;  // front-left speaker
        data71[i * 8 + 1] = channels[1] == '1' ? data[i] : 0;  // front-right speaker
        data71[i * 8 + 2] = channels[2] == '1' ? data[i] : 0;  // front-center speaker
        data71[i * 8 + 3] = channels[3] == '1' ? data[i] : 0;  // low frequency (sub-woofer) speaker
        data71[i * 8 + 4] = channels[4] == '1' ? data[i] : 0;  // back-left speaker
        data71[i * 8 + 5] = channels[5] == '1' ? data[i] : 0;  // back-right speaker
        data71[i * 8 + 6] = channels[6] == '1' ? data[i] : 0;  // side-left speaker
        data71[i * 8 + 7] = channels[7] == '1' ? data[i] : 0;  // side-right speaker
    }

    return data71;
}

// Initialization and enumeration
void ALFWInit()
{
        g_pWaveLoader = new CWaves();
}

void ALFWShutdown()
{
        if (g_pWaveLoader)
        {
                delete g_pWaveLoader;
                g_pWaveLoader = NULL;
        }

        //ALFWprintf("\nPress a key to quit\n");
        //ALchar ch = _getch();
}

ALboolean ALFWInitOpenAL()
{
        ALDeviceList *pDeviceList = NULL;
        ALCcontext *pContext = NULL;
        ALCdevice *pDevice = NULL;
        //ALint i;
        ALboolean bReturn = AL_FALSE;

        pDeviceList = new ALDeviceList();
        if ((pDeviceList) && (pDeviceList->GetNumDevices()))
        {
                //ALFWprintf("\nSelect OpenAL Device:\n");
                //for (i = 0; i < pDeviceList->GetNumDevices(); i++)
                        //ALFWprintf("%d. %s%s\n", i + 1, pDeviceList->GetDeviceName(i), i == pDeviceList->GetDefaultDevice() ? "(DEFAULT)" : "");
       
                //do {
                        //ALchar ch = _getch();
                        //i = atoi(&ch);
                //} while ((i < 1) || (i > pDeviceList->GetNumDevices()));

                //pDevice = alcOpenDevice(pDeviceList->GetDeviceName(i - 1));
                pDevice = alcOpenDevice(pDeviceList->GetDeviceName(pDeviceList->GetDefaultDevice()));
                if (pDevice)
                {
                        pContext = alcCreateContext(pDevice, NULL);
                        if (pContext)
                        {
                                //ALFWprintf("\nOpened %s Device\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
                                alcMakeContextCurrent(pContext);
                                bReturn = AL_TRUE;
                        }
                        else
                        {
                                alcCloseDevice(pDevice);
                        }
                }

                delete pDeviceList;
        }

        return bReturn;
}

ALboolean ALFWShutdownOpenAL()
{
        ALCcontext *pContext;
        ALCdevice *pDevice;

        pContext = alcGetCurrentContext();
        pDevice = alcGetContextsDevice(pContext);
       
        alcMakeContextCurrent(NULL);
        alcDestroyContext(pContext);
        alcCloseDevice(pDevice);

        return AL_TRUE;
}

ALboolean ALFWLoadWaveToBuffer(const char *szWaveFile, ALuint uiBufferID, ALenum eXRAMBufferMode, const char *channels)
{
        WAVEID WaveID;
        ALint iDataSize, iFrequency;
        ALenum eBufferFormat;
        ALchar *pData;
        ALboolean bReturn;

        bReturn = AL_FALSE;
        if (g_pWaveLoader)
        {
                if (SUCCEEDED(g_pWaveLoader->LoadWaveFile(szWaveFile, &WaveID)))
                {
                        if ((SUCCEEDED(g_pWaveLoader->GetWaveSize(WaveID, (unsigned long*)&iDataSize))) &&
                                (SUCCEEDED(g_pWaveLoader->GetWaveData(WaveID, (void**)&pData))) &&
                                (SUCCEEDED(g_pWaveLoader->GetWaveFrequency(WaveID, (unsigned long*)&iFrequency))) &&
                                (SUCCEEDED(g_pWaveLoader->GetWaveALBufferFormat(WaveID, &alGetEnumValue, (unsigned long*)&eBufferFormat))))
                        {
                                // Set XRAM Mode (if application)
                                if (eaxSetBufferMode && eXRAMBufferMode)
                                        eaxSetBufferMode(1, &uiBufferID, eXRAMBufferMode);

                WAVEFORMATEX fmt;
                g_pWaveLoader->GetWaveFormatExHeader(WaveID, &fmt);

                if(fmt.wBitsPerSample == 8)         // assumes 8-bit byte
                {
                    ALbyte *data = load_data((const ALbyte*)pData, iDataSize, channels);
                    alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_71CHN8"), data, iDataSize * 8, iFrequency);
                    delete[] data;
                }
                else if(fmt.wBitsPerSample == 16)   // assumes 16-bit short
                {
                    ALshort *data = load_data((const ALshort*)pData, iDataSize, channels);
                    alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_71CHN16"), data, iDataSize * 8, iFrequency);
                    delete[] data;
                }
                else if(fmt.wBitsPerSample == 32)   // assumes 32-bit float
                {
                    ALfloat *data = load_data((const ALfloat*)pData, iDataSize, channels);
                    alBufferData(uiBufferID, alGetEnumValue("AL_FORMAT_71CHN32"), data, iDataSize * 8, iFrequency);
                    delete[] data;
                }

                                alGetError();
                                //alBufferData(uiBufferID, eBufferFormat, pData, iDataSize, iFrequency);
                                if (alGetError() == AL_NO_ERROR)
                                        bReturn = AL_TRUE;

                                g_pWaveLoader->DeleteWaveFile(WaveID);
                        }
                }
        }

        return bReturn;
}

void ALFWprintf( const char* x, ... )
{
    va_list args;
    va_start( args, x );
    vprintf( x, args );
    va_end( args );
}

ALchar fullPath[_MAX_PATH];
ALchar *ALFWaddMediaPath(const ALchar *filename)
{
        sprintf_s(fullPath, _MAX_PATH, "%s%s", "..\\..\\Media\\", filename);
        return fullPath;
}

ALint ALFWKeyPress(void)
{
        return _kbhit();
}

// Extension Queries

ALboolean ALFWIsXRAMSupported()
{
        ALboolean bXRAM = AL_FALSE;
       
        if (alIsExtensionPresent("EAX-RAM") == AL_TRUE)
        {
                // Get X-RAM Function pointers
                eaxSetBufferMode = (EAXSetBufferMode)alGetProcAddress("EAXSetBufferMode");
                eaxGetBufferMode = (EAXGetBufferMode)alGetProcAddress("EAXGetBufferMode");

                if (eaxSetBufferMode && eaxGetBufferMode)
                {
                        eXRAMSize = alGetEnumValue("AL_EAX_RAM_SIZE");
                        eXRAMFree = alGetEnumValue("AL_EAX_RAM_FREE");
                        eXRAMAuto = alGetEnumValue("AL_STORAGE_AUTOMATIC");
                        eXRAMHardware = alGetEnumValue("AL_STORAGE_HARDWARE");
                        eXRAMAccessible = alGetEnumValue("AL_STORAGE_ACCESSIBLE");

                        if (eXRAMSize && eXRAMFree && eXRAMAuto && eXRAMHardware && eXRAMAccessible)
                                bXRAM = AL_TRUE;
                }
        }

        return bXRAM;
}

ALboolean ALFWIsEFXSupported()
{
        ALCdevice *pDevice = NULL;
        ALCcontext *pContext = NULL;
        ALboolean bEFXSupport = AL_FALSE;

        pContext = alcGetCurrentContext();
        pDevice = alcGetContextsDevice(pContext);

        if (alcIsExtensionPresent(pDevice, (ALCchar*)ALC_EXT_EFX_NAME))
        {
                // Get function pointers
                alGenEffects = (LPALGENEFFECTS)alGetProcAddress("alGenEffects");
                alDeleteEffects = (LPALDELETEEFFECTS )alGetProcAddress("alDeleteEffects");
                alIsEffect = (LPALISEFFECT )alGetProcAddress("alIsEffect");
                alEffecti = (LPALEFFECTI)alGetProcAddress("alEffecti");
                alEffectiv = (LPALEFFECTIV)alGetProcAddress("alEffectiv");
                alEffectf = (LPALEFFECTF)alGetProcAddress("alEffectf");
                alEffectfv = (LPALEFFECTFV)alGetProcAddress("alEffectfv");
                alGetEffecti = (LPALGETEFFECTI)alGetProcAddress("alGetEffecti");
                alGetEffectiv = (LPALGETEFFECTIV)alGetProcAddress("alGetEffectiv");
                alGetEffectf = (LPALGETEFFECTF)alGetProcAddress("alGetEffectf");
                alGetEffectfv = (LPALGETEFFECTFV)alGetProcAddress("alGetEffectfv");
                alGenFilters = (LPALGENFILTERS)alGetProcAddress("alGenFilters");
                alDeleteFilters = (LPALDELETEFILTERS)alGetProcAddress("alDeleteFilters");
                alIsFilter = (LPALISFILTER)alGetProcAddress("alIsFilter");
                alFilteri = (LPALFILTERI)alGetProcAddress("alFilteri");
                alFilteriv = (LPALFILTERIV)alGetProcAddress("alFilteriv");
                alFilterf = (LPALFILTERF)alGetProcAddress("alFilterf");
                alFilterfv = (LPALFILTERFV)alGetProcAddress("alFilterfv");
                alGetFilteri = (LPALGETFILTERI )alGetProcAddress("alGetFilteri");
                alGetFilteriv= (LPALGETFILTERIV )alGetProcAddress("alGetFilteriv");
                alGetFilterf = (LPALGETFILTERF )alGetProcAddress("alGetFilterf");
                alGetFilterfv= (LPALGETFILTERFV )alGetProcAddress("alGetFilterfv");
                alGenAuxiliaryEffectSlots = (LPALGENAUXILIARYEFFECTSLOTS)alGetProcAddress("alGenAuxiliaryEffectSlots");
                alDeleteAuxiliaryEffectSlots = (LPALDELETEAUXILIARYEFFECTSLOTS)alGetProcAddress("alDeleteAuxiliaryEffectSlots");
                alIsAuxiliaryEffectSlot = (LPALISAUXILIARYEFFECTSLOT)alGetProcAddress("alIsAuxiliaryEffectSlot");
                alAuxiliaryEffectSloti = (LPALAUXILIARYEFFECTSLOTI)alGetProcAddress("alAuxiliaryEffectSloti");
                alAuxiliaryEffectSlotiv = (LPALAUXILIARYEFFECTSLOTIV)alGetProcAddress("alAuxiliaryEffectSlotiv");
                alAuxiliaryEffectSlotf = (LPALAUXILIARYEFFECTSLOTF)alGetProcAddress("alAuxiliaryEffectSlotf");
                alAuxiliaryEffectSlotfv = (LPALAUXILIARYEFFECTSLOTFV)alGetProcAddress("alAuxiliaryEffectSlotfv");
                alGetAuxiliaryEffectSloti = (LPALGETAUXILIARYEFFECTSLOTI)alGetProcAddress("alGetAuxiliaryEffectSloti");
                alGetAuxiliaryEffectSlotiv = (LPALGETAUXILIARYEFFECTSLOTIV)alGetProcAddress("alGetAuxiliaryEffectSlotiv");
                alGetAuxiliaryEffectSlotf = (LPALGETAUXILIARYEFFECTSLOTF)alGetProcAddress("alGetAuxiliaryEffectSlotf");
                alGetAuxiliaryEffectSlotfv = (LPALGETAUXILIARYEFFECTSLOTFV)alGetProcAddress("alGetAuxiliaryEffectSlotfv");

                if (alGenEffects && alDeleteEffects && alIsEffect && alEffecti && alEffectiv && alEffectf &&
                        alEffectfv && alGetEffecti && alGetEffectiv && alGetEffectf && alGetEffectfv && alGenFilters &&
                        alDeleteFilters && alIsFilter && alFilteri && alFilteriv && alFilterf && alFilterfv &&
                        alGetFilteri && alGetFilteriv && alGetFilterf && alGetFilterfv && alGenAuxiliaryEffectSlots &&
                        alDeleteAuxiliaryEffectSlots && alIsAuxiliaryEffectSlot && alAuxiliaryEffectSloti &&
                        alAuxiliaryEffectSlotiv && alAuxiliaryEffectSlotf && alAuxiliaryEffectSlotfv &&
                        alGetAuxiliaryEffectSloti && alGetAuxiliaryEffectSlotiv && alGetAuxiliaryEffectSlotf &&
                        alGetAuxiliaryEffectSlotfv)
                        bEFXSupport = AL_TRUE;
        }

        return bEFXSupport;
}


_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: OpenAL with C++ WindowsForm application?

by Stephen A. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 2009-09-29 at 18:10 +0300, Ümit Uzun wrote:
> Can OpenTK support me same control? Does it let me to change
> BufferData's ingredients to play my expected channels only?

As far as I can see, OpenTK supports everything necessary for
Framework.cpp.  Just note that you won't be able to use this file
directly.

The reason is that OpenTK is a .Net API, not a C API like OpenAL. This
means that some concepts will be slightly different - and I'm not sure
whether this is the best route for your application.

C++/CLI can use both C APIs and .Net APIs natively - both approaches can
work, but depending on the specific API one might be easier than the
other. In this case, maybe it would be simpler to modify
GetWaveALBufferFormat() with an implementation that does not use
function pointers at all?

If this is not possible, you can translate parts of ALFW to use OpenTK.
I don't know how large ALFW is, but I suspect this is going to be a lot
of work.

Framework.cpp itself should be relatively easy to translate:

1. ALFW[Init/Shutdown]OpenAL() init / deinit can be replaced by a single
line of code: just create an OpenTK.::Audio::AudioContext() instance.
OpenTK also provides ALC bindings (OpenTK::Audio::OpenAL::Alc), but
there's little reason to use them.

2. EFX extensions are initialized automatically (no need to set up
function pointers and initialize them by hand). This means that 50% of
Framework.cpp is redudant and can be removed completely.

3. ALFWLoadWaveToBuffer() can be translated directly to use
OpenTK::Audio::OpenAL::AL methods.

All in all, the resulting implementation will be about 1/3 of the
current Framework.cpp.

> If I bother you please forgive me I haven't played OpenTK yet, and I
> don't know it's capability.

Hey, no problem! :)


_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal