~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to intern/SoundSystem/openal/SND_OpenALDevice.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: SND_OpenALDevice.cpp,v 1.12 2004/04/17 01:14:35 kester Exp $
 
2
 * $Id: SND_OpenALDevice.cpp,v 1.20 2005/06/08 18:54:16 ton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
31
31
 * SND_OpenALDevice derived from SND_IAudioDevice
32
32
 */
33
33
 
34
 
#ifdef HAVE_CONFIG_H
35
 
#include <config.h>
36
 
#endif
37
 
 
38
34
#ifdef WIN32
39
35
#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
40
36
#endif //WIN32
60
56
#endif
61
57
#include <fcntl.h>
62
58
 
 
59
#include <signal.h>
 
60
 
63
61
/* untill openal gets unified we need this hack for non-windows systems */
64
62
#if !defined(WIN32) && !defined(ALC_MAJOR_VERSION)
65
63
 
202
200
 
203
201
#endif /* WIN32 */
204
202
 
 
203
#ifdef __APPLE__
 
204
#define OUDE_OPENAL 1
 
205
#endif
205
206
 
206
207
 
207
208
SND_OpenALDevice::SND_OpenALDevice()
 
209
        : SND_AudioDevice(),
 
210
          m_context(NULL),
 
211
          m_device(NULL)
208
212
{
209
213
    /* Removed the functionality for checking if noaudio was provided on */
210
214
    /* the commandline. */
229
233
                        if (m_context) {
230
234
                                alcMakeContextCurrent(m_context);
231
235
                                m_audio = true;
 
236
                                m_device = dev;
 
237
#ifdef __linux__
 
238
                                /*
 
239
                                *   SIGHUP Hack:
 
240
                                *
 
241
                                *   On Linux, alcDestroyContext generates a SIGHUP (Hangup) when killing the OpenAL
 
242
                                *   mixer thread, which kills Blender.
 
243
                                *  
 
244
                                *   So we set the signal to ignore....
 
245
                                *
 
246
                                *   TODO: check if this applies to other platforms.
 
247
                                *
 
248
                                */
 
249
                                signal(SIGHUP, SIG_IGN);
 
250
#endif
232
251
                        }
233
252
                }
234
253
 
301
320
 
302
321
SND_OpenALDevice::~SND_OpenALDevice()
303
322
{
 
323
        MakeCurrent();
 
324
        
 
325
        if (m_buffersinitialized)
 
326
        {
 
327
                alDeleteBuffers(NUM_BUFFERS, m_buffers);
 
328
                m_buffersinitialized = false;
 
329
        }
 
330
        
 
331
        if (m_sourcesinitialized)
 
332
        {
 
333
                for (int i = 0; i < NUM_SOURCES; i++)
 
334
                        alSourceStop(m_sources[i]);
 
335
                
 
336
                alDeleteSources(NUM_SOURCES, m_sources);
 
337
                m_sourcesinitialized = false;
 
338
        }
 
339
        
304
340
        if (m_context) {
305
 
                alcMakeContextCurrent(m_context);
306
 
 
307
 
                if (m_buffersinitialized)
308
 
                        alDeleteBuffers(NUM_BUFFERS, m_buffers);
309
 
 
310
 
                if (m_sourcesinitialized)
311
 
                        alDeleteSources(NUM_SOURCES, m_sources);
 
341
                MakeCurrent();
 
342
                alcDestroyContext(m_context);
 
343
                m_context = NULL;
312
344
        }
313
345
        
 
346
#ifdef __linux__
 
347
        // restore the signal state above.
 
348
        signal(SIGHUP, SIG_DFL);
 
349
#endif  
314
350
        // let's see if we used the cd. if not, just leave it alone
315
351
        SND_CDObject* pCD = SND_CDObject::Instance();
316
352
        
323
359
        if (m_cdrom)
324
360
                delete m_cdrom;
325
361
#endif
 
362
#ifdef OUDE_OPENAL
 
363
        if (m_audio)
 
364
                alutExit();
 
365
#else
 
366
        if (m_device)
 
367
                alcCloseDevice((ALCdevice*) m_device);
 
368
#endif
326
369
}
327
370
 
328
371
 
346
389
                        {
347
390
                                int buffer = waveslot->GetBuffer();
348
391
                                void* data = NULL;
 
392
#ifndef __APPLE__
349
393
                                char loop = 'a';
 
394
#endif
350
395
                                int sampleformat, bitrate, numberofchannels;
351
396
                                ALenum al_error = alGetError();
352
397
                                
353
398
#ifdef OUDE_OPENAL
354
399
                                unsigned int samplerate, numberofsamples;               // openal_2.12
355
400
#else
356
 
                                int samplerate, numberofsamples, frequency;  // openal_2.14+
 
401
                                int samplerate, numberofsamples;  // openal_2.14+
357
402
#endif
358
403
                                
 
404
                                /* Give them some safe defaults just incase */
 
405
                                bitrate = numberofchannels = 0;
 
406
 
359
407
                                /* load the sample from memory? */
360
408
                                if (size && memlocation)
361
409
                                {
382
430
                                else
383
431
                                {
384
432
#ifdef __APPLE__
385
 
                                        alutLoadWAVFile((signed char*)samplename.Ptr(), &sampleformat, &data, &numberofsamples, &samplerate);
386
 
#elif defined(WIN32)
387
 
                                        alutLoadWAVFile((signed char*)samplename.Ptr(), &sampleformat, &data, &numberofsamples, &samplerate, &loop);
 
433
                                        alutLoadWAVFile((ALbyte *)samplename.Ptr(), &sampleformat, &data, &numberofsamples, &samplerate);
388
434
#else
389
 
                                        alutLoadWAV((char*)samplename.Ptr(), &data,
390
 
                                                &sampleformat, &numberofsamples,
391
 
                                                &samplerate, &frequency);
 
435
                                        alutLoadWAVFile((ALbyte *)samplename.Ptr(), &sampleformat, &data, &numberofsamples, &samplerate, &loop);
392
436
#endif
393
437
                                        /* put it in the buffer */
394
438
                                        alBufferData(m_buffers[buffer], sampleformat, data, numberofsamples, samplerate);
570
614
 
571
615
        alSourcefv(m_sources[id], AL_POSITION, obpos);
572
616
        alSourcefv(m_sources[id], AL_VELOCITY, obvel);
573
 
        
 
617
 
574
618
        alSourcef(m_sources[id], AL_GAIN, 1.0);
575
619
        alSourcef(m_sources[id], AL_PITCH, 1.0);
576
620
        alSourcei(m_sources[id], AL_LOOPING, AL_FALSE);