日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux ALSA音频系统:soundcard

發布時間:2024/3/7 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux ALSA音频系统:soundcard 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

8.1聲卡和PCM設備的建立過程

 前面分析了codec,platform,machine驅動的組成部分及其注冊過程,這三者都是物理設備相關的。

???  pcm邏輯設備,我們習慣稱之為PCM中間層或pcm native,起著承上啟下的作用:往上是與用戶態接口的交互,實現音頻數據在用戶和內核態之間的拷貝;往下是觸發codec,platform,machine的操作函數,實現音頻數據在dma_buffer<->cpu_dai<->codec之間的傳輸。

  聲卡驅動中,一般掛載著多個邏輯設備,看看我們計算機的聲卡驅動有幾個邏輯設備:

$ cat /proc/asound/devices 2: [ 0] : control3: [ 0- 0]: digital audio playback4: [ 0- 0]: digital audio capture5: [ 0- 3]: digital audio playback6: [ 0- 7]: digital audio playback7: [ 0- 8]: digital audio playback8: [ 0- 0]: hardware dependent9: [ 0- 3]: hardware dependent33: : timer

?

DeviceDescription
digital audio playback用于回放的 PCM 設備
digital audio capture用于錄制的 PCM 設備
control用于聲卡控制的 CTL 設備,如通路控制、音量調整等
timer定時器設備
sequencer音序器設備

嵌入式系統中,我們更關心PCM和CTL這兩種設備。

$ ll /dev/snd/ total 0 drwxr-xr-x 2 root root 60 7月 14 22:19 by-path crw-rw----+ 1 root audio 116, 2 7月 14 22:19 controlC0 crw-rw----+ 1 root audio 116, 8 7月 14 22:19 hwC0D0 crw-rw----+ 1 root audio 116, 9 7月 14 22:19 hwC0D3 crw-rw----+ 1 root audio 116, 4 7月 15 13:43 pcmC0D0c crw-rw----+ 1 root audio 116, 3 7月 15 15:35 pcmC0D0p crw-rw----+ 1 root audio 116, 5 7月 14 22:20 pcmC0D3p crw-rw----+ 1 root audio 116, 6 7月 14 22:20 pcmC0D7p crw-rw----+ 1 root audio 116, 7 7月 14 22:20 pcmC0D8p crw-rw----+ 1 root audio 116, 1 7月 14 22:19 seq crw-rw----+ 1 root audio 116, 33 7月 14 22:19 timer

可以看到這些設備節點的Major=116,Minor則與/proc/asound/devices所列的對應起來,都是字符設備。上層可以通過open/close/read/write/ioctl等系統調用來操作聲卡設備,這和其他字符設備類似,但一般情況下我們會使用已封裝好的用戶接口庫如alsa-lib。

8.2聲卡結構概述

  回顧下ASoC是如何注冊聲卡的,這里僅簡單陳述下:

  • Machine驅動初始化時,.name = "soc-audio"的platform_device與platform_driver匹配成功,觸發soc_probe()調用;
  • 繼而調用snd_soc_register_card():??
  • 為每個音頻物理鏈路找到對應的codec,codec_dai,cpu_dai,platform設備實例,完成dai_link的綁定;
  • 調用snd_card_create()創建聲卡;
  • 依次回調cpu_dai,codec,platform的probe()函數,完成物理設備的初始化;
    • 隨后調用soc_new_pcm():
  • 設置pcm native中要使用的pcm操作函數,這些函數用于驅動音頻物理設備,包括machine,codec_dai,cpu_dai,platform;
  • 調用snd_pcm_new()創建pcm邏輯設備,回放子流和錄制子流都在這里創建;
  • 回調platform驅動的pcm_new(),完成音頻dma設備初始化和dma buffer內存分配;
    • 最后調用snd_card_register()注冊聲卡。

    下面詳細分析聲卡和PCM邏輯設備的注冊過程。

    上面提到聲卡驅動上掛著多個邏輯子設備,有pcm音頻數據流,control混音器,midi,timer定時器,sequencer音序器等。

    ?

    +-----------+| snd_card |+-----------+| | |+-----------+ | +------------+| | | +-----------+ +-----------+ +-----------+| snd_pcm | |snd_control| | snd_timer | ...+-----------+ +-----------+ +-----------+

    這些與聲音相關的邏輯設備都在結構體snd_card管理之下,可以說snd_card是alsa中最頂層的結構。我們在看看alsa聲卡驅動的大致結構圖。

    ?

         

    snd_cards:記錄著所注冊的聲卡實例,每個聲卡實例有著各自的邏輯設備,如PCM設備,CTL設備,MIDI設備等,并一一記錄到snd_card的device鏈表上

    snd_minors:記錄著所有邏輯設備的上下文信息,它是聲卡邏輯設備與系統調用api之間的橋梁;每個snd_minor在邏輯設備注冊時被填充,在邏輯設備使用時就可以從該結構中的到相應的信息(主要是系統調用函數集file_operations)

    8.3聲卡的創建

    聲卡實例通過函數snd_card_new()來創建,其函數原型:

    /*** snd_card_new - create and initialize a soundcard structure* @parent: the parent device object* @idx: card index (address) [0 ... (SNDRV_CARDS-1)]* @xid: card identification (ASCII string)* @module: top level module for locking* @extra_size: allocate this extra size after the main soundcard structure* @card_ret: the pointer to store the created card instance** Creates and initializes a soundcard structure.** The function allocates snd_card instance via kzalloc with the given* space for the driver to use freely. The allocated struct is stored* in the given card_ret pointer.** Return: Zero if successful or a negative error code.*/int snd_card_new(struct device *parent, int idx, const char *xid, struct module *module, int extra_size,struct snd_card **card_ret)

    主要參數說明:

    • parent: 父設備對象
    • idx:聲卡的編號,如為-1,則由系統自動分配
    • xid:聲卡標識符,如為NULL,則以snd_card的shortname或longname代替
    • card_ret:返回所創建的聲卡實例的指針

    如下是我ubuntu16.04的聲卡信息:

    $ cat /proc/asound/cards0 [PCH ]: HDA-Intel - HDA Intel PCHHDA Intel PCH at 0xf2530000 irq 31
    • number:? 0
    • id: PCH
    • shortname: HDA Intel PCH
    • longname:HDA Intel PCH at 0xf7c30000 irq 47

    shortname,longname常用于打印信息,上面的聲卡信息是通過如下函數打印出來的:

    static void snd_card_info_read(struct snd_info_entry *entry,struct snd_info_buffer *buffer){int idx, count;struct snd_card *card;for (idx = count = 0; idx < SNDRV_CARDS; idx++) {mutex_lock(&snd_card_mutex);if ((card = snd_cards[idx]) != NULL) {count++;snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n",idx,card->id,card->driver,card->shortname);snd_iprintf(buffer, " %s\n",card->longname);}mutex_unlock(&snd_card_mutex);}if (!count)snd_iprintf(buffer, "--- no soundcards ---\n");}

    8.4邏輯設備的創建

    當聲卡實例建立后,接著可以創建聲卡下面的各個邏輯設備看。每個邏輯設備創建式,都會調用snd_device_new()生成一個snd_device實例,并把該實例掛到聲卡snd_card的devices鏈表上。alsa驅動為各種邏輯設備提供了創建接口,如下:

    DeviceInterface
    PCMsnd_pcm_new()
    CONTROLsnd_ctl_create()
    MIDIsnd_rawmidi_new()
    TIMERsnd_timer_new()
    SEQUENCERsnd_seq_device_new()
    JACKsnd_jack_new()

    這些接口的一般過程如下:

    int snd_xxx_new() {//這些接口提供邏輯設備注冊時回調static struct snd_device_ops ops = {.dev_free = snd_xxx_dev_free,.dev_register = snd_xxx_dev_register,.dev_disconnect = snd_xxx_dev_disconnect,};//邏輯設備實例初始化//新建一個設備實例snd_device,掛到snd_card的devices鏈表上,把該邏輯設備納入聲卡的管理當中,SNDRV_DEV_XXX是邏輯設備的類型snd_device_new(card, SNDRV_DEV_XXX, xxx, &ops); }

    其中snd_device_ops是聲卡邏輯設備的注冊函數集,dev_register()回調尤其重要,它在聲卡注冊時被調用,用于建立系統的設備節點,/dev/snd/目錄的設備節點都是在這里創建的,通過這些設備節點可系統調用open/release/read/write/ioctl..訪問操作該邏輯設備。

    snd_ctl_dev_register():

    static const struct file_operations snd_ctl_f_ops ={ .owner = THIS_MODULE,.read = snd_ctl_read,.open = snd_ctl_open,.release = snd_ctl_release,.llseek = no_llseek,.poll = snd_ctl_poll,.unlocked_ioctl = snd_ctl_ioctl,.compat_ioctl = snd_ctl_ioctl_compat,.fasync = snd_ctl_fasync,};/** registration of the control device*/static int snd_ctl_dev_register(struct snd_device *device){struct snd_card *card = device->device_data;return snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1,&snd_ctl_f_ops, card, &card->ctl_dev);} /*** snd_register_device - Register the ALSA device file for the card* @type: the device type, SNDRV_DEVICE_TYPE_XXX * @card: the card instance* @dev: the device index* @f_ops: the file operations* @private_data: user pointer for f_ops->open()* @device: the device to register** Registers an ALSA device file for the given card.* The operators have to be set in reg parameter.** Return: Zero if successful, or a negative error code on failure.*/int snd_register_device(int type, struct snd_card *card, int dev,const struct file_operations *f_ops,void *private_data, struct device *device){int minor;int err = 0;struct snd_minor *preg; if (snd_BUG_ON(!device))return -EINVAL; preg = kmalloc(sizeof *preg, GFP_KERNEL);if (preg == NULL)return -ENOMEM;preg->type = type;preg->card = card ? card->number : -1;preg->device = dev;preg->f_ops = f_ops;preg->private_data = private_data;preg->card_ptr = card;mutex_lock(&sound_mutex);minor = snd_find_free_minor(type, card, dev);if (minor < 0) {err = minor;goto error;}preg->dev = device;device->devt = MKDEV(major, minor);err = device_add(device);if (err < 0)goto error;snd_minors[minor] = preg;error:mutex_unlock(&sound_mutex);if (err < 0)kfree(preg);return err;}

    從snd_ctl_dev_register函數中可以看到:

    • 分配并初始化一個snd_minor實例,
    • 分配設備節點
    • 保存snd_minor實例到snd_minors數組中
    1016 /**1017 * device_add - add device to device hierarchy. 1018 * @dev: device.1019 *1020 * This is part 2 of device_register(), though may be called1021 * separately _iff_ device_initialize() has been called separately.1022 *1023 * This adds @dev to the kobject hierarchy via kobject_add(), adds it1024 * to the global and sibling lists for the device, then1025 * adds it to the other relevant subsystems of the driver model.1026 *1027 * Do not call this routine or device_register() more than once for1028 * any device structure. The driver model core is not designed to work1029 * with devices that get unregistered and then spring back to life.1030 * (Among other things, it's very hard to guarantee that all references1031 * to the previous incarnation of @dev have been dropped.) Allocate1032 * and register a fresh new struct device instead.1033 *1034 * NOTE: _Never_ directly free @dev after calling this function, even1035 * if it returned an error! Always use put_device() to give up your1036 * reference instead.1037 */1038 int device_add(struct device *dev)1039 {1040 struct device *parent = NULL;1041 struct kobject *kobj;1042 struct class_interface *class_intf;1043 int error = -EINVAL;1044 struct kobject *glue_dir = NULL;1045 1046 dev = get_device(dev);1047 if (!dev)1048 goto done; 1050 if (!dev->p) {1051 error = device_private_init(dev);1052 if (error)1053 goto done;1054 }1055 1056 /*1057 * for statically allocated devices, which should all be converted1058 * some day, we need to initialize the name. We prevent reading back1059 * the name, and force the use of dev_name()1060 */1061 if (dev->init_name) {1062 dev_set_name(dev, "%s", dev->init_name);1063 dev->init_name = NULL;1064 }1065 1066 /* subsystems can specify simple device enumeration */1067 if (!dev_name(dev) && dev->bus && dev->bus->dev_name)1068 dev_set_name(dev, "%s%u", dev->bus->dev_name, dev->id);1069 1070 if (!dev_name(dev)) {1071 error = -EINVAL;1072 goto name_error;1073 }1074 1075 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);1076 1077 parent = get_device(dev->parent);1078 kobj = get_device_parent(dev, parent);1079 if (kobj)1080 dev->kobj.parent = kobj; 1081 1082 /* use parent numa_node */1083 if (parent && (dev_to_node(dev) == NUMA_NO_NODE))1084 set_dev_node(dev, dev_to_node(parent));1085 1086 /* first, register with generic layer. */1087 /* we require the name to be set before, and pass NULL */1088 error = kobject_add(&dev->kobj, dev->kobj.parent, NULL);1089 if (error) {1090 glue_dir = get_glue_dir(dev);1091 goto Error;1092 }1093 1094 /* notify platform of device entry */1095 if (platform_notify)1096 platform_notify(dev);1097 1098 error = device_create_file(dev, &dev_attr_uevent);1099 if (error)1100 goto attrError;1101 1102 error = device_add_class_symlinks(dev);1103 if (error)1104 goto SymlinkError;1105 error = device_add_attrs(dev);1106 if (error)1107 goto AttrsError;1108 error = bus_add_device(dev);1109 if (error)1110 goto BusError;1111 error = dpm_sysfs_add(dev);1112 if (error)goto DPMError;device_pm_add(dev); if (MAJOR(dev->devt)) {error = device_create_file(dev, &dev_attr_dev);if (error)goto DevAttrError;error = device_create_sys_dev_entry(dev);if (error)goto SysEntryError;devtmpfs_create_node(dev);}/* Notify clients of device addition. This call must come* after dpm_sysfs_add() and before kobject_uevent().*/if (dev->bus)blocking_notifier_call_chain(&dev->bus->p->bus_notifier,BUS_NOTIFY_ADD_DEVICE, dev); kobject_uevent(&dev->kobj, KOBJ_ADD);bus_probe_device(dev); if (parent)klist_add_tail(&dev->p->knode_parent,&parent->p->klist_children);if (dev->class) {mutex_lock(&dev->class->p->mutex);/* tie the class to the device */klist_add_tail(&dev->knode_class,&dev->class->p->klist_devices);/* notify any interfaces that the device is here */list_for_each_entry(class_intf,&dev->class->p->interfaces, node)if (class_intf->add_dev)class_intf->add_dev(dev, class_intf);mutex_unlock(&dev->class->p->mutex);}done:put_device(dev);return error;SysEntryError:if (MAJOR(dev->devt))device_remove_file(dev, &dev_attr_dev);DevAttrError:device_pm_remove(dev);dpm_sysfs_remove(dev);DPMError:bus_remove_device(dev);BusError:device_remove_attrs(dev);AttrsError:device_remove_class_symlinks(dev);SymlinkError:device_remove_file(dev, &dev_attr_uevent);attrError:kobject_uevent(&dev->kobj, KOBJ_REMOVE);glue_dir = get_glue_dir(dev);kobject_del(&dev->kobj);Error:cleanup_glue_dir(dev, glue_dir);put_device(parent);name_error:kfree(dev->p);dev->p = NULL;goto done;}

    上面過程是聲卡注冊時才被回調的。

    8.5聲卡的注冊

    當聲卡下的所有邏輯設備都已經準備就緒后,就可以調用snd_card_register()注冊聲卡了:

    • 創建聲卡的sysfs設備;
    • 調用snd_device_register_all()注冊所有掛在該聲卡下的邏輯設備;
    • 建立proc信息文件和sysfs屬性文件。
    724 /**725 * snd_card_register - register the soundcard726 * @card: soundcard structure727 *728 * This function registers all the devices assigned to the soundcard.729 * Until calling this, the ALSA control interface is blocked from the730 * external accesses. Thus, you should call this function at the end731 * of the initialization of the card.732 *733 * Return: Zero otherwise a negative error code if the registration failed.734 */735 int snd_card_register(struct snd_card *card)736 {737 int err;738 739 if (snd_BUG_ON(!card))740 return -EINVAL;741    //創建sysfs設備,聲卡的class將會出現在/sys/class/sound下面742 if (!card->registered) {743 err = device_add(&card->card_dev);744 if (err < 0)745 return err;746 card->registered = true;747 }748 //遍歷掛在該聲卡的所有邏輯設備,回調各snd_device的ops->dev_register()完成各邏輯設備的注冊749 if ((err = snd_device_register_all(card)) < 0)750 return err;751 mutex_lock(&snd_card_mutex);752 if (snd_cards[card->number]) {753 /* already registered */754 mutex_unlock(&snd_card_mutex);755 return snd_info_card_register(card); /* register pending info */756 }757 if (*card->id) {758 /* make a unique id name from the given string */759 char tmpid[sizeof(card->id)];760 memcpy(tmpid, card->id, sizeof(card->id));761 snd_card_set_id_no_lock(card, tmpid, tmpid);762 } else {763 /* create an id from either shortname or longname */764 const char *src;765 src = *card->shortname ? card->shortname : card->longname;766 snd_card_set_id_no_lock(card, src,767 retrieve_id_from_card_name(src)); 768 }769 snd_cards[card->number] = card;//把該聲卡實例保存到snd_cards數組中770 mutex_unlock(&snd_card_mutex);//聲卡相關信息,見:/proc/asound/card0771 init_info_for_card(card);772 #if IS_ENABLED(CONFIG_SND_MIXER_OSS)773 if (snd_mixer_oss_notify_callback)774 snd_mixer_oss_notify_callback(card, SND_MIXER_OSS_NOTIFY_REGISTER);775 #endif776 return 0;777 }

    至此完成了聲卡及聲卡下的所有邏輯設備的注冊,用戶態可以通過系統調用來訪問這些設備。

    8.6PCM設備的創建

    ?

    snd_pcm_set_ops:設置PCM設備的操作接口,設置完成后,在PCM設備層即可訪問操作底層音頻物理設備。

    snd_pcm_new:

    • 創建一個PCM設備實例snd_pcm;
    • 創建playback stream和capture stream,旗下的substream也同時建立;
    • 調用snd_device_new()把pcm設備掛到聲卡的devices鏈表上。
    /**800 * snd_pcm_new - create a new PCM instance801 * @card: the card instance802 * @id: the id string803 * @device: the device index (zero based)804 * @playback_count: the number of substreams for playback805 * @capture_count: the number of substreams for capture806 * @rpcm: the pointer to store the new pcm instance807 *808 * Creates a new PCM instance.809 *810 * The pcm operators have to be set afterwards to the new instance811 * via snd_pcm_set_ops().812 *813 * Return: Zero if successful, or a negative error code on failure.814 */815 int snd_pcm_new(struct snd_card *card, const char *id, int device,816 int playback_count, int capture_count, struct snd_pcm **rpcm)817 {818 return _snd_pcm_new(card, id, device, playback_count, capture_count,819 false, rpcm);820 } 755 static int _snd_pcm_new(struct snd_card *card, const char *id, int device,756 int playback_count, int capture_count, bool internal,757 struct snd_pcm **rpcm)758 {759 struct snd_pcm *pcm;760 int err;761 static struct snd_device_ops ops = {762 .dev_free = snd_pcm_dev_free,763 .dev_register = snd_pcm_dev_register,764 .dev_disconnect = snd_pcm_dev_disconnect,765 };766 767 if (snd_BUG_ON(!card))768 return -ENXIO;769 if (rpcm)770 *rpcm = NULL;771 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);772 if (!pcm)773 return -ENOMEM;774 pcm->card = card;775 pcm->device = device;776 pcm->internal = internal;777 mutex_init(&pcm->open_mutex);778 init_waitqueue_head(&pcm->open_wait);779 INIT_LIST_HEAD(&pcm->list);780 if (id)781 strlcpy(pcm->id, id, sizeof(pcm->id));782 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {783 snd_pcm_free(pcm);784 return err;785 }786 if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) {787 snd_pcm_free(pcm);788 return err;789 }790 if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {791 snd_pcm_free(pcm);792 return err;793 }794 if (rpcm)795 *rpcm = pcm;796 return 0; 797 }

    在看看pcm設備的系統調用:

    const struct file_operations snd_pcm_f_ops[2] = {3681 {3682 .owner = THIS_MODULE,3683 .write = snd_pcm_write,3684 .write_iter = snd_pcm_writev,3685 .open = snd_pcm_playback_open,3686 .release = snd_pcm_release,3687 .llseek = no_llseek,3688 .poll = snd_pcm_playback_poll,3689 .unlocked_ioctl = snd_pcm_playback_ioctl,3690 .compat_ioctl = snd_pcm_ioctl_compat,3691 .mmap = snd_pcm_mmap,3692 .fasync = snd_pcm_fasync,3693 .get_unmapped_area = snd_pcm_get_unmapped_area,3694 },3695 {3696 .owner = THIS_MODULE,3697 .read = snd_pcm_read,3698 .read_iter = snd_pcm_readv,3699 .open = snd_pcm_capture_open,3700 .release = snd_pcm_release,3701 .llseek = no_llseek,3702 .poll = snd_pcm_capture_poll,3703 .unlocked_ioctl = snd_pcm_capture_ioctl,3704 .compat_ioctl = snd_pcm_ioctl_compat,3705 .mmap = snd_pcm_mmap,3706 .fasync = snd_pcm_fasync,3707 .get_unmapped_area = snd_pcm_get_unmapped_area,3708 }3709 };

    snd_pcm_f_ops作為snd_register_device_for_dev()的參數傳入,并被記錄在snd_minors[minor]中的字段f_ops中。snd_pcm_f_ops[0]是回放使用的系統調用接口,snd_pcm_f_ops[1]是錄制使用的系統調用接口。

    9.Frame && Period

    音頻數據中的幾個重要概念:

    • Sample:樣本長度,音頻數據最基本的單位,常見的有8bit和16bit;
    • channel:聲道數,分為單聲道mono和立體聲stereo;
    • Frame:幀,構成一個完整的聲音單元,所謂的聲音單元是?一個采樣樣本, Frame = Sample * channel;
    • Rate:又稱sample rate,采樣率,即毎秒的采樣次數,針對幀而言;
    • Period Size:周期,每次硬件中斷處理音頻數據的幀數,對于音頻設備的數據讀寫,以此為單位;
    • Buffer Size:數據緩沖區大小,這里這指runtime的buffer size,而不是結構圖snd_pcm_hardware中定義的buffer_bytes_max;一般來說buffer_size = period_size * period_count,period_count相當于處理完一個buffer數據所需的硬件中斷次數。

    下面是一章直觀的表示buffer/period/frame/sample之間的關系:

    這個buffer中有4個period,每當DMA搬運完一個period的數據就會出生一次中斷,因此搬運這個buffer中的數據將產生4次中斷。

    ALSA為什么這樣做?因為數據緩沖區可能很大,一次傳輸可能會導致不可接收的延遲;為了解決這個問題,alsa把緩沖區拆分成多個周期,以周期為單元傳輸數據。

    9.1frames&periods

    alsa官網對periods的解釋:https://www.alsa-project.org/main/index.php/FramesPeriods

    • Frame:幀,構成一個完整的聲音單元,它的大小等于sample_bits * channels;
    • Period:周期大小,即每次dma運輸處理音頻數據的幀數,如果周期大小設定的較大,則單次處理的數據較多,這意味著單位時間內硬件中斷的次數較少,CPU也就有更多時間處理其他任務,功耗也更低,但這樣帶來一個顯著的弊端-數據處理的時延會增大。
    • period bytes,對于dma處理來說,它直接關心的是數據大小,而非period_size(一個周期的幀數),有個轉換關系:period_bytes =period_size * sample_bits * channels / 8

    由于i2s總線采樣率是穩定的,我們可以計算i2s傳輸一個周期的數據所需的時間:transfer_time = 1 * period_size /sample_rate,in second.

    例如period_size = 1024, sample_rate = 48khz,那么一個周期數據的傳輸時間是:1*1024/48000 = 21.3(ms)

    ?

    ?

    總結

    以上是生活随笔為你收集整理的Linux ALSA音频系统:soundcard的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。