Пример #1
11
    void input(ALshort ** input_audio,ALshort ** output_audio) {
        ALint samples, val, state;
        // Если источник вдруг перестал играть, то пнем его
        alGetSourcei (al_source, AL_SOURCE_STATE,  &state);
        if (state != AL_PLAYING) alSourcePlay(al_source);

        alcGetIntegerv(in_device, ALC_CAPTURE_SAMPLES, sizeof(samples), &samples);
        if( (error=  alcGetError(in_device)) != AL_NO_ERROR)
            std::cout<<error<<" alcGetIntegerv "<<__LINE__<<"\n";
        alGetSourcei (al_source, AL_BUFFERS_PROCESSED , &val);
	
        while ( ( (val--) > 0) && (samples < play_buf_size)   ) {
            ALuint buffer;
	    //Write sound
            alcCaptureSamples(in_device, play_buf, samples);
	    //-Write sound

	    //Connect with main thread
	    for(int copy=0; copy<play_buf_size; copy++) input_audio[copy] = play_buf[copy];
	    for(int copy=0; copy<play_buf_size; copy++) play_buf[copy] = output_audio[copy];

	    //Play sound 
	    alSourceUnqueueBuffers(al_source, 1, &buffer);
            alBufferData(buffer, AL_FORMAT_STEREO16, play_buf, play_buf_size * sizeof(ALshort), play_buf_size);
            alSourceQueueBuffers(al_source, 1, &buffer);
	    //-Play sound

	    //Write sound
            alcGetIntegerv(in_device, ALC_CAPTURE_SAMPLES, sizeof(samples), &samples);
	    //-Write sound
        }
	
    }
Пример #2
0
bool
QALContext::create()
{
    if ((d->alcDevice = alcOpenDevice(d->requestedAttributes.deviceSpecifier().toAscii())) == false) {
        qWarning() << Q_FUNC_INFO << "Failed to open the device:" << d->requestedAttributes.deviceSpecifier();
        return false;
    }

    ALCenum error;
    if ((error = alcGetError(d->alcDevice)) != ALC_NO_ERROR) {
        qWarning() << Q_FUNC_INFO << "Error before trying to create the context:" << alcGetString(d->alcDevice, error);
    };

    ALCint attributes[] = {
        ALC_FREQUENCY, d->requestedAttributes.frequency(),
        ALC_MONO_SOURCES, d->requestedAttributes.monoSources(),
        ALC_REFRESH, d->requestedAttributes.refresh(),
        ALC_STEREO_SOURCES, d->requestedAttributes.stereoSources(),
        ALC_SYNC, d->requestedAttributes.sync(),
        0
    };

    d->alcContext = alcCreateContext(d->alcDevice, attributes);
    if ((error = alcGetError(d->alcDevice)) != ALC_NO_ERROR) {
        qWarning() << Q_FUNC_INFO << "Failed to create the context:" << alcGetString(d->alcDevice, error);
        alcCloseDevice(d->alcDevice);
        d->alcDevice = 0;
        return false;
    }

    return true;
}
Пример #3
0
static void audio_setup()
{
    clog << "Initializing audio." << endl;

    device = alcOpenDevice(NULL);
    if (device==NULL)
    {
        Exception(alcGetString(NULL, alcGetError(NULL)));
    }
    
    int attr[] = { ALC_FREQUENCY, 22050, ALC_INVALID };

    context = alcCreateContext(device, attr);
    if (context==NULL)
    {
        string error = string(alcGetString(device, alcGetError(device)));
        alcCloseDevice(device);
        Exception(error);
    }
    alcMakeContextCurrent(context);

    int major=0, minor=0;
    alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major);
    alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor);

    clog << " * Version    : " << major << '.' << minor << endl
         << " * Vendor     : " << alGetString(AL_VENDOR) << endl
         << " * Renderer   : " << alGetString(AL_RENDERER) << endl
         << " * Device     : " << alcGetString(device, ALC_DEVICE_SPECIFIER) << endl
         << " * Extensions : " << alcGetString(device, ALC_EXTENSIONS) << endl;
}
Пример #4
0
void* recAndSend(void * param){
  ALshort alrecBuffer[SAMPLESIZE];
  ALint alSample;
  ALCdevice* device = alcOpenDevice(NULL);
  ALCcontext* context = alcCreateContext(device,  NULL);
  alcMakeContextCurrent(context);
  ALCdevice* alDevice = alcCaptureOpenDevice(NULL, SRATE, AL_FORMAT_MONO16, SAMPLESIZE);
  alcGetError(alDevice);
  alcCaptureStart(alDevice);
  alcGetError(alDevice);
  while (1){
    alcGetIntegerv(alDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &alSample);
    alcGetError(alDevice);
    if(alSample > SAMPLESIZE/2) {
      alcCaptureSamples(alDevice, (ALCvoid *)alrecBuffer, alSample);
      int n;
      socklen_t addrlen = sizeof(senderinfo);
      int i;
      for(i=0; i<alSample; i++){
        if(abs((int)alrecBuffer[i]) > (0.8*INT16_MAX) ) break;
      }
      if(i==alSample) continue;
      if((n = sendto(sock, alrecBuffer, alSample*2, 0, (struct sockaddr *)&senderinfo, addrlen)) != alSample*2){
        perror("sendto");
        exit(1);
      }
    }
    if(callFlag==OFF) break;
  }
  alcCaptureCloseDevice(alDevice);
  alcCaptureStop(alDevice);
  alcCloseDevice(device);
//  fprintf(stderr, "close recAndSend\n");
}
	void SoundManager::init() {
		m_device = alcOpenDevice(NULL);

		if (!m_device || alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Could not open audio device - deactivating audio module");
			m_device = NULL;
			return;
		}

		m_context = alcCreateContext(m_device, NULL);
		if (!m_context || alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Couldn't create audio context - deactivating audio module");
			m_device = NULL;
			return;
		}

		alcMakeContextCurrent(m_context);
		if (alcGetError(m_device) != ALC_NO_ERROR) {
			FL_ERR(_log, LMsg() << "Couldn't change current audio context - deactivating audio module");
			m_device = NULL;
			return;
		}

		// set listener position
		alListener3f(AL_POSITION, 0.0, 0.0, 0.0);
		ALfloat vec1[6] = { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
		alListenerfv(AL_ORIENTATION, vec1);

		// set volume
		alListenerf(AL_GAIN, m_volume);
	}
Пример #6
0
    /* Function: alureInitDevice
     *
     * Opens the named device, creates a context with the given attributes, and
     * sets that context as current. The name and attribute list would be the same
     * as what's passed to alcOpenDevice and alcCreateContext respectively.
     *
     * Returns:
     * AL_FALSE on error.
     *
     * See Also:
     * <alureShutdownDevice>
     */
    ALURE_API ALboolean ALURE_APIENTRY alureInitDevice(const ALCchar *name, const ALCint *attribs)
    {
        ALCdevice *device = alcOpenDevice(name);
        if(!device)
        {
            alcGetError(NULL);

            SetError("Device open failed");
            return AL_FALSE;
        }

        ALCcontext *context = alcCreateContext(device, attribs);
        if(!context || alcMakeContextCurrent(context) == ALC_FALSE)
        {
            if(context)
                alcDestroyContext(context);
            alcCloseDevice(device);

            SetError("Context setup failed");
            return AL_FALSE;
        }
        alcGetError(device);

        return AL_TRUE;
    }
Пример #7
0
void AudioController::initialize()
{
    _alcDevice = alcOpenDevice(NULL);
    if (!_alcDevice)
    {
        GP_ERROR("Unable to open OpenAL device.\n");
        return;
    }
    
    _alcContext = alcCreateContext(_alcDevice, NULL);
    ALCenum alcErr = alcGetError(_alcDevice);
    if (!_alcContext || alcErr != ALC_NO_ERROR)
    {
        alcCloseDevice(_alcDevice);
        GP_ERROR("Unable to create OpenAL context. Error: %d\n", alcErr);
        return;
    }
    
    alcMakeContextCurrent(_alcContext);
    alcErr = alcGetError(_alcDevice);
    if (alcErr != ALC_NO_ERROR)
    {
        GP_ERROR("Unable to make OpenAL context current. Error: %d\n", alcErr);
    }
}
Пример #8
0
AudioAnalyzer::AudioAnalyzer(int frequency_, int captureSize_) :
	frequency(frequency_), captureSize(captureSize_), initialized(false)
{
	ALenum errorCode=0;
	inputDevice = alcCaptureOpenDevice(NULL, frequency, AL_FORMAT_MONO16, frequency/2);
	if (inputDevice == NULL) {
		Logger::Instance()->OutputString("Error: alcCaptureOpenDevice");
		return;
	}

	errorCode = alcGetError(inputDevice);
	if (errorCode != AL_NO_ERROR) {
		Logger::Instance()->OutputString("Error: alcCaptureOpenDevice -- ?");
		return;
	}
	alcCaptureStart(inputDevice); // Begin capturing
	errorCode = alcGetError(inputDevice);
	if (errorCode != AL_NO_ERROR) {
		Logger::Instance()->OutputString("Error: alcCaptureStart");
		alcCaptureCloseDevice(inputDevice);
		return;
	}

	capturedBuffer = new  short[captureSize];
	ffted = new float[captureSize];
	ar = new float[captureSize];
	ai = new float[captureSize];

	initialized = true;

	Logger::Instance()->OutputString("OpenAL succeeded");
}
Пример #9
0
	OpenALSoundManager(OnDemandSoundFetcher *fetcher):
		m_fetcher(fetcher),
		m_device(NULL),
		m_context(NULL),
		m_can_vorbis(false),
		m_next_id(1),
		m_is_initialized(false)
	{
		ALCenum error = ALC_NO_ERROR;
		
		infostream<<"Audio: Initializing..."<<std::endl;

		m_device = alcOpenDevice(NULL);
		if(!m_device){
			infostream<<"Audio: No audio device available, audio system "
				<<"not initialized"<<std::endl;
			return;
		}

		if(alcIsExtensionPresent(m_device, "EXT_vorbis")){
			infostream<<"Audio: Vorbis extension present"<<std::endl;
			m_can_vorbis = true;
		} else{
			infostream<<"Audio: Vorbis extension NOT present"<<std::endl;
			m_can_vorbis = false;
		}

		m_context = alcCreateContext(m_device, NULL);
		if(!m_context){
			error = alcGetError(m_device);
			infostream<<"Audio: Unable to initialize audio context, "
					<<"aborting audio initialization ("<<alcErrorString(error)
					<<")"<<std::endl;
			alcCloseDevice(m_device);
			m_device = NULL;
			return;
		}

		if(!alcMakeContextCurrent(m_context) ||
				(error = alcGetError(m_device) != ALC_NO_ERROR))
		{
			infostream<<"Audio: Error setting audio context, aborting audio "
					<<"initialization ("<<alcErrorString(error)<<")"<<std::endl;
			alcDestroyContext(m_context);
			m_context = NULL;
			alcCloseDevice(m_device);
			m_device = NULL;
			return;
		}

		alDistanceModel(AL_EXPONENT_DISTANCE);

		infostream<<"Audio: Initialized: OpenAL "<<alGetString(AL_VERSION)
				<<", using "<<alcGetString(m_device, ALC_DEVICE_SPECIFIER)
				<<std::endl;

		m_is_initialized = true;
	}
Пример #10
0
Status CSoundManager::AlcInit()
{	
	Status ret = INFO::OK;

	m_Device = alcOpenDevice(NULL);
	if (m_Device)
	{
		ALCint attribs[] = {ALC_STEREO_SOURCES, 16, 0};
		m_Context = alcCreateContext(m_Device, &attribs[0]);

		if (m_Context)
		{
			alcMakeContextCurrent(m_Context);
			m_ALSourceBuffer = new ALSourceHolder[SOURCE_NUM];
			ALuint* sourceList = new ALuint[SOURCE_NUM];

			alGenSources(SOURCE_NUM, sourceList);
			ALCenum err = alcGetError(m_Device);

			if (err == ALC_NO_ERROR)
			{
				for (int x = 0; x < SOURCE_NUM; x++)
				{
					m_ALSourceBuffer[x].ALSource = sourceList[x];
					m_ALSourceBuffer[x].SourceItem = NULL;
				}
				m_Enabled = true;
			}
			else
			{
				LOGERROR("error in gensource = %d", err);
			}
			delete[] sourceList;
		}
	}

	// check if init succeeded.
	// some OpenAL implementations don't indicate failure here correctly;
	// we need to check if the device and context pointers are actually valid.
	ALCenum err = alcGetError(m_Device);
	const char* dev_name = (const char*)alcGetString(m_Device, ALC_DEVICE_SPECIFIER);

	if (err == ALC_NO_ERROR && m_Device && m_Context)
		debug_printf("Sound: AlcInit success, using %s\n", dev_name);
	else
	{
		LOGERROR("Sound: AlcInit failed, m_Device=%p m_Context=%p dev_name=%s err=%x\n", (void *)m_Device, (void *)m_Context, dev_name, err);

// FIXME Hack to get around exclusive access to the sound device
#if OS_UNIX
		ret = INFO::OK;
#else
		ret = ERR::FAIL;
#endif // !OS_UNIX
	}

	return ret;
}
Пример #11
0
void csSndSysRendererOpenAL::Open()
{
  ScopedRendererLock lock (*this);

  // First assume we have both a config and a device, but no context.
  CS_ASSERT (m_Config != 0);
  CS_ASSERT (m_Device != 0);
  CS_ASSERT (m_Context == 0);

  Report (CS_REPORTER_SEVERITY_DEBUG, "Opening OpenAL sound system");

  // Clear any error condition
  alcGetError (m_Device);

  // Setup the attribute list for the OpenAL context
  const ALCint attr[] =
  {
    ALC_REFRESH,   m_Config->GetInt ("SndSys.OpenALRefresh", 10),    // How often do we update the mixahead buffer (hz).
    ALC_SYNC,      AL_FALSE,                                         // We want an asynchronous context.
    ALC_STEREO_SOURCES, 12,
    ALC_MONO_SOURCES, 120,
    0
  };
  // Note: If the sound is choppy, it may be because your OpenAL
  //       implementation does not implement async (threaded) contexts and
  //       your framerate is below SndSys.OpenALRefresh. If this is the case,
  //       please try to decrease SndSys.OpenALRefresh to below your
  //       framerate. This however will increase sound latency. Alternatively
  //       you may attempt to implement the async operation in CS.

  // Get an OpenAL context
  m_Context = alcCreateContext (m_Device, attr);
  if (m_Context == 0)
  {
    Report (CS_REPORTER_SEVERITY_ERROR, "Unable to get OpenAL context");
    CS_ASSERT (m_Context != 0);
  }

  // Make our new context current
  alcMakeContextCurrent (m_Context);

  // Set the context processing
  alcProcessContext (m_Context);

  // Check for any errors
  ALCenum err = alcGetError (m_Device);
  if (err != ALC_NO_ERROR)
  {
    Report (CS_REPORTER_SEVERITY_ERROR, "An OpenAL error occured: %s", alcGetString (m_Device, err));
    CS_ASSERT (err == ALC_NO_ERROR);
  }

  // Query available extensions
  QueryExtensions ();

  // Create a listener
  m_Listener.AttachNew(new SndSysListenerOpenAL());
}
Пример #12
0
String ALDevice::getName(PlaybackDeviceName type) const
{
    if(type == PlaybackDeviceName::Complete && !alcIsExtensionPresent(mDevice, "ALC_ENUMERATE_ALL_EXT"))
        type = PlaybackDeviceName::Basic;
    alcGetError(mDevice);
    const ALCchar *name = alcGetString(mDevice, (ALenum)type);
    if(alcGetError(mDevice) != ALC_NO_ERROR || !name)
        name = alcGetString(mDevice, (ALenum)PlaybackDeviceName::Basic);
    return name ? String(name) : String();
}
Пример #13
0
void OpenALCapture::grabSamples()
{
    alcGetIntegerv(this->capDevice, ALC_CAPTURE_SAMPLES, (ALCsizei)sizeof(ALint), &numAvailSamples);
    this->error(alcGetError(this->capDevice));
    if (numAvailSamples >= this->BUFFER_SIZE)
    {
        alcCaptureSamples(this->capDevice, &(this->tempBuffer), this->BUFFER_SIZE);
        this->error(alcGetError(this->capDevice));
        this->softWave();
    }
}
Пример #14
0
int InicializarAudio(){

	/* Asignamos el mejor dispositivo de audio disponible */
#ifdef _LINUX

	if (( Device = alcOpenDevice ((ALubyte* ) "waveOut" )) == NULL){
		fprintf ( logs,"No existe WaveOut Backend\n");
		if (( Device = alcOpenDevice (( ALubyte* ) "SDL" )) == NULL ){
			fprintf ( logs,"No existe SDL Backend\n");
			if (( Device = alcOpenDevice (( ALubyte* ) "arts" )) == NULL ){
				fprintf ( logs,"No existe arts Backend\n");
				if (( Device = alcOpenDevice ( NULL )) == NULL ){
					fprintf ( logs,"No hay disponible ningun dispositivo de audio\n");
					return -1;
				}
			}
		}
	}
#endif
#ifdef _WIN32
	if (( Device = alcOpenDevice ((ALubyte* ) "DirectSound3D" )) == NULL ){
		fprintf ( logs,"No existe DirectSound3D Backend\n");
		if (( Device = alcOpenDevice (( ALubyte* ) "DirectSound" )) == NULL ){
			fprintf ( logs,"No existe DirectSound Backend\n");
			if (( Device = alcOpenDevice (( ALubyte* ) "WaveOut" )) == NULL ){
				fprintf ( logs,"No existe WaveOut Backend\n");
				if (( Device = alcOpenDevice ( NULL )) == NULL ){
					fprintf ( logs,"No hay disponible ningun dispositivo de audio\n");
					return -1;
				}
			}
		}
	}
#endif

	/* Creamos un contexto y lo asignamos (comprobando si hay errores)*/
	if ( Device != NULL ){
		Context = alcCreateContext ( Device , NULL ); /* Creamos */
	    if ( alcGetError ( Device ) != ALC_NO_ERROR ){
			fprintf ( logs, "No se puede crear un contexto para el sistema de audio\n");
			return -1;
		}

		alcMakeContextCurrent ( Context ); /* Asignamos */
	    if ( alcGetError ( Device ) != ALC_NO_ERROR ){
			fprintf ( logs, "No se puede asignar el contexto para el sistema de audio\n");
			return -1;
		}
	}
  audio_on = 1;
  return 0;
}
Пример #15
0
/* The open method starts up the driver and should lock the device, using the
   previously set paramters, or defaults. It shouldn't need to start sending
   audio data to the device yet, however. */
static int _openal_open(void)
{
   ALenum openal_err;
   ALCenum alc_err;

   ALLEGRO_INFO("Starting OpenAL\n");

   /* clear the error state */
   openal_err = alGetError();

   /* pick default device. always a good choice */
   openal_dev = alcOpenDevice(NULL);

   alc_err = ALC_NO_ERROR;
   if (!openal_dev || (alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) {
      ALLEGRO_ERROR("Could not open audio device: %s\n",
         alc_get_err_str(alc_err));
      return 1;
   }

   openal_context = alcCreateContext(openal_dev, NULL);
   alc_err = ALC_NO_ERROR;
   if (!openal_context || (alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) {
      ALLEGRO_ERROR("Could not create current device context: %s\n",
         alc_get_err_str(alc_err));
      return 1;
   }

   alcMakeContextCurrent(openal_context);
#if !defined ALLEGRO_IPHONE
   if ((alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) {
      ALLEGRO_ERROR("Could not make context current: %s\n",
         alc_get_err_str(alc_err));
      return 1;
   }

   alDistanceModel(AL_NONE);
   if ((openal_err = alGetError()) != AL_NO_ERROR) {
      ALLEGRO_ERROR("Could not set distance model: %s\n",
         openal_get_err_str(openal_err));
      return 1;
   }
#endif

   ALLEGRO_DEBUG("Vendor: %s\n", alGetString(AL_VENDOR));
   ALLEGRO_DEBUG("Version: %s\n", alGetString(AL_VERSION));
   ALLEGRO_DEBUG("Renderer: %s\n", alGetString(AL_RENDERER));
   ALLEGRO_DEBUG("Extensions: %s\n", alGetString(AL_EXTENSIONS));

   return 0;
}
Пример #16
0
OpenALAudio::OpenALAudio( unsigned poly ) :
	mPoly( poly ),
	mNextSource( 0 )
{
	// initialization
	mDevice = alcOpenDevice( NULL ); // select the "preferred device"

	if ( mDevice == NULL )
		throw OpenALAudioExc( "Could not open audio device" );

	mContext = alcCreateContext( mDevice, NULL );
	if ( mContext == NULL )
		throw "Could not open context " + string( alGetString( alcGetError( mDevice ) ) );
	alcMakeContextCurrent( mContext );

	alListener3f( AL_POSITION, 0.f, 0.f, 0.f );

	// generate the sources
	for ( int i = 0; i < mPoly; ++i )
	{
		unsigned id;
		alGenSources( 1, &id );
		mSources.push_back( id );
	}
}
Пример #17
0
    AudioWorld::AudioWorld(Engine::BaseEngine& engine, AudioEngine& audio_engine, const VDFS::FileIndex& vdfidx)
        : m_Engine(engine)
        , m_VDFSIndex(vdfidx)
        , m_exiting(false)
    {
#ifdef RE_USE_SOUND
        if (!audio_engine.getDevice())
            return;

        m_Context = alcCreateContext(audio_engine.getDevice(), nullptr);
        if (!m_Context)
        {
            LogWarn() << "Could not create OpenAL context: "
                      << AudioEngine::getErrorString(alcGetError(audio_engine.getDevice()));
            return;
        }

        alcMakeContextCurrent(m_Context);

        alListener3f(AL_POSITION, 0, 0, 0.0f);
        // check for errors
        alListener3f(AL_VELOCITY, 0, 0, 0);
        // check for errors
        ALfloat listenerOri[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f};
        alListenerfv(AL_ORIENTATION, listenerOri);

        // Need this for AL_MAX_DISTANCE to work
        alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);

        createSounds();

        initializeMusic();
#endif
    }
Пример #18
0
//TODO: ENABLE OPTIONS FOR AUDIO
bool SoundManager::_initAL()
{
	SingletonLogMgr::Instance()->AddNewLine("SoundManager::InitAL","Initializing sound system...",LOGNORMAL);
	
	ALenum error;
	ALCdevice* pDevice;
	ALCcontext* pContext;

	SingletonLogMgr::Instance()->AddNewLine("SoundManager::InitAL","Opening default sound device...",LOGNORMAL);
	// Get handle to default device.
	pDevice = alcOpenDevice(NULL);

	if(pDevice == NULL)
		throw GenericException("Cant open default sound device. Reinstall drivers and check audio device configuration",GenericException::LIBRARY_ERROR);

	SingletonLogMgr::Instance()->AddNewLine("SoundManager::InitAL","Default sound device opened",LOGNORMAL);

	// Create audio context.
	pContext = alcCreateContext(pDevice, NULL);
	if(pContext == NULL)
		throw GenericException("Cant open default sound device. Reinstall drivers and check audio device configuration",GenericException::LIBRARY_ERROR);
	// Set active context.
	alcMakeContextCurrent(pContext);

	// Check for an error.
	if ((error=alcGetError(pDevice)) != ALC_NO_ERROR)
	{
		SingletonLogMgr::Instance()->AddNewLine("SoundManager::InitAL","Can't create openAL context (" + GetALErrorString(error,true) + ")",LOGEXCEPTION);
		throw(GenericException("Can't create openAL context (" + GetALErrorString(error,true) + ")",GenericException::LIBRARY_ERROR));
	}

	SingletonLogMgr::Instance()->AddNewLine("SoundManager::InitAL","Sound system initialized correctly",LOGNORMAL);
	return true;
}
Пример #19
0
static int group_audio_open_out_device(int groupnum)
{
    char dname[MAX_STR_SIZE];
    get_primary_device_name(output, dname, sizeof(dname));
    dname[MAX_STR_SIZE - 1] = '\0';

    groupchats[groupnum].audio.dvhandle = alcOpenDevice(dname);

    if (groupchats[groupnum].audio.dvhandle == NULL)
        return -1;

    groupchats[groupnum].audio.dvctx = alcCreateContext(groupchats[groupnum].audio.dvhandle, NULL);
    alcMakeContextCurrent(groupchats[groupnum].audio.dvctx);
    alGenBuffers(OPENAL_BUFS, groupchats[groupnum].audio.buffers);
    alGenSources((uint32_t) 1, &groupchats[groupnum].audio.source);
    alSourcei(groupchats[groupnum].audio.source, AL_LOOPING, AL_FALSE);

    if (alcGetError(groupchats[groupnum].audio.dvhandle) != AL_NO_ERROR) {
        group_audio_close_out_device(groupnum);
        groupchats[groupnum].audio.dvhandle = NULL;
        groupchats[groupnum].audio.dvctx = NULL;
        return -1;
    }

    alSourceQueueBuffers(groupchats[groupnum].audio.source, OPENAL_BUFS, groupchats[groupnum].audio.buffers);
    alSourcePlay(groupchats[groupnum].audio.source);

    return 0;
}
Пример #20
0
	//-----------------------------------------------------------------//
	void audio_io::initialize()
	{
		if(init_) return;

		device_ = alcOpenDevice(nullptr);
		if(device_ == nullptr) {
			ALenum error = alGetError();
			if(error != AL_NO_ERROR) {
				std::cout << "OpenAL error: alcOpenDevice" << std::endl;
			// die("AL", (const char*)alGetString(error));
			}
			return;
		}

		context_ = alcCreateContext(device_, nullptr);
		if(context_ == nullptr) {
			ALCenum error = alcGetError(device_);
			if(error != ALC_NO_ERROR) {
			// die("ALC", (const char*)alcGetString(device, error));
			}
			return;
		}
		alcMakeContextCurrent(context_);
		init_ = true;
		destroy_ = false;
	}
Пример #21
0
static PyObject*
_device_repr (PyObject *self)
{
    PyObject *retval;
    const ALCchar *name;
    size_t len;
    char *str;
    
    CLEAR_ALCERROR_STATE ();
    name = alcGetString (PyDevice_AsDevice (self), ALC_DEVICE_SPECIFIER);
    if (!name)
    {
        SetALCErrorException (alcGetError (PyDevice_AsDevice (self)), 1);
        return NULL;
    }

    /* Device('') == 10 */
    len = strlen ((const char*) name) + 11;
    str = malloc (len);
    if (!str)
        return NULL;

    snprintf (str, len, "Device('%s')", (const char*) name);
    retval = Text_FromUTF8 (str);
    free (str);
    return retval;
}
Пример #22
0
bool CsAudioManager::Init(ALCchar *deviceName)  {
	//initialize the audio library
    ALCdevice* pDevice;
    ALCcontext* pContext;
    const ALCchar* deviceSpecifier;
    // Get handle to device.
    pDevice = alcOpenDevice(deviceName);
    // Get the device specifier.
    deviceSpecifier = alcGetString(pDevice, ALC_DEVICE_SPECIFIER);
    // Create audio context.
    pContext = alcCreateContext(pDevice, NULL);

    // Set active context.
    alcMakeContextCurrent(pContext);

    // Check for an error.
    if (alcGetError(pDevice) != ALC_NO_ERROR)
        return false;

    alGenBuffers(NUM_SOUNDS, Buffer);

	LoadBuffer("../../sounds/0explosion.wav", EXPLOSION);
	LoadBuffer("../../sounds/0FIREMISSILE.wav",FIRE_MISSILE);
	LoadBuffer("../../sounds/0FIREMACHINEGUN.wav",FIRE_MACHINEGUN);
	LoadBuffer("../../sounds/0JETENGINE.wav", JET_ENGINE);
	LoadBuffer("../../sounds/0COLLISION.wav", COLLISION);
	LoadBuffer("../../sounds/0RICOCHET.wav", RICOCHET);
	LoadBuffer("../../sounds/game_music.wav", GAME_MUSIC);
	LoadBuffer("../../sounds/menu_music.wav", MENU_MUSIC);
	//LoadBuffer("wavdata/stereo.wav", MENU_SOUND);
	//LoadBuffer("wavdata/stereo.wav", EXPLOSION_SOUND);

	return true;
}
Пример #23
0
static void
checkForErrors (void)
{
  {
    ALenum error = alutGetError ();
    if (error != ALUT_ERROR_NO_ERROR)
      {
        die ("ALUT", alutGetErrorString (error));
      }
  }
  {
    ALCdevice *device = alcGetContextsDevice (alcGetCurrentContext ());
    ALCenum error = alcGetError (device);
    if (error != ALC_NO_ERROR)
      {
        die ("ALC", (const char *) alcGetString (device, error));
      }
  }
  {
    ALenum error = alGetError ();
    if (error != AL_NO_ERROR)
      {
        die ("AL", (const char *) alGetString (error));
      }
  }
}
Пример #24
0
static int init(struct ao *ao)
{
    float position[3] = {0, 0, 0};
    float direction[6] = {0, 0, 1, 0, -1, 0};
    ALCdevice *dev = NULL;
    ALCcontext *ctx = NULL;
    ALCint freq = 0;
    ALCint attribs[] = {ALC_FREQUENCY, ao->samplerate, 0, 0};
    int i;
    struct priv *p = ao->priv;
    if (ao_data) {
        MP_FATAL(ao, "Not reentrant!\n");
        return -1;
    }
    ao_data = ao;
    ao->no_persistent_volume = true;
    struct mp_chmap_sel sel = {0};
    for (i = 0; speaker_pos[i].id != -1; i++)
        mp_chmap_sel_add_speaker(&sel, speaker_pos[i].id);
    if (!ao_chmap_sel_adjust(ao, &sel, &ao->channels))
        goto err_out;
    struct speaker speakers[MAX_CHANS];
    for (i = 0; i < ao->channels.num; i++) {
        speakers[i].id = -1;
        for (int n = 0; speaker_pos[n].id >= 0; n++) {
            if (speaker_pos[n].id == ao->channels.speaker[i])
                speakers[i] = speaker_pos[n];
        }
        if (speakers[i].id < 0) {
            MP_FATAL(ao, "Unknown channel layout\n");
            goto err_out;
        }
    }
    dev = alcOpenDevice(p->cfg_device && p->cfg_device[0] ? p->cfg_device : NULL);
    if (!dev) {
        MP_FATAL(ao, "could not open device\n");
        goto err_out;
    }
    ctx = alcCreateContext(dev, attribs);
    alcMakeContextCurrent(ctx);
    alListenerfv(AL_POSITION, position);
    alListenerfv(AL_ORIENTATION, direction);
    alGenSources(ao->channels.num, sources);
    for (i = 0; i < ao->channels.num; i++) {
        cur_buf[i] = 0;
        unqueue_buf[i] = 0;
        alGenBuffers(NUM_BUF, buffers[i]);
        alSourcefv(sources[i], AL_POSITION, speakers[i].pos);
        alSource3f(sources[i], AL_VELOCITY, 0, 0, 0);
    }
    alcGetIntegerv(dev, ALC_FREQUENCY, 1, &freq);
    if (alcGetError(dev) == ALC_NO_ERROR && freq)
        ao->samplerate = freq;
    ao->format = AF_FORMAT_S16_NE;
    tmpbuf = malloc(CHUNK_SIZE);
    return 0;

err_out:
    return -1;
}
Пример #25
0
static ALCenum checkALCErrors(ALCdevice *device, int linenum)
{
    ALCenum err = alcGetError(device);
    if(err != ALC_NO_ERROR)
        printf("ALC Error: %s (0x%x), @ %d\n", alcGetString(device, err), err, linenum);
    return err;
}
Пример #26
0
ALboolean initOpenAL()
{
    ALCdevice* pDevice;
    ALCcontext* pContext;
    ALCubyte* deviceSpecifier;
    ALCubyte deviceName[] = "DirectSound3D";

    // Get handle to device.
    pDevice = alcOpenDevice(deviceName);

    // Get the device specifier.
    deviceSpecifier = alcGetString(pDevice, ALC_DEVICE_SPECIFIER);

    // Create audio context.
    pContext = alcCreateContext(pDevice, NULL);

    // Set active context.
    alcMakeContextCurrent(pContext);

    // Check for an error.
    if (alcGetError(pDevice) != ALC_NO_ERROR)
        return AL_FALSE;

    return AL_TRUE;
}
Пример #27
0
QALAttributes
QALContext::attributes() const
{
    if (isValid() == false)
        return QALAttributes::defaultAttributes();

    ALCenum error;

    if ((error = alcGetError(d->alcDevice)) != ALC_NO_ERROR) {
        qWarning() << Q_FUNC_INFO << "Error before trying to create attributes:" << alcGetString(d->alcDevice, error);
    };

    QALAttributes attributes;
    attributes.setDeviceSpecifier(alcGetString(d->alcDevice, ALC_DEVICE_SPECIFIER));

    ALCint tmp;

    alcGetIntegerv(d->alcDevice, ALC_FREQUENCY, 1, &tmp);
    attributes.setFrequency(tmp);

    alcGetIntegerv(d->alcDevice, ALC_REFRESH, 1, &tmp);
    attributes.setRefresh(tmp);

    alcGetIntegerv(d->alcDevice, ALC_SYNC, 1, &tmp);
    attributes.setSync(tmp);

    alcGetIntegerv(d->alcDevice, ALC_MONO_SOURCES, 1, &tmp);
    attributes.setMonoSources(tmp);

    alcGetIntegerv(d->alcDevice, ALC_STEREO_SOURCES, 1, &tmp);
    attributes.setStereoSources(tmp);

    return attributes;
}
Пример #28
0
 bool recreateContext(int freq)
 {
     if (!device)
     {
         URHO3D_LOGERROR("Failed to create OpenAL context, device is not open");
         return false;
     }
     if (freq == 0)
     {
         ALCint dev_rate = 0;
         alcGetIntegerv(device, ALC_FREQUENCY, 1, &dev_rate);
         if (ALC_NO_ERROR == alcGetError(device))
             freq = dev_rate;
     }
     ALCint attrvalues[] = {ALC_FREQUENCY, freq, 0};
     alGetError();
     if (!context)
     {
         context = alcCreateContext(device, attrvalues);
     }
     else
     {
         assert(alcResetDeviceSOFT!=nullptr);
         alcResetDeviceSOFT(device, attrvalues);
     }
     if (!alcMakeContextCurrent(context))
     {
         auto errorcode = alGetError();
         URHO3D_LOGERROR(QString("Failed to create OpenAL context: alerror = %1").arg(errorcode));
         return false;
     }
     return true;
 }
Пример #29
0
ALboolean
_alutSanityCheck (void)
{
  ALCcontext *context;

  if (initialisationState == Unintialized)
    {
      _alutSetError (ALUT_ERROR_INVALID_OPERATION);
      return AL_FALSE;
    }

  context = alcGetCurrentContext ();
  if (context == NULL)
    {
      _alutSetError (ALUT_ERROR_NO_CURRENT_CONTEXT);
      return AL_FALSE;
    }

  if (alGetError () != AL_NO_ERROR)
    {
      _alutSetError (ALUT_ERROR_AL_ERROR_ON_ENTRY);
      return AL_FALSE;
    }

  if (alcGetError (alcGetContextsDevice (context)) != ALC_NO_ERROR)
    {
      _alutSetError (ALUT_ERROR_ALC_ERROR_ON_ENTRY);
      return AL_FALSE;
    }

  return AL_TRUE;
}
Пример #30
0
OpenAL::OpenAL()
    : audioThread{new QThread}
    , alInDev{nullptr}
    , inSubscriptions{0}
    , alOutDev{nullptr}
    , alOutContext{nullptr}
    , alMainSource{0}
    , alMainBuffer{0}
    , outputInitialized{false}
{
    // initialize OpenAL error stack
    alGetError();
    alcGetError(nullptr);

    audioThread->setObjectName("qTox Audio");
    QObject::connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);

    moveToThread(audioThread);

    connect(&captureTimer, &QTimer::timeout, this, &OpenAL::doCapture);
    captureTimer.setInterval(AUDIO_FRAME_DURATION / 2);
    captureTimer.setSingleShot(false);
    captureTimer.start();
    connect(&playMono16Timer, &QTimer::timeout, this, &OpenAL::playMono16SoundCleanup);
    playMono16Timer.setSingleShot(true);

    audioThread->start();
}