Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

/root/src/subsynth/syn/Stream/OpenALAudioContext.h

Go to the documentation of this file.
00001 
00002 /****************** <SYN heading BEGIN do not edit this line> *****************
00003  *
00004  * subsynth - modular audio synthesizer
00005  * subsynth is (C) Copyright 2001-2002 by Kevin Meinert
00006  *
00007  * Original Author: Kevin Meinert
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  *
00024  * -----------------------------------------------------------------
00025  * File:          $RCSfile: OpenALAudioContext.h,v $
00026  * Date modified: $Date: 2002/04/08 16:13:28 $
00027  * Version:       $Revision: 1.14 $
00028  * -----------------------------------------------------------------
00029  *
00030  ****************** <SYN heading END do not edit this line> ******************/
00031 #ifndef OAL_SOUND_SYSTEM
00032 #define OAL_SOUND_SYSTEM
00033 
00034 #include <AL/al.h>
00035 #include <AL/alc.h>
00036 #include <AL/alut.h>
00037 
00038 #include <iostream>
00039 #include <vector>
00040 #include <string>
00041 
00042 #ifdef HAVE_VPR
00043 #  include "vpr/vpr.h"
00044 #  ifdef VPR_USE_IRIX_SPROC
00045    #error "VPR_USE_IRIX_SPROC: you idiot"
00046 #  endif
00047 #endif
00048 
00049 #ifdef _WIN32
00050    #include <windows.h>
00051 #endif
00052 
00053 #include "syn/Stream/AudioContext.h"
00054 
00055 namespace syn
00056 {
00057 
00058    // 
00059    class OpenALAudioContext : public syn::AudioContext
00060    {
00061 #ifdef WIN32
00062       ALCcontext* context_id;
00063 #else
00064       void* context_id;
00065 #endif
00066       ALCdevice* dev;
00067 
00068    public:
00069       OpenALAudioContext() : context_id( NULL ), dev( NULL )
00070       {
00071       }
00072 
00073       // opens the openal device context
00074       void open()
00075       {
00076          if (context_id == NULL && dev == NULL)
00077          {
00078             std::vector<int> attrlist;
00079             attrlist.push_back( ALC_FREQUENCY );
00080             attrlist.push_back( 44100 );
00081             attrlist.push_back( ALC_INVALID );
00082             //time_t shouldend;
00083 
00084             dev = alcOpenDevice( NULL );
00085             if (dev == NULL) 
00086             {
00087                std::cerr<<"[syn]openalctx: Could not open device\n"<<std::flush;
00088                return;
00089             }
00090 
00091 
00092             // Initialize ALUT
00093             context_id = alcCreateContext( dev, &attrlist[0] );
00094             if (context_id == NULL) 
00095             {
00096                std::string err = (char*)alGetString( alcGetError(dev) );
00097                std::cerr<<"[syn]openalctx: Could not open context: ";//<<err.c_str()<<"\n";
00098                return;
00099             }
00100 
00101             alcMakeContextCurrent( context_id );
00102          }
00103          std::cout<<"[syn]openalctx: Opened context\n"<<std::endl;
00104       }
00105 
00106       void printError()
00107       {
00108          std::string err = (char*)alGetString( alcGetError(dev) );
00109          std::cerr<<err.c_str()<<"\n";
00110       }      
00111       
00112       // closes the openal device context.
00113       void close()
00114       {
00115          alcDestroyContext( context_id );
00116          alcCloseDevice(  dev  );
00117       }  
00118    };
00119 
00120 }
00121 
00122 #endif

Generated at Mon Apr 15 09:26:08 2002 for subsynth by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001