~ubuntu-branches/ubuntu/natty/libsdl1.2/natty

« back to all changes in this revision

Viewing changes to src/audio/SDL_audio.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-12-05 20:29:43 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071205202943-ryogi07hodn5cdif
Tags: 1.2.12-1ubuntu1
* Merge with Debian; remaining changes:
  - Remove svgalib support.
  - Prefer libgl1-mesa-dev build-dependency over xlibmesa-gl-dev.
  - Build for lpia as for i386.
* Link using -Wl,-Bsymbolic-functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#if SDL_AUDIO_DRIVER_ALSA
47
47
        &ALSA_bootstrap,
48
48
#endif
 
49
#if SDL_AUDIO_DRIVER_PULSE
 
50
        &PULSE_bootstrap,
 
51
#endif
49
52
#if SDL_AUDIO_DRIVER_QNXNTO
50
53
        &QNXNTOAUDIO_bootstrap,
51
54
#endif
82
85
#if SDL_AUDIO_DRIVER_SNDMGR
83
86
        &SNDMGR_bootstrap,
84
87
#endif
85
 
#if SDL_AUDIO_DRIVER_AHI
86
 
        &AHI_bootstrap,
87
 
#endif
88
88
#if SDL_AUDIO_DRIVER_MINT
89
89
        &MINTAUDIO_GSXB_bootstrap,
90
90
        &MINTAUDIO_MCSN_bootstrap,
101
101
#if SDL_AUDIO_DRIVER_DC
102
102
        &DCAUD_bootstrap,
103
103
#endif
 
104
#if SDL_AUDIO_DRIVER_NDS
 
105
        &NDSAUD_bootstrap,
 
106
#endif
104
107
#if SDL_AUDIO_DRIVER_MMEAUDIO
105
108
        &MMEAUDIO_bootstrap,
106
109
#endif
107
110
#if SDL_AUDIO_DRIVER_DART
108
111
        &DART_bootstrap,
109
112
#endif
 
113
#if SDL_AUDIO_DRIVER_EPOCAUDIO
 
114
        &EPOCAudio_bootstrap,
 
115
#endif
110
116
        NULL
111
117
};
112
118
SDL_AudioDevice *current_audio = NULL;
115
121
int SDL_AudioInit(const char *driver_name);
116
122
void SDL_AudioQuit(void);
117
123
 
118
 
#if SDL_AUDIO_DRIVER_AHI
119
 
static int audio_configured = 0;
120
 
#endif
121
 
 
122
124
/* The general mixing thread function */
123
125
int SDLCALL SDL_RunAudio(void *audiop)
124
126
{
128
130
        void  *udata;
129
131
        void (SDLCALL *fill)(void *userdata,Uint8 *stream, int len);
130
132
        int    silence;
131
 
#if SDL_AUDIO_DRIVER_AHI
132
 
        int started = 0;
133
 
 
134
 
/* AmigaOS NEEDS that the audio driver is opened in the thread that uses it! */
135
 
 
136
 
        D(bug("Task audio started audio struct:<%lx>...\n",audiop));
137
 
 
138
 
        D(bug("Before Openaudio..."));
139
 
        if(audio->OpenAudio(audio, &audio->spec)==-1)
140
 
        {
141
 
                D(bug("Open audio failed...\n"));
142
 
                return(-1);
143
 
        }
144
 
        D(bug("OpenAudio...OK\n"));
145
 
#endif
146
133
 
147
134
        /* Perform any thread setup */
148
135
        if ( audio->ThreadInit ) {
154
141
        fill  = audio->spec.callback;
155
142
        udata = audio->spec.userdata;
156
143
 
157
 
#if SDL_AUDIO_DRIVER_AHI
158
 
        audio_configured = 1;
159
 
 
160
 
        D(bug("Audio configured... Checking for conversion\n"));
161
 
        SDL_mutexP(audio->mixer_lock);
162
 
        D(bug("Semaphore obtained...\n"));
163
 
#endif
164
 
 
165
144
        if ( audio->convert.needed ) {
166
145
                if ( audio->convert.src_format == AUDIO_U8 ) {
167
146
                        silence = 0x80;
174
153
                stream_len = audio->spec.size;
175
154
        }
176
155
 
177
 
#if SDL_AUDIO_DRIVER_AHI
178
 
        SDL_mutexV(audio->mixer_lock);
179
 
        D(bug("Entering audio loop...\n"));
180
 
#endif
181
 
 
182
156
#ifdef __OS2__
183
157
        /* Increase the priority of this thread to make sure that
184
158
           the audio will be continuous all the time! */
216
190
                                stream = audio->fake_stream;
217
191
                        }
218
192
                }
 
193
 
219
194
                SDL_memset(stream, silence, stream_len);
220
195
 
221
196
                if ( ! audio->paused ) {
253
228
                audio->WaitDone(audio);
254
229
        }
255
230
 
256
 
#if SDL_AUDIO_DRIVER_AHI
257
 
        D(bug("WaitAudio...Done\n"));
258
 
 
259
 
        audio->CloseAudio(audio);
260
 
 
261
 
        D(bug("CloseAudio..Done, subtask exiting...\n"));
262
 
        audio_configured = 0;
263
 
#endif
264
231
#ifdef __OS2__
265
232
#ifdef DEBUG_BUILD
266
233
        printf("[SDL_RunAudio] : Task exiting. (TID%d)\n", SDL_ThreadID());
350
317
                   This probably isn't the place to do this, but... Shh! :)
351
318
                 */
352
319
                for ( i=0; bootstrap[i]; ++i ) {
353
 
                        if ( SDL_strcmp(bootstrap[i]->name, "esd") == 0 ) {
 
320
                        if ( SDL_strcasecmp(bootstrap[i]->name, "esd") == 0 ) {
354
321
#ifdef HAVE_PUTENV
355
322
                                const char *esd_no_spawn;
356
323
 
381
348
                        }
382
349
#endif
383
350
                        for ( i=0; bootstrap[i]; ++i ) {
384
 
                                if (SDL_strncmp(bootstrap[i]->name, driver_name,
385
 
                                            SDL_strlen(bootstrap[i]->name)) == 0) {
 
351
                                if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) {
386
352
                                        if ( bootstrap[i]->available() ) {
387
353
                                                audio=bootstrap[i]->create(idx);
388
354
                                                break;
471
437
        if ( desired->channels == 0 ) {
472
438
                env = SDL_getenv("SDL_AUDIO_CHANNELS");
473
439
                if ( env ) {
474
 
                        desired->channels = SDL_atoi(env);
 
440
                        desired->channels = (Uint8)SDL_atoi(env);
475
441
                }
476
442
        }
477
443
        if ( desired->channels == 0 ) {
491
457
        if ( desired->samples == 0 ) {
492
458
                env = SDL_getenv("SDL_AUDIO_SAMPLES");
493
459
                if ( env ) {
494
 
                        desired->samples = SDL_atoi(env);
 
460
                        desired->samples = (Uint16)SDL_atoi(env);
495
461
                }
496
462
        }
497
463
        if ( desired->samples == 0 ) {
508
474
                return(-1);
509
475
        }
510
476
 
511
 
#if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED)
512
 
        /* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */
513
 
#else
514
 
#if defined(__MINT__) && SDL_THREADS_DISABLED
 
477
#if SDL_THREADS_DISABLED
515
478
        /* Uses interrupt driven audio, without thread */
516
479
#else
517
480
        /* Create a semaphore for locking the sound buffers */
521
484
                SDL_CloseAudio();
522
485
                return(-1);
523
486
        }
524
 
#endif /* __MINT__ */
525
 
#endif /* __MACOS__ */
 
487
#endif /* SDL_THREADS_DISABLED */
526
488
 
527
489
        /* Calculate the silence and size of the audio specification */
528
490
        SDL_CalculateAudioSpec(desired);
533
495
        audio->enabled = 1;
534
496
        audio->paused  = 1;
535
497
 
536
 
#if !SDL_AUDIO_DRIVER_AHI
537
 
 
538
 
/* AmigaOS opens audio inside the main loop */
539
498
        audio->opened = audio->OpenAudio(audio, &audio->spec)+1;
540
499
 
541
500
        if ( ! audio->opened ) {
542
501
                SDL_CloseAudio();
543
502
                return(-1);
544
503
        }
545
 
#else
546
 
        D(bug("Locking semaphore..."));
547
 
        SDL_mutexP(audio->mixer_lock);
548
 
 
549
 
 
550
 
        audio->thread = SDL_CreateThread(SDL_RunAudio, audio);
551
 
        D(bug("Created thread...\n"));
552
 
 
553
 
        if ( audio->thread == NULL ) {
554
 
                SDL_mutexV(audio->mixer_lock);
555
 
                SDL_CloseAudio();
556
 
                SDL_SetError("Couldn't create audio thread");
557
 
                return(-1);
558
 
        }
559
 
 
560
 
        while(!audio_configured)
561
 
                SDL_Delay(100);
562
 
#endif
563
504
 
564
505
        /* If the audio driver changes the buffer size, accept it */
565
506
        if ( audio->spec.samples != desired->samples ) {
591
532
                        return(-1);
592
533
                }
593
534
                if ( audio->convert.needed ) {
594
 
                        audio->convert.len = desired->size;
 
535
                        audio->convert.len = (int) ( ((double) desired->size) /
 
536
                                          audio->convert.len_ratio );
595
537
                        audio->convert.buf =(Uint8 *)SDL_AllocAudioMem(
596
538
                           audio->convert.len*audio->convert.len_mult);
597
539
                        if ( audio->convert.buf == NULL ) {
602
544
                }
603
545
        }
604
546
 
605
 
#if !SDL_AUDIO_DRIVER_AHI
606
547
        /* Start the audio thread if necessary */
607
548
        switch (audio->opened) {
608
549
                case  1:
609
550
                        /* Start the audio thread */
610
 
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
 
551
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__)
611
552
#undef SDL_CreateThread
612
553
                        audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL);
613
554
#else
624
565
                        /* The audio is now playing */
625
566
                        break;
626
567
        }
627
 
#else
628
 
        SDL_mutexV(audio->mixer_lock);
629
 
        D(bug("SDL_OpenAudio USCITA...\n"));
630
 
 
631
 
#endif
632
568
 
633
569
        return(0);
634
570
}
702
638
                        SDL_FreeAudioMem(audio->convert.buf);
703
639
 
704
640
                }
705
 
#if !SDL_AUDIO_DRIVER_AHI
706
641
                if ( audio->opened ) {
707
642
                        audio->CloseAudio(audio);
708
643
                        audio->opened = 0;
709
644
                }
710
 
#endif
711
645
                /* Free the driver data */
712
646
                audio->free(audio);
713
647
                current_audio = NULL;