~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/core/pcm_timer.c

Version: ~ [ linux-6.2-rc3 ] ~ [ linux-6.1.5 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.87 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.162 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.228 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.269 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.302 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  Digital Audio (PCM) abstract layer
  3  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4  *
  5  *
  6  *   This program is free software; you can redistribute it and/or modify
  7  *   it under the terms of the GNU General Public License as published by
  8  *   the Free Software Foundation; either version 2 of the License, or
  9  *   (at your option) any later version.
 10  *
 11  *   This program is distributed in the hope that it will be useful,
 12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  *   GNU General Public License for more details.
 15  *
 16  *   You should have received a copy of the GNU General Public License
 17  *   along with this program; if not, write to the Free Software
 18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 19  *
 20  */
 21 
 22 #include <linux/time.h>
 23 #include <linux/gcd.h>
 24 #include <sound/core.h>
 25 #include <sound/pcm.h>
 26 #include <sound/timer.h>
 27 
 28 /*
 29  *  Timer functions
 30  */
 31 
 32 void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream)
 33 {
 34         unsigned long rate, mult, fsize, l, post;
 35         struct snd_pcm_runtime *runtime = substream->runtime;
 36         
 37         mult = 1000000000;
 38         rate = runtime->rate;
 39         if (snd_BUG_ON(!rate))
 40                 return;
 41         l = gcd(mult, rate);
 42         mult /= l;
 43         rate /= l;
 44         fsize = runtime->period_size;
 45         if (snd_BUG_ON(!fsize))
 46                 return;
 47         l = gcd(rate, fsize);
 48         rate /= l;
 49         fsize /= l;
 50         post = 1;
 51         while ((mult * fsize) / fsize != mult) {
 52                 mult /= 2;
 53                 post *= 2;
 54         }
 55         if (rate == 0) {
 56                 snd_printk(KERN_ERR "pcm timer resolution out of range (rate = %u, period_size = %lu)\n", runtime->rate, runtime->period_size);
 57                 runtime->timer_resolution = -1;
 58                 return;
 59         }
 60         runtime->timer_resolution = (mult * fsize / rate) * post;
 61 }
 62 
 63 static unsigned long snd_pcm_timer_resolution(struct snd_timer * timer)
 64 {
 65         struct snd_pcm_substream *substream;
 66         
 67         substream = timer->private_data;
 68         return substream->runtime ? substream->runtime->timer_resolution : 0;
 69 }
 70 
 71 static int snd_pcm_timer_start(struct snd_timer * timer)
 72 {
 73         struct snd_pcm_substream *substream;
 74         
 75         substream = snd_timer_chip(timer);
 76         substream->timer_running = 1;
 77         return 0;
 78 }
 79 
 80 static int snd_pcm_timer_stop(struct snd_timer * timer)
 81 {
 82         struct snd_pcm_substream *substream;
 83         
 84         substream = snd_timer_chip(timer);
 85         substream->timer_running = 0;
 86         return 0;
 87 }
 88 
 89 static struct snd_timer_hardware snd_pcm_timer =
 90 {
 91         .flags =        SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_SLAVE,
 92         .resolution =   0,
 93         .ticks =        1,
 94         .c_resolution = snd_pcm_timer_resolution,
 95         .start =        snd_pcm_timer_start,
 96         .stop =         snd_pcm_timer_stop,
 97 };
 98 
 99 /*
100  *  Init functions
101  */
102 
103 static void snd_pcm_timer_free(struct snd_timer *timer)
104 {
105         struct snd_pcm_substream *substream = timer->private_data;
106         substream->timer = NULL;
107 }
108 
109 void snd_pcm_timer_init(struct snd_pcm_substream *substream)
110 {
111         struct snd_timer_id tid;
112         struct snd_timer *timer;
113         
114         tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
115         tid.dev_class = SNDRV_TIMER_CLASS_PCM;
116         tid.card = substream->pcm->card->number;
117         tid.device = substream->pcm->device;
118         tid.subdevice = (substream->number << 1) | (substream->stream & 1);
119         if (snd_timer_new(substream->pcm->card, "PCM", &tid, &timer) < 0)
120                 return;
121         sprintf(timer->name, "PCM %s %i-%i-%i",
122                         substream->stream == SNDRV_PCM_STREAM_CAPTURE ?
123                                 "capture" : "playback",
124                         tid.card, tid.device, tid.subdevice);
125         timer->hw = snd_pcm_timer;
126         if (snd_device_register(timer->card, timer) < 0) {
127                 snd_device_free(timer->card, timer);
128                 return;
129         }
130         timer->private_data = substream;
131         timer->private_free = snd_pcm_timer_free;
132         substream->timer = timer;
133 }
134 
135 void snd_pcm_timer_done(struct snd_pcm_substream *substream)
136 {
137         if (substream->timer) {
138                 snd_device_free(substream->pcm->card, substream->timer);
139                 substream->timer = NULL;
140         }
141 }
142 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp