~ubuntu-branches/debian/sid/bristol/sid

« back to all changes in this revision

Viewing changes to libbristolaudio/audioEngineALSA.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2011-02-15 02:54:23 UTC
  • mfrom: (13.1.6 experimental)
  • Revision ID: james.westby@ubuntu.com-20110215025423-g8hcla5gyl08mae3
Tags: 0.60.8-2
* Upload to unstable.
* Relax JACK's build-deps to let this build in sid.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
 
83
83
#include <time.h>
84
84
 
85
 
static int adInit = 1;
 
85
static int adInit = 1, dummycapture = 0;
86
86
static struct adev alsaDev[MAX_DEVICES + 1];
87
87
 
88
 
void setscheduler(audioDev)
89
 
duplexDev *audioDev;
90
 
{
91
 
#if defined(linux)
92
 
        struct sched_param sched_param;
93
 
 
94
 
        if (sched_getparam(0, &sched_param) < 0) {
95
 
                printf("Scheduler getparam failed...\n");
96
 
                return;
97
 
        }
98
 
        sched_param.sched_priority = sched_get_priority_max(SCHED_FIFO);
99
 
        if (!sched_setscheduler(0, SCHED_FIFO, &sched_param)) {
100
 
                if (audioDev->cflags & SLAB_AUDIODBG)
101
 
                        printf("Scheduler set to FIFO with priority %i...\n",
102
 
                                sched_param.sched_priority);
103
 
                return;
104
 
        }
105
 
        if (audioDev->cflags & SLAB_AUDIODBG)
106
 
                printf("!!!Scheduler set to FIFO with priority %i FAILED!!!\n",
107
 
                        sched_param.sched_priority);
108
 
#else /* of LINUX */
109
 
        printf("Cannot reschedule audio API, wrong machine type\n");
110
 
#endif
111
 
}
112
 
 
113
88
#define SND_PCM_OPEN_PLAYBACK SND_PCM_STREAM_PLAYBACK
114
89
#define SND_PCM_OPEN_CAPTURE SND_PCM_STREAM_CAPTURE
115
90
 
129
104
                        &alsaDev[audioDev->devID].phandle);
130
105
*/
131
106
 
132
 
        if (alsaDev[audioDev->devID].chandle != (snd_pcm_t *) NULL)
 
107
        if (dummycapture == 0)
133
108
        {
134
 
                if (audioDev->cflags & SLAB_AUDIODBG)
135
 
                        printf("closing alsa capture channel\n");
136
 
 
137
 
                /* snd_pcm_unlink((void *) alsaDev[audioDev->devID].chandle); */
138
 
                snd_pcm_drop((void *) alsaDev[audioDev->devID].chandle);
139
 
                snd_pcm_hw_free((void *) alsaDev[audioDev->devID].chandle);
140
 
                snd_pcm_close((void *) alsaDev[audioDev->devID].chandle);
141
 
 
142
 
                alsaDev[audioDev->devID].chandle = (snd_pcm_t *) NULL;
 
109
                if (alsaDev[audioDev->devID].chandle != (snd_pcm_t *) NULL)
 
110
                {
 
111
                        if (audioDev->cflags & SLAB_AUDIODBG)
 
112
                                printf("closing alsa capture channel\n");
 
113
 
 
114
                        /* snd_pcm_unlink((void *) alsaDev[audioDev->devID].chandle); */
 
115
                        snd_pcm_drop((void *) alsaDev[audioDev->devID].chandle);
 
116
                        snd_pcm_hw_free((void *) alsaDev[audioDev->devID].chandle);
 
117
                        snd_pcm_close((void *) alsaDev[audioDev->devID].chandle);
 
118
 
 
119
                        alsaDev[audioDev->devID].chandle = (snd_pcm_t *) NULL;
 
120
                }
143
121
        }
144
122
 
145
123
        if (alsaDev[audioDev->devID].phandle != (snd_pcm_t *) NULL)
402
380
        /*
403
381
         * And do the same for the capture channel
404
382
         */
405
 
        if (flags & SLAB_RDONLY)
 
383
        if ((flags & SLAB_RDONLY) && (strcmp(audioDev->devName, "plug:dmix") != 0))
406
384
        {
407
385
                if (audioDev->cflags & SLAB_AUDIODBG)
408
386
                        printf("open capture on %s: pre %i\n",
414
392
                                &alsaDev[audioDev->devID].c_swparams,
415
393
                                "capture") < 0)
416
394
                        return(-1);
417
 
        }
 
395
        } else
 
396
                dummycapture = 1;
418
397
 
419
398
        bristolfree(audioDev->fragBuf);
420
399
 
447
426
                snd_pcm_writei(alsaDev[audioDev->devID].phandle, audioDev->fragBuf,
448
427
                        audioDev->samplecount);
449
428
 
450
 
        snd_pcm_drop(alsaDev[audioDev->devID].chandle);
451
 
        snd_pcm_prepare(alsaDev[audioDev->devID].chandle);
 
429
        if (dummycapture == 0) {
 
430
                snd_pcm_drop(alsaDev[audioDev->devID].chandle);
 
431
                snd_pcm_prepare(alsaDev[audioDev->devID].chandle);
 
432
        }
452
433
 
453
434
        if ((err = snd_pcm_start(alsaDev[audioDev->devID].phandle)) < 0) {
454
435
                printf("Playback start error: %s\n", snd_strerror(err));
455
436
                return(-1);
456
437
        }
457
438
 
458
 
        if ((err = snd_pcm_start(alsaDev[audioDev->devID].chandle)) < 0) {
459
 
                printf("Record start error: %s\n", snd_strerror(err));
460
 
                return(-1);
 
439
        if (dummycapture == 0)
 
440
        {
 
441
                if ((err = snd_pcm_start(alsaDev[audioDev->devID].chandle)) < 0) {
 
442
                        printf("Record start error: %s\n", snd_strerror(err));
 
443
                        return(-1);
 
444
                }
461
445
        }
462
446
#else
463
447
        if ((audioDev->flags == ADIOD_OUTPUT) || (audioDev->flags == ADIOD_DUPLEX))
471
455
 
472
456
        if ((audioDev->flags == ADIOD_INPUT) || (audioDev->flags == ADIOD_DUPLEX))
473
457
        {
474
 
                printf("Start capture\n");
475
 
                if ((err = snd_pcm_start(alsaDev[audioDev->devID].chandle)) < 0) {
476
 
                        printf("Record start error: %s\n", snd_strerror(err));
477
 
                        return(-1);
 
458
                if (dummycapture == 0)
 
459
                {
 
460
                        printf("Start capture\n");
 
461
                        if ((err = snd_pcm_start(alsaDev[audioDev->devID].chandle)) < 0) {
 
462
                                printf("Record start error: %s\n", snd_strerror(err));
 
463
                                return(-1);
 
464
                        }
478
465
                }
479
466
        }
480
467
#endif
507
494
                return(count);
508
495
 
509
496
        if (audioDev->flags & SLAB_AUDIODBG2)
510
 
                printf("alsa audioRead(%i)\n", count);
 
497
                printf("audioWrite(%i)\n", count);
511
498
 
512
499
#if (BRISTOL_HAS_ALSA == 1)
513
500
        /*
514
501
         * This if for ALSA 0.9 and 1.0
515
502
         */
516
 
        if (audioDev->flags & AUDIO_ALSA)
 
503
        if (audioDev->siflags & AUDIO_ALSA)
517
504
        {
518
505
                long r;
519
506
 
535
522
        }
536
523
#endif /* BRISTOL_HAS_ALSA */
537
524
 
 
525
#ifdef BRISTOL_PA
 
526
        if (audioDev->siflags & AUDIO_PULSE)
 
527
                return(pulseDevWrite(audioDev->fd, buffer, count));
 
528
#endif
 
529
 
538
530
        /*
539
531
         * Otherwise just to a normal OSS fd write operation. Since bristol release
540
532
         * went to 1.0 started using sample counts rather than bytes, so OSS has to
553
545
        int result;
554
546
 
555
547
        if (audioDev->flags & SLAB_AUDIODBG2)
556
 
                printf("alsa audioRead(%i)\n", count);
 
548
                printf("audioRead(%i)\n", count);
557
549
 
558
550
        if (audioDev->flags & AUDIO_DUMMY)
559
551
        {
566
558
         * This if for ALSA 0.9 and 1.0
567
559
        printf("audioRead(%x, %i)\n", buffer, count);
568
560
         */
569
 
        if (audioDev->flags & AUDIO_ALSA)
 
561
        if (dummycapture)
 
562
        {
 
563
                memset(buffer, 0, audioDev->fragSize);
 
564
                return(count);
 
565
        }
 
566
        if (audioDev->siflags & AUDIO_ALSA)
570
567
                return(snd_pcm_readi(alsaDev[audioDev->devID].chandle, buffer, count));
571
568
#endif
572
569
 
 
570
#ifdef BRISTOL_PA
 
571
        if (audioDev->siflags & AUDIO_PULSE)
 
572
                return(pulseDevRead(audioDev->fd2, buffer, count));
 
573
#endif
 
574
 
573
575
        /*
574
576
         * If this is not an ALSA dev, do a normal OSS fd read operation.
575
577
         */