WO2017005010A1 - Audio processing method and device, and computer storage medium - Google Patents

Audio processing method and device, and computer storage medium Download PDF

Info

Publication number
WO2017005010A1
WO2017005010A1 PCT/CN2016/076802 CN2016076802W WO2017005010A1 WO 2017005010 A1 WO2017005010 A1 WO 2017005010A1 CN 2016076802 W CN2016076802 W CN 2016076802W WO 2017005010 A1 WO2017005010 A1 WO 2017005010A1
Authority
WO
WIPO (PCT)
Prior art keywords
buffer
mix
dma
virtual sound
sound card
Prior art date
Application number
PCT/CN2016/076802
Other languages
French (fr)
Chinese (zh)
Inventor
杨爱民
于光海
Original Assignee
深圳市中兴微电子技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市中兴微电子技术有限公司 filed Critical 深圳市中兴微电子技术有限公司
Publication of WO2017005010A1 publication Critical patent/WO2017005010A1/en

Links

Images

Classifications

    • GPHYSICS
    • G10MUSICAL INSTRUMENTS; ACOUSTICS
    • G10LSPEECH ANALYSIS TECHNIQUES OR SPEECH SYNTHESIS; SPEECH RECOGNITION; SPEECH OR VOICE PROCESSING TECHNIQUES; SPEECH OR AUDIO CODING OR DECODING
    • G10L19/00Speech or audio signals analysis-synthesis techniques for redundancy reduction, e.g. in vocoders; Coding or decoding of speech or audio signals, using source filter models or psychoacoustic analysis

Definitions

  • the present invention relates to audio technologies in the field of embedded platforms, and in particular, to an audio processing method and device, and a computer storage medium.
  • the ear-back time (the time from the input of the microphone to the time of output from the TV) is above 120 milliseconds (ms), compared to the 40-second ear-back time of the iOS system.
  • the big ear return time affects the user experience.
  • the embodiment of the invention provides an audio processing method and device, and a computer storage medium, which can reduce the ear return time of the Android device.
  • An embodiment of the present invention provides an audio processing method, where the method includes:
  • DMA direct memory read
  • the play buffer address and the recording buffer address are obtained in the soft interrupt of the mix, the mix processing function is called to perform the mixing process, and the processed mixed data is saved in the mix play buffer.
  • the method further includes:
  • the address of the mix play buffer is used to support the DMA function from the address data of the mix play buffer to the first in first out (FIFO) queue of the virtual sound card.
  • the method further includes:
  • the data of the sound mixing buffer is copied into the sound recording buffer, and the sound recording buffer is used to support the application layer to read the sound by opening the virtual sound card. After the audio data.
  • the method before the allocation of the mix play buffer and the mix recording buffer in the memory space, the method further includes:
  • the method further includes:
  • a normal recording buffer is allocated to the DMA buffer, and the normal recording buffer is used to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
  • An embodiment of the present invention provides an audio processing device, where the device includes:
  • a buffer unit configured to allocate a memory space for the DMA buffer, where the DMA buffer includes a mix play buffer and a mix recording buffer;
  • a soft interrupt declaration unit configured to declare a name of a soft interrupt that handles the mix and a corresponding processing function
  • the soft interrupt processing unit is configured to acquire the play buffer address and the recording buffer address in the soft interrupt of the mix, call the mix processing function for mixing processing, and process the data after the mixing There is the mix play buffer.
  • the device further includes:
  • a mixing playback processing unit configured to assign an address of the sound mixing buffer to a source address of a DMA function pointer
  • the address of the mix play buffer is configured to support the DMA function from the address data of the mix play buffer to the FIFO queue of the virtual sound card.
  • the device further includes:
  • a sound recording processing unit configured to copy data of the sound mixing buffer into the sound recording buffer in an interrupt callback function of the DMA function, wherein the sound recording buffer is used to support an application layer Read the mixed audio data by turning on the virtual sound card.
  • the device further includes:
  • a registration unit configured to perform the following operations before the allocation of the mix play buffer and the mix recording buffer in the buffer unit memory space; registering the virtual sound card driver and the virtual sound card; registering the platform device and the platform device driver; registering the codec Device, Codec driver and Codec DAI.
  • the buffer unit is further configured to allocate a memory space normal play buffer for the DMA buffer, and the normal play buffer is configured to support the application layer to write audio data to be played by opening the virtual sound card;
  • the buffer unit is further configured to allocate a normal recording buffer to the DMA buffer, and the normal recording buffer is configured to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
  • an embodiment of the present invention provides a computer storage medium, where the computer storage medium stores executable instructions, and the executable instructions are used to execute an audio processing method provided by an embodiment of the present invention.
  • the play buffer address and the recording buffer address are obtained through the soft interrupt of the mix, and the mix processing function is called to perform the mixing process, for example, when running on the ARM processor.
  • the mixing processing at the Linux kernel level is realized (instead of the mixing processing implemented by the related technology in the application layer), and the mixing processing result is provided to the application layer, and the application layer does not need to perform the mixing processing by itself.
  • the application layer of the related art directly performs the mixing process to greatly shorten the ear return delay.
  • FIG. 1 is a schematic flowchart of an implementation process of an audio processing method according to an embodiment of the present invention
  • FIG. 2 is a flowchart of an ASoC-based audio processing method according to an embodiment of the present invention
  • FIG. 3 is a flowchart of a call of a soc_probe function according to an embodiment of the present invention.
  • FIG. 5 is a flowchart of a snd_soc_instantiate_card function call according to an embodiment of the present invention
  • FIG. 6 is a schematic diagram of a virtual sound card being mounted under a snd_card according to an embodiment of the present invention
  • FIG. 7 is a flowchart of a tasklet mixing according to an embodiment of the present invention.
  • FIG. 8 is a first schematic structural diagram of an audio processing device according to an embodiment of the present invention.
  • FIG. 9 is a second schematic structural diagram of an audio processing device according to an embodiment of the present invention.
  • Android devices have a relatively standard and robust architecture for processing audio.
  • the architecture includes: application layer, Java framework service Audio Mananger, local service Audio Flinger, abstraction layer Alsa HAL, local library, external (external) Alsa-lib support library, The underlying coding (Codec) driver;
  • the audio processing device described in the embodiment of the present invention is an Advanced Linux Sound Architecture (ALSA) based on Android, and is based on an Android device, an Advanced RISC Machine (ARM) device, and a Linux device running on an Android device.
  • the virtual sound card is added to the device list of the kernel, and the virtual sound card directly intercepts the audio data (such as the audio data input by the user through the microphone) and the background audio data (the background sound of the song playing) for mixing processing, and the application layer can directly obtain the mixed sound. Sound data, no need to be mixed by the application layer itself, reducing the ear return time;
  • a virtual sound card device (referred to as a virtual sound card) is added to the device list of the Linux kernel, and the virtual sound card resource is registered into the Linux.
  • the kernel is managed by the Linux kernel;
  • the audio processing device provided in this embodiment is based on the ALSA architecture of the system-on-a-chip (SOC), that is, ASOC, and the ASoC runs the Linux kernel for audio processing.
  • the Linux kernel running in the ASoC is provided with a virtual sound card, a Platform, a virtual sound card Codec, and a virtual sound card Codec driver.
  • the audio data is processed by the virtual sound card at the Linux kernel level (instead of the application layer), and the Linux kernel is added with a normal play buffer, a normal recording buffer, a mix play buffer, and a mix recording buffer for different
  • the application scene stores audio data, and the two channels of data are mixed by soft interrupt when the recorded data and the play data arrive, and the application layer can directly read the mixed data.
  • the driver of the virtual sound card is set under the driver management and registration mechanism of the Linux, including: defining the platform device (platform_device) structure corresponding to the virtual sound card, registering the platform_device structure corresponding to the virtual sound card, and defining the platform driver (platform_driver) structure corresponding to the virtual sound card. Body, and the platform_driver structure of the registered virtual sound card; adding virtual sound card, Platform, virtual sound card Codec and virtual sound card Codec driver processing follows the Linux driver Management and registration mechanism;
  • the Linux kernel running on the Android device includes a bus, that is, a virtual bus or platform bus, a platform device (platform_device), and a platform driver (platform_driver); the virtual bus binds the platform device and the platform driver: registering a platform driver At the time, the virtual bus looks for platform devices that match the platform drivers.
  • Virtual sound card resource registration and mixing soft interrupt (Tasklet) processing if you want a virtual sound card to work properly, you need to complete three steps: 1, virtual sound card driver and virtual sound card registration; 2, platform equipment and platform device driver
  • the registration of the platform device mainly implements the direct memory access (DMA) function.
  • the name of the platform device driver is consistent with the name of the platform device: 3.
  • the registration of the virtual sound card driver and the virtual sound card device (referred to as the virtual sound card), the name of the virtual sound card driver must be the same as the name of the platform device:
  • the resource information of the virtual sound card is described by the platform_device structure, which includes the name (name), the identifier (ID) of the virtual sound card, the codec resource of the defined virtual sound card, and the resource of the Codec of the virtual sound card. The number of bytes occupied.
  • platform device implements DMA function, platform driver name and platform device name are the same, both are zx-audio-platform:
  • the buffer contains The normal play buffer, the normal recording buffer, the mix play buffer, and the mix recording buffer are configured to store audio data for different application scenarios;
  • the soft break (tasklet) processing function is configured to process audio data input by the user through the microphone and Mixing of background audio.
  • Step 101 Allocate a memory space for a direct memory read (DMA) buffer, where the DMA buffer includes a mix play buffer and a mix recording buffer.
  • DMA direct memory read
  • Step 102 declaring the name of the soft interrupt handling the mix and the corresponding processing function.
  • Step 103 Acquire a play buffer address and a recording buffer address in the soft interrupt of the mix, call a mix processing function to perform a mixing process, and save the processed data in the mix play buffer.
  • the address of the mix play buffer is assigned a source address of the DMA function pointer; the DMA function is based on the address of the mix play buffer, from the address of the mix play buffer Data to the virtual sound card's first in first out (FIFO) queue.
  • FIFO first in first out
  • the data of the sound mixing buffer is copied into the sound recording buffer, and the sound recording buffer is used to support the application layer. Turn on the virtual sound card to read the audio data after the mix.
  • a normal play buffer is allocated for the DMA buffer, and the normal play buffer is used to support the application layer by opening the virtual
  • the sound card writes audio data that needs to be played;
  • the normal recording buffer is allocated to the DMA buffer, and the normal recording buffer is used to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
  • the following describes an audio processing method shown in FIG. 2 for an Android device such as a set top box running the above Linux kernel, including the following steps:
  • step 201 the platform bus matches the device and driver whose names are virtual sound cards.
  • step 202 also triggers the invocation of the soc_probe function, which is the entry for the entire ASoC driver initialization.
  • platform_driver if there is platform_device, there will be platform_driver.
  • the name field in the AS_C platform_driver is soc-audio, which is exactly the same as the name in the platform_device defined in step 1.
  • the platform bus will Matching the two devices and drivers with the same name will also trigger the call to soc_probe, which is the entry point for the entire ASoC driver initialization.
  • Step 202 Call the soc_probe function.
  • the call to the soc_probe function includes the following steps:
  • step 301 the snd_soc_register_card is called in the soc_probe function to apply for memory for the snd_soc_pcm_runtime array, and each dai_link corresponds to a unit of the snd_soc_pcm_runtime array.
  • Step 302 Copy the dai_link configuration in the snd_soc_card to the corresponding snd_soc_pcm_runtime.
  • step 303 the snd_soc_instantiate_card function is called.
  • Card->rtd kzalloc(sizeof(struct snd_soc_pcm_runtime)*(card->num_links+card->num_aux_devs), GFP_KERNEL)
  • Step 203 The snd_soc_instantiate_card function call process, The snd_soc_instantiate_card function traverses each pair of dai_links, binds Codec, Platform, and DAI, and the snd_soc_instantiate_card function calls the soc_probe_dai_link function.
  • the call flow of the soc_probe_dai_link function is shown in Figure 4.
  • the soc_probe_dai_link function the Codec, DAI, and platform-driven probes are called.
  • the soc_new_pcm() function is also called at the end to create a virtual sound card.
  • step 401 card->instantiated is used to determine whether the virtual sound card has been instantiated, and if it has been instantiated, it returns directly.
  • step 402 each pair of dai_links is traversed, and the binding of codec, platform, and DAI is performed.
  • step 403 the register buffer of Codec is initialized.
  • step 404 a virtual sound card is created.
  • FIG. 6 A schematic diagram of the virtual sound card being mounted under the snd_card is shown in FIG. 6.
  • step 405 the probe function of each substructure is called in turn.
  • step 406 the soc_probe_dai_link() function is executed.
  • Step 407 initialization and setting.
  • step 408 the virtual sound card is registered by calling the sound card registration function driven by the standard ALSA.
  • Step 204 The audio data input by the user through the microphone and the audio data of the background music are processed and mixed by processing a soft break of the mix.
  • step 204 is implemented by the following steps:
  • Step 501 Define a structure of a record buffer, including a normal play buffer, a normal recording buffer, a mix play buffer, and a mix recording buffer, and store audio data for different application scenarios.
  • the code is as follows:
  • the four pointers are assigned respectively.
  • Step 502 declaring the name of the tasklet that processes the mix and the corresponding processing function, that is, DECLARE_TASKLET (zx_i2s_spdif_mix_tasklet, zx_snd_soc_mix_taskelet, 0).
  • step 503 the tasklet is initialized in the DMA interrupt callback function (only needs to be initialized once), and the tasklet_schedule is called to dispatch the tasklet.
  • Step 504 Obtain a mix play buffer address and a mix recording buffer address in the mixed tasklet, call a mix processing function to perform a mix process, and save the processed data in the mix play buffer.
  • step 505a when the mixing is played, the address of the mixing play buffer is assigned to the source address of the DMA pointer, and the DMA transfers data from the address to the first-in-first-out (FIFO) queue of the virtual sound card, thereby realizing the mixing play. .
  • FIFO first-in-first-out
  • Step 506b when the sound recording is realized, in the DMA interrupt callback function, the data of the sound mixing buffer is copied into the sound recording buffer, and the application layer can read the mixed audio data by opening the virtual sound card. Normal play.
  • the tasklet mechanism is a relatively common mechanism, usually used to reduce the interrupt processing time, which should be in the interrupt service routine.
  • the completed task is converted to a soft interrupt completion.
  • the addresses of the normal play buffer, the normal recording buffer, and the mix play buffer are recorded as parameters, and the mixing process is performed by the following mixing algorithm:
  • tasklet_init &zx_i2s_spdif_mix_tasklet, zx_snd_soc_mix_taskelet, (unsigned long) arg) of the mix is registered for the first time, and tasklet_schedule(&zx_i2s_spdif_mix_tasklet) is called;
  • the DMA interrupt callback processing function firstly assign the stream pointer of the recorded data and the playback data to the global variable pcm_substream, and then pass the two-way audio stream pointer to the tasklet of the mixing process through the global variable. Finally, in the task bar of the mixing process, the two pointers are respectively applied to the above-mentioned mixing algorithm, and after the algorithm is processed, the mixed data is obtained (the data is stored in the buffer pointed to by the mixing play pointer). If the data for DMA transfer is 1 KB, the size of the recorded data and the playback data is 1 KB each time the mix is mixed, and the data of the mix output is still 1 KB.
  • the mixed data is played and the audio data is obtained through the virtual sound card. Therefore, in the DMA interrupt processing function, the physical address pointer of the DMA at the time of playback needs to be replaced with the mixed after the mixing processing. DMA physical address pointer for audio data playback, so After the change, the originally played sound data is replaced with the data after the mixing process, and the data of the sound mixing buffer is copied to the buffer pointed to by the sound recording buffer pointer, and snd_pcm_period_elapsed is called to notify the Linux kernel. The current data has been processed.
  • the data can be read by opening the device dev/snd/pcmC0D0c.
  • the application layer wants to play the sound it can be written by opening the dev/snd/pcmC1D0p device.
  • the function of mixing the device dev/snd/pcmC0D0c and the device dev/snd/pcmC1D0p can be realized by opening the dev/snd/pcmC2D0p device to write data.
  • the dev/snd/pcmC2D0c device can be opened to read the mixed data and send it to other nodes on the network.
  • the function pointer that needs to be transmitted in the function for processing the mix points to the mix play buffer, that is, the pointer records the virtual address, so it is necessary to allocate the record mix.
  • the dma_alloc_coherent is called to record the virtual address and the physical address of the buffer of the mixing process, and the virtual address and the physical address of the buffer of the mixing process are in a one-to-one correspondence, so that the buffer is processed into the buffer.
  • the virtual address writes data, it can be handled by transferring the physical address of the buffer of the mixing process to the DMA.
  • Two sets of resources are defined, which describe the resources of a virtual sound card.
  • the first group describes the bus address range occupied by the virtual sound card.
  • IORESOURCE_MEM indicates that the first group describes the memory type resource information, and the second group describes this.
  • the interrupt number of the mixing device, IORESOURCE_IRQ indicates that the second group describes the interrupt resource information, and the virtual sound card driver obtains the corresponding resource information according to the flags.
  • platform_device Based on the resource information, you can define platform_device. After defining the platform_device structure, you can call the function platform_add_devices to add a virtual sound card to the Linux system.
  • the virtual sound card can be registered by calling platform_device_register(). For the virtual sound card Codec device, only the name and ID identifier need to be defined.
  • the virtual sound card and the virtual sound card Codec will be added to the Linux system's device list.
  • the soc_new_pcm function in the Linux kernel will call the function that requests the memory space for the virtual sound card. This address space is used to record the data after the mixing process.
  • the DMA interrupt callback function the physics corresponding to the memory buffer processed by the mix is processed. The address is allocated to the DMA for mixing playback, and the mixing processing is completed based on the tasklet.
  • the tasklet reads the DMA-transferred microphone data and the background music sent by the application layer for the mixing process, and processes the recorded and played data.
  • the size is currently 1K of data per processing, and the data after mixing is also 1K.
  • the user can play back the mix by reading and writing /dev/snd/pcmC2D0p, and the mix can be recorded by dev/snd/pcmC2D0c.
  • the ear return time of the mixing scheme based on the technical solution of the embodiment of the present invention is reduced to 60 ms, which can meet the demand of the product.
  • the embodiment of the invention further describes a computer storage medium, wherein the computer storage medium stores executable instructions, and the executable instructions are used to execute the audio processing method shown in FIG. 1 or FIG.
  • the embodiment of the invention describes an audio processing device based on the Linux kernel, which performs mixing processing at the kernel level based on the running Linux kernel. As shown in FIG. 8, the device includes:
  • the buffer unit 100 is configured to allocate a memory space for the direct memory read DMA buffer, where the DMA buffer includes a mix play buffer and a mix recording buffer;
  • a soft interrupt declaration unit 200 configured to declare a name of a soft interrupt for processing a mix and a corresponding processing function
  • Soft interrupt processing unit 300 configured to acquire a play buffer address and a soft interrupt in the mix Record the buffer address, call the mix processing function to perform the mixing process, and save the processed data in the mix play buffer.
  • the device further includes:
  • the mixing playback processing unit 400 is connected to the soft interrupt processing unit 300, and configured to assign an address of the sound mixing buffer to a source address of the DMA function pointer;
  • the address of the mix play buffer is used to support the DMA function from the address data of the mix play buffer to the first in first out FIFO queue of the virtual sound card.
  • the device further includes:
  • the sound recording processing unit 500 is connected to the soft interrupt processing unit 300, and configured to copy the data of the sound mixing buffer into the sound recording buffer in the interrupt callback function of the DMA function, the mixing The tone recording buffer is used to support the application layer to read the mixed audio data by turning on the virtual sound card.
  • the device further includes:
  • the registration unit 600 is connected to the buffer unit 100, and configured to perform the following operations before registering the sound mixing buffer and the mixing recording buffer in the memory space of the buffer unit 100; registering the virtual sound card driver and the virtual sound card; Device and platform device drivers; registered codec Codec devices, Codec drivers and Codec digital audio interfaces DAI.
  • the buffer unit 100 is further configured to allocate a memory space normal play buffer for the DMA buffer, and the normal play buffer is used to support the application layer to write audio data to be played by opening the virtual sound card;
  • the buffer unit 100 is further configured to allocate a normal recording buffer to the DMA buffer, and the normal recording buffer is configured to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
  • Each of the above units is a virtual functional unit, and the actual application can be implemented by an ASoC such as a processor in a set top box (such as an ARM processor), a logic programmable gate array (FPGA), or a dedicated integrated power supply. Road (ASIC) implementation.
  • ASoC such as a processor in a set top box (such as an ARM processor), a logic programmable gate array (FPGA), or a dedicated integrated power supply. Road (ASIC) implementation.
  • the embodiment of the invention further provides a computer storage medium, wherein the computer storage medium stores executable instructions, and the executable instructions are used to execute the audio processing method described in the embodiment of the invention.
  • the foregoing program may be stored in a computer readable storage medium, and the program is executed when executed.
  • the foregoing storage medium includes: a mobile storage device, a random access memory (RAM), a read-only memory (ROM), a magnetic disk, or an optical disk.
  • RAM random access memory
  • ROM read-only memory
  • magnetic disk or an optical disk.
  • optical disk A medium that can store program code.
  • the above-described integrated unit of the present invention may be stored in a computer readable storage medium if it is implemented in the form of a software function module and sold or used as a standalone product.
  • the technical solution of the embodiments of the present invention may be embodied in the form of a software product in essence or in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for making
  • a computer device which may be a personal computer, server, or network device, etc.
  • the foregoing storage medium includes various media that can store program codes, such as a mobile storage device, a RAM, a ROM, a magnetic disk, or an optical disk.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computational Linguistics (AREA)
  • Signal Processing (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • Acoustics & Sound (AREA)
  • Multimedia (AREA)
  • Circuit For Audible Band Transducer (AREA)
  • Reverberation, Karaoke And Other Acoustics (AREA)

Abstract

Disclosed are an audio processing method and device, and computer storage medium. The method comprises: allocating a memory space for a DMA buffer area, wherein the DMA buffer area comprises a mixed audio playing buffer area and a mixed audio recording buffer area; declaring a name of a soft interrupt for processing the audio mixing and a corresponding processing function; acquiring addresses of the playing buffer area and the recording buffer area in the soft interrupt for audio mixing, invoking the processing function for audio mixing to perform the audio mixing process, and storing data undergone the audio mixing process in the mixed audio playing buffer area.

Description

音频处理方法及设备、计算机存储介质Audio processing method and device, computer storage medium 技术领域Technical field
本发明涉及嵌入式平台领域的音频技术,尤其涉及一种音频处理方法及设备、计算机存储介质。The present invention relates to audio technologies in the field of embedded platforms, and in particular, to an audio processing method and device, and a computer storage medium.
背景技术Background technique
伴随着顶部(OTT,Over The Top)机顶盒业务的兴起,在机顶盒上安装K歌软件来实现在家庭里面实现卡拉OK的需求倍增。而目前基于Android的设备上,耳返时间(声音从麦克风输入的时间到从电视里面输出的延时)都在120毫秒(ms)以上,相对于iOS系统的40ms的耳返时间来说,较大耳返时间影响了用户使用体验。With the rise of the top (OTT, Over The Top) set-top box business, the installation of K-song software on the set-top box to double the demand for karaoke in the home. On Android-based devices, the ear-back time (the time from the input of the microphone to the time of output from the TV) is above 120 milliseconds (ms), compared to the 40-second ear-back time of the iOS system. The big ear return time affects the user experience.
对于有效减小基于Android设备的耳返时间,相关技术尚无有效解决方案。There is no effective solution for related technologies to effectively reduce the ear-back time of Android-based devices.
发明内容Summary of the invention
本发明实施例提供一种音频处理方法及设备、计算机存储介质,能够减少Android设备的耳返时间。The embodiment of the invention provides an audio processing method and device, and a computer storage medium, which can reduce the ear return time of the Android device.
本发明实施例的技术方案是这样实现的:The technical solution of the embodiment of the present invention is implemented as follows:
本发明实施例提供一种音频处理方法,所述方法包括:An embodiment of the present invention provides an audio processing method, where the method includes:
为直接内存读取(DMA)缓冲区分配内存空间,所述DMA缓冲区包括混音播放缓冲区和混音录制缓冲区;Allocating memory space for a direct memory read (DMA) buffer, the DMA buffer including a mix play buffer and a mix recording buffer;
声明处理混音的软中断的名称以及对应的处理函数;Declare the name of the soft interrupt handling the mix and the corresponding handler function;
在混音的软中断中获取播放缓冲区地址和录制缓冲区地址,调用混音处理函数进行混音处理,将处理混音后的数据保存在所述混音播放缓冲区。 The play buffer address and the recording buffer address are obtained in the soft interrupt of the mix, the mix processing function is called to perform the mixing process, and the processed mixed data is saved in the mix play buffer.
优选地,所述方法还包括:Preferably, the method further includes:
将所述混音播放缓冲区的地址赋值给DMA功能指针的源地址;Assigning the address of the mix play buffer to the source address of the DMA function pointer;
所述混音播放缓冲区的地址用于支持所述DMA功能从所述混音播放缓冲区的地址数据到虚拟声卡的先入先出(FIFO)队列。The address of the mix play buffer is used to support the DMA function from the address data of the mix play buffer to the first in first out (FIFO) queue of the virtual sound card.
优选地,所述方法还包括:Preferably, the method further includes:
在DMA功能的中断回调函数中,将所述混音播放缓冲区的数据拷贝到所述混音录制缓冲区中,所述混音录制缓冲区用于支持应用层通过打开虚拟声卡读取混音后的音频数据。In the interrupt callback function of the DMA function, the data of the sound mixing buffer is copied into the sound recording buffer, and the sound recording buffer is used to support the application layer to read the sound by opening the virtual sound card. After the audio data.
优选地,在内存空间分配混音播放缓冲区和混音录制缓冲区之前,所述方法还包括:Preferably, before the allocation of the mix play buffer and the mix recording buffer in the memory space, the method further includes:
注册虚拟声卡驱动和虚拟声卡;Register a virtual sound card driver and a virtual sound card;
注册平台设备和平台设备驱动;Register platform devices and platform device drivers;
注册编解码器(Codec)设备、Codec驱动和Codec数字音频接口(DAI)。Registered codec (Codec) devices, Codec drivers and Codec Digital Audio Interface (DAI).
优选地,所述方法还包括:Preferably, the method further includes:
为所述DMA缓冲区分配内存空间正常播放缓冲区,所述正常播放缓冲区用于支持应用层通过打开虚拟声卡写入需要播放的音频数据;Allocating a memory space normal play buffer for the DMA buffer, wherein the normal play buffer is used to support the application layer to write audio data to be played by opening the virtual sound card;
为所述DMA缓冲区分配正常录制缓冲区,所述正常录制缓冲区用于支持应用层通过打开所述虚拟声卡读取麦克风输入的原始音频数据。A normal recording buffer is allocated to the DMA buffer, and the normal recording buffer is used to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
本发明实施例提供一种音频处理设备,所述设备包括:An embodiment of the present invention provides an audio processing device, where the device includes:
缓冲区单元,配置为为DMA缓冲区分配内存空间,所述DMA缓冲区包括混音播放缓冲区和混音录制缓冲区;a buffer unit configured to allocate a memory space for the DMA buffer, where the DMA buffer includes a mix play buffer and a mix recording buffer;
软中断声明单元,配置为声明处理混音的软中断的名称以及对应的处理函数;a soft interrupt declaration unit configured to declare a name of a soft interrupt that handles the mix and a corresponding processing function;
软中断处理单元,配置为在混音的软中断中获取播放缓冲区地址和录制缓冲区地址,调用混音处理函数进行混音处理,将处理混音后的数据保 存在所述混音播放缓冲区。The soft interrupt processing unit is configured to acquire the play buffer address and the recording buffer address in the soft interrupt of the mix, call the mix processing function for mixing processing, and process the data after the mixing There is the mix play buffer.
优选地,所述设备还包括:Preferably, the device further includes:
混音播放处理单元,配置为将所述混音播放缓冲区的地址赋值给DMA功能指针的源地址;a mixing playback processing unit configured to assign an address of the sound mixing buffer to a source address of a DMA function pointer;
所述混音播放缓冲区的地址配置为支持所述DMA功能从所述混音播放缓冲区的地址数据到虚拟声卡的FIFO队列。The address of the mix play buffer is configured to support the DMA function from the address data of the mix play buffer to the FIFO queue of the virtual sound card.
优选地,所述设备还包括:Preferably, the device further includes:
混音录制处理单元,配置为在DMA功能的中断回调函数中,将所述混音播放缓冲区的数据拷贝到所述混音录制缓冲区中,所述混音录制缓冲区用于支持应用层通过打开虚拟声卡读取混音后的音频数据。a sound recording processing unit configured to copy data of the sound mixing buffer into the sound recording buffer in an interrupt callback function of the DMA function, wherein the sound recording buffer is used to support an application layer Read the mixed audio data by turning on the virtual sound card.
优选地,所述设备还包括:Preferably, the device further includes:
注册单元,配置为在所述缓冲区单元内存空间分配混音播放缓冲区和混音录制缓冲区之前,执行以下操作;注册虚拟声卡驱动和虚拟声卡;注册平台设备和平台设备驱动;注册编解码器设备、Codec驱动和Codec DAI。a registration unit configured to perform the following operations before the allocation of the mix play buffer and the mix recording buffer in the buffer unit memory space; registering the virtual sound card driver and the virtual sound card; registering the platform device and the platform device driver; registering the codec Device, Codec driver and Codec DAI.
优选地,所述缓冲区单元还配置为为所述DMA缓冲区分配内存空间正常播放缓冲区,所述正常播放缓冲区用于支持应用层通过打开虚拟声卡写入需要播放的音频数据;Preferably, the buffer unit is further configured to allocate a memory space normal play buffer for the DMA buffer, and the normal play buffer is configured to support the application layer to write audio data to be played by opening the virtual sound card;
所述缓冲区单元还配置为为所述DMA缓冲区分配正常录制缓冲区,所述正常录制缓冲区用于支持应用层通过打开所述虚拟声卡读取麦克风输入的原始音频数据。The buffer unit is further configured to allocate a normal recording buffer to the DMA buffer, and the normal recording buffer is configured to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
第三方面,本发明实施例提供一种计算机存储介质,所述计算机存储介质中存储有可执行指令,所述可执行指令用于执行本发明实施例提供的音频处理方法。In a third aspect, an embodiment of the present invention provides a computer storage medium, where the computer storage medium stores executable instructions, and the executable instructions are used to execute an audio processing method provided by an embodiment of the present invention.
本发明实施例中,通过混音的软中断中获取播放缓冲区地址和录制缓冲区地址,调用混音处理函数进行混音处理,例如当在ARM处理器上运行 Android操作系统时,实现了在Linux内核层面的混音处理(代替了相关技术在应用层实现的混音处理),将混音处理结果提供给应用层,无需应用层自行进行混音处理,较相关技术的应用层自行进行混音处理大大缩短了耳返延时。In the embodiment of the present invention, the play buffer address and the recording buffer address are obtained through the soft interrupt of the mix, and the mix processing function is called to perform the mixing process, for example, when running on the ARM processor. In the Android operating system, the mixing processing at the Linux kernel level is realized (instead of the mixing processing implemented by the related technology in the application layer), and the mixing processing result is provided to the application layer, and the application layer does not need to perform the mixing processing by itself. The application layer of the related art directly performs the mixing process to greatly shorten the ear return delay.
附图说明DRAWINGS
图1为本发明实施例中音频处理方法的实现流程示意图;1 is a schematic flowchart of an implementation process of an audio processing method according to an embodiment of the present invention;
图2为本发明实施例中基于ASoC的音频处理方法的流程图;2 is a flowchart of an ASoC-based audio processing method according to an embodiment of the present invention;
图3为本发明实施例中soc_probe函数的调用流程图;3 is a flowchart of a call of a soc_probe function according to an embodiment of the present invention;
图4为本发明实施例中soc_probe_dai_link()函数流程图;4 is a flowchart of a soc_probe_dai_link() function according to an embodiment of the present invention;
图5为本发明实施例中snd_soc_instantiate_card函数调用流程图;FIG. 5 is a flowchart of a snd_soc_instantiate_card function call according to an embodiment of the present invention;
图6为本发明实施例中虚拟声卡挂载在snd_card下的示意图;6 is a schematic diagram of a virtual sound card being mounted under a snd_card according to an embodiment of the present invention;
图7为本发明实施例中tasklet混音流程图;FIG. 7 is a flowchart of a tasklet mixing according to an embodiment of the present invention; FIG.
图8为本发明实施例中音频处理设备的功能结构示意图一;FIG. 8 is a first schematic structural diagram of an audio processing device according to an embodiment of the present invention; FIG.
图9为本发明实施例中音频处理设备的功能结构示意图二。FIG. 9 is a second schematic structural diagram of an audio processing device according to an embodiment of the present invention.
具体实施方式detailed description
为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Android设备拥有一个比较标准和健全的架构处理音频,架构包括:应用层、Java framework服务Audio Mananger、本地服务Audio Flinger、抽象层Alsa HAL、本地库、用外部(external)的Alsa-lib支持库、底层的编码(Codec)驱动;Android devices have a relatively standard and robust architecture for processing audio. The architecture includes: application layer, Java framework service Audio Mananger, local service Audio Flinger, abstraction layer Alsa HAL, local library, external (external) Alsa-lib support library, The underlying coding (Codec) driver;
因为音频数据在上述架构中经过了太多的处理而导致音频延时增加,这样复杂的系统架构是不能满足实时性要求很高的场景的使用需求,例如 网络K歌,需要将混音后的数据发送给网络上的其他点播用户,较大的延迟影响了用户使用体验。Because audio data has undergone too much processing in the above architecture, resulting in increased audio delay, such a complex system architecture cannot meet the needs of real-time scenarios, such as Network K songs need to send the mixed data to other on-demand users on the network, and the large delay affects the user experience.
本发明实施例记载的音频处理设备为基于高级Linux音频架构(ALSA,Advanced Linux Sound Architecture)Android,基于Android设备中高级精简指令集机器(ARM,Advanced RISC Machine)处理器,在Android设备运行的Linux内核的设备链表中添加设置虚拟声卡,使用虚拟声卡直接截取音频数据(例如用户通过麦克风输入的音频数据)和背景音频数据(歌曲播放的背景音)来进行混音处理,应用层可以直接获取混音数据,无需由应用层自身进行混音处理,减少了耳返时间;The audio processing device described in the embodiment of the present invention is an Advanced Linux Sound Architecture (ALSA) based on Android, and is based on an Android device, an Advanced RISC Machine (ARM) device, and a Linux device running on an Android device. The virtual sound card is added to the device list of the kernel, and the virtual sound card directly intercepts the audio data (such as the audio data input by the user through the microphone) and the background audio data (the background sound of the song playing) for mixing processing, and the application layer can directly obtain the mixed sound. Sound data, no need to be mixed by the application layer itself, reducing the ear return time;
为实现上述目的,本发明实施例中,针对已有的Linux内核下不能进行混音的不足,在Linux内核的设备链表上添加虚拟声卡设备(简称虚拟声卡),将虚拟声卡的资源注册进Linux内核,由Linux内核统一管理;In order to achieve the above object, in the embodiment of the present invention, in view of the insufficiency of mixing in the existing Linux kernel, a virtual sound card device (referred to as a virtual sound card) is added to the device list of the Linux kernel, and the virtual sound card resource is registered into the Linux. The kernel is managed by the Linux kernel;
本实施例提供的音频处理设备基于ALSA架构的片上系统(SOC)也即ASoC,ASoC运行Linux内核进行音频处理,ASoC运行的Linux内核中设置有虚拟声卡、Platform、虚拟声卡Codec和虚拟声卡Codec驱动,由虚拟声卡在Linux内核层面(代替应用层)对音频数据进行处理,Linux内核添加设置有正常播放缓冲区、正常录制缓冲区、混音播放缓冲区和混音录制缓冲区,用于在不同的应用场景存储音频数据,在录制数据和播放数据到达时通过软中断的方式将两路数据进行混音处理,应用层可以直接读取混音数据。The audio processing device provided in this embodiment is based on the ALSA architecture of the system-on-a-chip (SOC), that is, ASOC, and the ASoC runs the Linux kernel for audio processing. The Linux kernel running in the ASoC is provided with a virtual sound card, a Platform, a virtual sound card Codec, and a virtual sound card Codec driver. The audio data is processed by the virtual sound card at the Linux kernel level (instead of the application layer), and the Linux kernel is added with a normal play buffer, a normal recording buffer, a mix play buffer, and a mix recording buffer for different The application scene stores audio data, and the two channels of data are mixed by soft interrupt when the recorded data and the play data arrive, and the application layer can directly read the mixed data.
在Linux的驱动管理和注册机制下设置虚拟声卡的驱动,包括:定义虚拟声卡对应的平台设备(platform_device)结构体、注册虚拟声卡对应的platform_device结构体、定义虚拟声卡对应的平台驱动(platform_driver)结构体、以及注册虚拟声卡的platform_driver结构体;添加虚拟声卡、Platform、虚拟声卡Codec和虚拟声卡Codec驱动的处理遵循Linux的驱动 管理和注册机制;The driver of the virtual sound card is set under the driver management and registration mechanism of the Linux, including: defining the platform device (platform_device) structure corresponding to the virtual sound card, registering the platform_device structure corresponding to the virtual sound card, and defining the platform driver (platform_driver) structure corresponding to the virtual sound card. Body, and the platform_driver structure of the registered virtual sound card; adding virtual sound card, Platform, virtual sound card Codec and virtual sound card Codec driver processing follows the Linux driver Management and registration mechanism;
以下对设置虚拟声卡、Platform、虚拟声卡Codec和虚拟声卡Codec驱动的处理进行说明,对于未尽的细节,请参见Linux的驱动管理和注册机制的相关规范文档。The following describes the processing of setting the virtual sound card, Platform, virtual sound card Codec and virtual sound card Codec driver. For the details, please refer to the relevant specification document of Linux driver management and registration mechanism.
Android设备中所运行的Linux内核中包括总线也即虚拟总线或平台(platform)总线、平台设备(platform_device)和平台驱动(platform_driver);虚拟总线将平台设备和平台驱动绑定:在注册一个平台驱动的时候,虚拟总线寻找与平台驱动匹配的平台设备。The Linux kernel running on the Android device includes a bus, that is, a virtual bus or platform bus, a platform device (platform_device), and a platform driver (platform_driver); the virtual bus binds the platform device and the platform driver: registering a platform driver At the time, the virtual bus looks for platform devices that match the platform drivers.
虚拟声卡的资源注册与混音软中断(Tasklet)的处理,如果要想一个虚拟声卡正常工作,需要完成三个步骤:1、虚拟声卡驱动和虚拟声卡的注册;2、平台设备和平台设备驱动的注册,平台设备主要实现直接内存存取(DMA,Direct Memory Asset)功能,平台设备驱动的名称和平台设备的名称一致:3、编解码器(Codec)设备(简称Codec)、Codec驱动和Codec数字音频接口(DAI,Digital Aaudio Interface)的注册;下面分别进行说明:Virtual sound card resource registration and mixing soft interrupt (Tasklet) processing, if you want a virtual sound card to work properly, you need to complete three steps: 1, virtual sound card driver and virtual sound card registration; 2, platform equipment and platform device driver The registration of the platform device mainly implements the direct memory access (DMA) function. The name of the platform device driver is consistent with the name of the platform device: 3. Codec device (Codec), Codec driver and Codec Registration of Digital Audio Interface (DAI, Digital Aaudio Interface);
1.虚拟声卡驱动和虚拟声卡设备(简称虚拟声卡)的注册,虚拟声卡驱动的名称必须和平台设备的名称一致:1. The registration of the virtual sound card driver and the virtual sound card device (referred to as the virtual sound card), the name of the virtual sound card driver must be the same as the name of the platform device:
1)设置虚拟声卡驱动,相关代码如下:1) Set the virtual sound card driver, the relevant code is as follows:
Figure PCTCN2016076802-appb-000001
Figure PCTCN2016076802-appb-000001
2)注册虚拟声卡驱动,相关代码如下: 2) Register the virtual sound card driver, the relevant code is as follows:
Figure PCTCN2016076802-appb-000002
Figure PCTCN2016076802-appb-000002
3)设置虚拟声卡,包括虚拟声卡在内存中所占用的物理地址的开始和结束地址、以及相关标志位。3) Set the virtual sound card, including the start and end addresses of the physical address occupied by the virtual sound card in the memory, and related flag bits.
虚拟声卡的资源信息用platform_device结构体描述,platform_device结构体包含虚拟声卡的名称(name)、标识(ID),与定义的虚拟声卡的编解码器(Codec)的资源以及虚拟声卡的Codec的资源所占用的字节数目。The resource information of the virtual sound card is described by the platform_device structure, which includes the name (name), the identifier (ID) of the virtual sound card, the codec resource of the defined virtual sound card, and the resource of the Codec of the virtual sound card. The number of bytes occupied.
相关代码如下:The relevant code is as follows:
Figure PCTCN2016076802-appb-000003
Figure PCTCN2016076802-appb-000003
4)注册虚拟声卡的资源(zx_devices为包含了所有定义的虚拟设备的数组),相关代码如下:4) Register the virtual sound card resources (zx_devices is an array containing all defined virtual devices), the relevant code is as follows:
platform_add_devices(zx_devices,ARRAY_SIZE(zx_devices))Platform_add_devices(zx_devices,ARRAY_SIZE(zx_devices))
5)注册虚拟声卡,相关代码如下:5) Register the virtual sound card, the relevant code is as follows:
Figure PCTCN2016076802-appb-000004
Figure PCTCN2016076802-appb-000004
Figure PCTCN2016076802-appb-000005
Figure PCTCN2016076802-appb-000005
2、平台设备和平台驱动的注册,平台设备实现DMA功能,平台驱动的名称和平台设备的名称一致,均为zx-audio-platform:2. Platform device and platform driver registration, platform device implements DMA function, platform driver name and platform device name are the same, both are zx-audio-platform:
1)平台驱动的设置,相关代码如下:1) Platform driver settings, the relevant code is as follows:
Figure PCTCN2016076802-appb-000006
Figure PCTCN2016076802-appb-000006
2)平台驱动的注册,相关代码如下:2) Platform-driven registration, the relevant code is as follows:
Figure PCTCN2016076802-appb-000007
Figure PCTCN2016076802-appb-000007
3)平台设备的设置,相关代码如下:3) The setting of the platform device, the relevant code is as follows:
Figure PCTCN2016076802-appb-000008
Figure PCTCN2016076802-appb-000008
4)平台设备的注册:4) Registration of platform equipment:
platform_add_devices(zx_devices,ARRAY_SIZE(zx_devices));Platform_add_devices(zx_devices,ARRAY_SIZE(zx_devices));
3、Codec、Codec驱动和Codec DAI的注册。 3. Registration of Codec, Codec drivers and Codec DAI.
1)Codec驱动的定义,相关代码如下:1) The definition of Codec driver, the relevant code is as follows:
Figure PCTCN2016076802-appb-000009
Figure PCTCN2016076802-appb-000009
2)虚拟Codec驱动的注册,相关代码如下:2) Registration of the virtual Codec driver, the relevant code is as follows:
Figure PCTCN2016076802-appb-000010
Figure PCTCN2016076802-appb-000010
3)虚拟Codec设备的定义,相关代码如下:3) The definition of the virtual Codec device, the relevant code is as follows:
Figure PCTCN2016076802-appb-000011
Figure PCTCN2016076802-appb-000011
4)虚拟Codec设备的注册,相关代码如下:4) Registration of the virtual Codec device, the relevant code is as follows:
platform_add_devices(zx_devices,ARRAY_SIZE(zx_devices));Platform_add_devices(zx_devices,ARRAY_SIZE(zx_devices));
5)Codec DAI的定义,相关代码如下:5) Codec DAI definition, the relevant code is as follows:
Figure PCTCN2016076802-appb-000012
Figure PCTCN2016076802-appb-000012
Figure PCTCN2016076802-appb-000013
Figure PCTCN2016076802-appb-000013
6)Codec DAI的注册,相关代码如下:6) Registration of Codec DAI, the relevant code is as follows:
Figure PCTCN2016076802-appb-000014
Figure PCTCN2016076802-appb-000014
除了根据上述步骤在Linux内核中设置虚拟声卡、Platform、虚拟声卡Codec和虚拟声卡Codec驱动,还需要设置记录缓冲区的结构体以及处理混音的软中断(tasklet)处理函数;其中,缓冲区包含正常播放缓冲区、正常录制缓冲区、混音播放缓冲区和混音录制缓冲区,配置为不同的应用场景存储音频数据;软中断(tasklet)处理函数配置为处理用户通过麦克风输入的音频数据和背景音频进行的混音。In addition to setting the virtual sound card, Platform, virtual sound card Codec and virtual sound card Codec driver in the Linux kernel according to the above steps, it is also necessary to set the structure of the record buffer and the soft interrupt (tasklet) processing function for processing the mix; wherein the buffer contains The normal play buffer, the normal recording buffer, the mix play buffer, and the mix recording buffer are configured to store audio data for different application scenarios; the soft break (tasklet) processing function is configured to process audio data input by the user through the microphone and Mixing of background audio.
如图1所示,基于运行上述Linux内核的Android设备如机顶盒,音频 处理方法包括以下步骤:As shown in Figure 1, based on Android devices such as set-top boxes running the above Linux kernel, audio The processing method includes the following steps:
步骤101,为直接内存读取(DMA)缓冲区分配内存空间,所述DMA缓冲区包括混音播放缓冲区和混音录制缓冲区。Step 101: Allocate a memory space for a direct memory read (DMA) buffer, where the DMA buffer includes a mix play buffer and a mix recording buffer.
步骤102,声明处理混音的软中断的名称以及对应的处理函数。Step 102, declaring the name of the soft interrupt handling the mix and the corresponding processing function.
步骤103,在混音的软中断中获取播放缓冲区地址和录制缓冲区地址,调用混音处理函数进行混音处理,将处理混音后的数据保存在混音播放缓冲区。Step 103: Acquire a play buffer address and a recording buffer address in the soft interrupt of the mix, call a mix processing function to perform a mixing process, and save the processed data in the mix play buffer.
当需要混音播放时,将所述混音播放缓冲区的地址赋值DMA功能指针的源地址;所述DMA功能基于所述混音播放缓冲区的地址,从所述混音播放缓冲区的地址数据到虚拟声卡的先入先出(FIFO)队列。When the mix play is required, the address of the mix play buffer is assigned a source address of the DMA function pointer; the DMA function is based on the address of the mix play buffer, from the address of the mix play buffer Data to the virtual sound card's first in first out (FIFO) queue.
当需要混音录制时,在DMA功能的中断回调函数中,将所述混音播放缓冲区的数据拷贝到所述混音录制缓冲区中,所述混音录制缓冲区用于支持应用层通过打开虚拟声卡读取混音后的音频数据。When the sound recording is required, in the interrupt callback function of the DMA function, the data of the sound mixing buffer is copied into the sound recording buffer, and the sound recording buffer is used to support the application layer. Turn on the virtual sound card to read the audio data after the mix.
此外,在执行上述操作之前,还需要在设置虚拟声卡,注册虚拟声卡驱动和虚拟声卡;注册平台设备和平台设备驱动;注册编解码器(Codec)设备、Codec驱动和Codec数字音频接口(DAI);注册平台设备和平台设备驱动用于实现DMA功能。In addition, before performing the above operations, you need to set up a virtual sound card, register virtual sound card driver and virtual sound card; register platform device and platform device driver; register codec device, Codec driver and Codec digital audio interface (DAI) Registered platform devices and platform device drivers are used to implement DMA functions.
对于正常播放(也即非混音播放)之外的场景,当需要正常播放时,为所述DMA缓冲区分配内存空间正常播放缓冲区,所述正常播放缓冲区用于支持应用层通过打开虚拟声卡写入需要播放的音频数据;For scenes other than normal play (that is, non-mixed play), when normal play is required, a normal play buffer is allocated for the DMA buffer, and the normal play buffer is used to support the application layer by opening the virtual The sound card writes audio data that needs to be played;
当应用层需要获取麦克风输入的原始音频数据时,为所述DMA缓冲区分配正常录制缓冲区,所述正常录制缓冲区用于支持应用层通过打开所述虚拟声卡读取麦克风输入的原始音频数据。When the application layer needs to obtain the original audio data input by the microphone, the normal recording buffer is allocated to the DMA buffer, and the normal recording buffer is used to support the application layer to read the original audio data input by the microphone by opening the virtual sound card. .
下面就运行上述的Linux内核的Android设备如机顶盒实施图2所示的音频处理方法进行说明,包括以下步骤: The following describes an audio processing method shown in FIG. 2 for an Android device such as a set top box running the above Linux kernel, including the following steps:
步骤201,平台总线匹配名称为虚拟声卡的device和driver。In step 201, the platform bus matches the device and driver whose names are virtual sound cards.
后续步骤202同时会触发soc_probe函数的调用,soc_probe是整个ASoC驱动初始化的入口。 Subsequent step 202 also triggers the invocation of the soc_probe function, which is the entry for the entire ASoC driver initialization.
按照Linux的设备模型,有platform_device,就一定会有platform_driver,ASoC的platform_driver中的name字段为soc-audio,正好与在步骤1中定义的platform_device中的名称相同,按照Linux的设备模型,platform总线会匹配这两个名称相同的device和driver,同时会触发soc_probe的调用,它正是整个ASoC驱动初始化的入口。According to the Linux device model, if there is platform_device, there will be platform_driver. The name field in the AS_C platform_driver is soc-audio, which is exactly the same as the name in the platform_device defined in step 1. According to the Linux device model, the platform bus will Matching the two devices and drivers with the same name will also trigger the call to soc_probe, which is the entry point for the entire ASoC driver initialization.
步骤202:调用soc_probe函数。Step 202: Call the soc_probe function.
如图3所示,soc_probe函数的调用包括如下步骤:As shown in Figure 3, the call to the soc_probe function includes the following steps:
步骤301,在soc_probe函数中调用snd_soc_register_card为snd_soc_pcm_runtime数组申请内存,每一个dai_link对应snd_soc_pcm_runtime数组的一个单元。In step 301, the snd_soc_register_card is called in the soc_probe function to apply for memory for the snd_soc_pcm_runtime array, and each dai_link corresponds to a unit of the snd_soc_pcm_runtime array.
步骤302,把snd_soc_card中的dai_link配置复制到相应的snd_soc_pcm_runtime中。Step 302: Copy the dai_link configuration in the snd_soc_card to the corresponding snd_soc_pcm_runtime.
步骤303,调用snd_soc_instantiate_card函数。In step 303, the snd_soc_instantiate_card function is called.
soc_probe函数对应的代码如下所示:The code corresponding to the soc_probe function is as follows:
snd_soc_card*card=platform_get_drvdata(pdev)Snd_soc_card*card=platform_get_drvdata(pdev)
snd_soc_register_card(card)Snd_soc_register_card(card)
card->rtd=kzalloc(sizeof(struct snd_soc_pcm_runtime)*(card->num_links+card->num_aux_devs),GFP_KERNEL)Card->rtd=kzalloc(sizeof(struct snd_soc_pcm_runtime)*(card->num_links+card->num_aux_devs), GFP_KERNEL)
for(i=0;i<card->num_links;i++)For(i=0;i<card->num_links;i++)
          card->rtd[i].dai_link=Card->rtd[i].dai_link=
&card->dai_link[i]&card->dai_link[i]
snd_soc_instantiate_cards()Snd_soc_instantiate_cards()
snd_soc_instantiate_card()Snd_soc_instantiate_card()
步骤203:snd_soc_instantiate_card函数调用流程, snd_soc_instantiate_card函数遍历每一对dai_link,进行Codec、Platform和DAI的绑定,snd_soc_instantiate_card函数调用soc_probe_dai_link函数,soc_probe_dai_link函数的调用流程如图4所示,在soc_probe_dai_link函数中,调用了Codec、DAI和platform驱动的probe函数外,在最后还调用了soc_new_pcm()函数用于创建虚拟声卡。Step 203: The snd_soc_instantiate_card function call process, The snd_soc_instantiate_card function traverses each pair of dai_links, binds Codec, Platform, and DAI, and the snd_soc_instantiate_card function calls the soc_probe_dai_link function. The call flow of the soc_probe_dai_link function is shown in Figure 4. In the soc_probe_dai_link function, the Codec, DAI, and platform-driven probes are called. In addition to the function, the soc_new_pcm() function is also called at the end to create a virtual sound card.
snd_soc_instantiate_card函数调用流程如图5所示,包括以下步骤:The snd_soc_instantiate_card function call flow is shown in Figure 5 and includes the following steps:
步骤401,利用card->instantiated来判断虚拟声卡是否已经实例化,如果已经实例化则直接返回。In step 401, card->instantiated is used to determine whether the virtual sound card has been instantiated, and if it has been instantiated, it returns directly.
步骤402,遍历每一对dai_link,进行codec、platform和DAI的绑定。In step 402, each pair of dai_links is traversed, and the binding of codec, platform, and DAI is performed.
步骤403,初始化Codec的寄存器缓存。In step 403, the register buffer of Codec is initialized.
步骤404,创建虚拟声卡。In step 404, a virtual sound card is created.
虚拟声卡挂载在snd_card下的示意图如图6所示。A schematic diagram of the virtual sound card being mounted under the snd_card is shown in FIG. 6.
步骤405,依次调用各个子结构的probe函数。In step 405, the probe function of each substructure is called in turn.
步骤406,执行soc_probe_dai_link()函数。In step 406, the soc_probe_dai_link() function is executed.
步骤407,初始化和设置。 Step 407, initialization and setting.
步骤408,调用标准ALSA驱动的声卡注册函数对虚拟声卡进行注册。In step 408, the virtual sound card is registered by calling the sound card registration function driven by the standard ALSA.
步骤204:通过处理混音的软中断(tasklet),处理用户通过麦克风输入的音频数据和背景音乐的音频数据进行混音。Step 204: The audio data input by the user through the microphone and the audio data of the background music are processed and mixed by processing a soft break of the mix.
如图7所示,步骤204通过以下步骤实现:As shown in Figure 7, step 204 is implemented by the following steps:
步骤501,定义一个记录缓冲区的结构体,包含正常播放缓冲区、正常录制缓冲区、混音播放缓冲区和混音录制缓冲区,用于不同的应用场景存储音频数据,代码如下:Step 501: Define a structure of a record buffer, including a normal play buffer, a normal recording buffer, a mix play buffer, and a mix recording buffer, and store audio data for different application scenarios. The code is as follows:
定义记录缓冲区的指针:Define a pointer to the record buffer:
Figure PCTCN2016076802-appb-000015
Figure PCTCN2016076802-appb-000015
Figure PCTCN2016076802-appb-000016
Figure PCTCN2016076802-appb-000016
在为DMA缓冲区分配内核空间的函数中,分别将这4个指针赋值。In the function that allocates kernel space for the DMA buffer, the four pointers are assigned respectively.
步骤502,声明处理混音的tasklet的名称以及对应的处理函数,即DECLARE_TASKLET(zx_i2s_spdif_mix_tasklet,zx_snd_soc_mix_taskelet,0)。 Step 502, declaring the name of the tasklet that processes the mix and the corresponding processing function, that is, DECLARE_TASKLET (zx_i2s_spdif_mix_tasklet, zx_snd_soc_mix_taskelet, 0).
步骤503,tasklet在DMA的中断回调函数中初始化(只需要初始化一次),并调用tasklet_schedule来调度tasklet。In step 503, the tasklet is initialized in the DMA interrupt callback function (only needs to be initialized once), and the tasklet_schedule is called to dispatch the tasklet.
步骤504,在混音的tasklet中获取混音播放缓冲区地址和混音录制缓冲区地址,调用混音处理函数进行混音处理,将处理混音后的数据保存在混音播放缓冲区。Step 504: Obtain a mix play buffer address and a mix recording buffer address in the mixed tasklet, call a mix processing function to perform a mix process, and save the processed data in the mix play buffer.
步骤505a,实现混音播放时,将混音播放缓冲区的地址赋值给DMA指针的源地址,让DMA从这个地址搬运数据到虚拟声卡的先入先出(FIFO)队列中,从而实现混音播放。In step 505a, when the mixing is played, the address of the mixing play buffer is assigned to the source address of the DMA pointer, and the DMA transfers data from the address to the first-in-first-out (FIFO) queue of the virtual sound card, thereby realizing the mixing play. .
步骤506b,实现混音录制时,在DMA中断回调函数中,将混音播放缓冲区的数据拷贝到混音录制缓冲区中,应用层可以通过打开虚拟声卡读取混音后的音频数据,实现正常播放。Step 506b, when the sound recording is realized, in the DMA interrupt callback function, the data of the sound mixing buffer is copied into the sound recording buffer, and the application layer can read the mixed audio data by opening the virtual sound card. Normal play.
这样可以在每次录制数据和播放数据到达之后,将两路音频数据进行混音;tasklet机制是一种比较常见的机制,通常用于减少中断处理的时间,将本应该是在中断服务程序中完成的任务转换成软中断完成。This can mix two audio data after each recorded data and playback data arrives; the tasklet mechanism is a relatively common mechanism, usually used to reduce the interrupt processing time, which should be in the interrupt service routine. The completed task is converted to a soft interrupt completion.
为了最大程度的避免中断处理时间过长(中断里面如果进行混音操作会导致中断处理时间过长)而导致中断丢失,把一些在中断处理中不是非常紧急的任务放在后面执行,而让中断处理程序尽快返回。In order to avoid the interrupt processing time being too long (interruption, if the mixing operation will cause the interrupt processing time to be too long), the interrupt will be lost, and some tasks that are not very urgent in the interrupt processing will be executed later, and the interrupt will be interrupted. The handler returns as soon as possible.
在tasklet处理中,将记录正常播放缓冲区、正常录制缓冲区和混音播放缓冲区的地址作为参数,通过如下混音算法进行混音处理: In the tasklet processing, the addresses of the normal play buffer, the normal recording buffer, and the mix play buffer are recorded as parameters, and the mixing process is performed by the following mixing algorithm:
使用A和B表示两路音频信号,使用Y表示混音后的音频信号。Use A and B to represent two audio signals, and Y to represent the audio signal after mixing.
对于n比特的音频样本信号,如果A和B都为负,则,For an n-bit audio sample signal, if both A and B are negative, then
Y=A+B-(A*B/(-(2pow(n-1)-1)))Y=A+B-(A*B/(-(2pow(n-1)-1)))
否则:otherwise:
Y=A+B-(A*B/(2pow(n-1))。Y=A+B-(A*B/(2pow(n-1)).
C语言表示:C language means:
Figure PCTCN2016076802-appb-000017
Figure PCTCN2016076802-appb-000017
在DMA中断回调处理函数中,第一次会注册混音的tasklet处理函数tasklet_init(&zx_i2s_spdif_mix_tasklet,zx_snd_soc_mix_taskelet,(unsigned long)arg),并调用tasklet_schedule(&zx_i2s_spdif_mix_tasklet);In the DMA interrupt callback handler, the tasklet processing function tasklet_init(&zx_i2s_spdif_mix_tasklet, zx_snd_soc_mix_taskelet, (unsigned long) arg) of the mix is registered for the first time, and tasklet_schedule(&zx_i2s_spdif_mix_tasklet) is called;
在DMA中断回调处理函数中,首先分别将录音数据和放音数据的流指针赋值给全局变量pcm_substream,然后再通过这个全局变量将该这2路音频数据流指针传递到混音处理的tasklet中,最后在混音处理的tasklet中将这2个指针分别作用于上述的混音算法,经过该算法处理后,得到了混音后的数据(该数据存储在混音播放指针指向的缓冲区)。如果配置DMA搬运的数据为1KB,那么每次混音的时候,录音数据和播放数据的大小都为1KB,混音输出的数据依然为1KB。In the DMA interrupt callback processing function, firstly assign the stream pointer of the recorded data and the playback data to the global variable pcm_substream, and then pass the two-way audio stream pointer to the tasklet of the mixing process through the global variable. Finally, in the task bar of the mixing process, the two pointers are respectively applied to the above-mentioned mixing algorithm, and after the algorithm is processed, the mixed data is obtained (the data is stored in the buffer pointed to by the mixing play pointer). If the data for DMA transfer is 1 KB, the size of the recorded data and the playback data is 1 KB each time the mix is mixed, and the data of the mix output is still 1 KB.
由于混音后的数据要分两路处理,播放混音数据和通过虚拟声卡获取音频数据,因此在DMA中断处理函数中,需要将播放时候DMA的物理地址指针,替换成混音处理后的混音数据播放的DMA物理地址指针,这样替 换后,原来播放的声音数据就被替换成了混音处理后的数据,同时将混音播放缓冲区的数据拷贝到混音录制缓冲区指针所指向的缓冲区,同时调用snd_pcm_period_elapsed来通知Linux内核,当前的数据已经处理完毕。Since the mixed data is processed in two ways, the mixed data is played and the audio data is obtained through the virtual sound card. Therefore, in the DMA interrupt processing function, the physical address pointer of the DMA at the time of playback needs to be replaced with the mixed after the mixing processing. DMA physical address pointer for audio data playback, so After the change, the originally played sound data is replaced with the data after the mixing process, and the data of the sound mixing buffer is copied to the buffer pointed to by the sound recording buffer pointer, and snd_pcm_period_elapsed is called to notify the Linux kernel. The current data has been processed.
当应用层层需要获取用户麦克风输入的原始音频数据,可以通过打开dev/snd/pcmC0D0c这个设备来读取数据,当应用层想播放声音的时候,可以通过打开dev/snd/pcmC1D0p这个设备来写入数据。当应用层想要直接播放混音数据的时候,可以通过打开dev/snd/pcmC2D0p这个设备来写入数据来实现将设备dev/snd/pcmC0D0c和设备dev/snd/pcmC1D0p声音混合的功能。当应用层想要通过网络传输混音后的数据时候,可以通过打开dev/snd/pcmC2D0c这个设备来读取混音后的数据,发给网络其他节点。When the application layer needs to obtain the original audio data input by the user's microphone, the data can be read by opening the device dev/snd/pcmC0D0c. When the application layer wants to play the sound, it can be written by opening the dev/snd/pcmC1D0p device. Into the data. When the application layer wants to play the mix data directly, the function of mixing the device dev/snd/pcmC0D0c and the device dev/snd/pcmC1D0p can be realized by opening the dev/snd/pcmC2D0p device to write data. When the application layer wants to transmit the mixed data through the network, the dev/snd/pcmC2D0c device can be opened to read the mixed data and send it to other nodes on the network.
由于配置DMA的时候需要配置物理地址,而在处理混音的函数中需要传出的函数指针指向的是混音播放缓冲区,也即指针记录的是虚拟地址,因此需要在分配记录混音处理的缓冲区的时候,调用dma_alloc_coherent分别记录混音处理的缓冲区的虚拟地址和物理地址,混音处理的缓冲区的虚拟地址和物理地址是一一对应关系,这样向混音处理的缓冲区的虚拟地址写数据的时候,就可以通过将混音处理的缓冲区的物理地址传递给DMA来进行搬运处理。Since the physical address needs to be configured when configuring the DMA, the function pointer that needs to be transmitted in the function for processing the mix points to the mix play buffer, that is, the pointer records the virtual address, so it is necessary to allocate the record mix. In the buffer, the dma_alloc_coherent is called to record the virtual address and the physical address of the buffer of the mixing process, and the virtual address and the physical address of the buffer of the mixing process are in a one-to-one correspondence, so that the buffer is processed into the buffer. When the virtual address writes data, it can be handled by transferring the physical address of the buffer of the mixing process to the DMA.
本发明实施例的所涉及的虚拟声卡资源注册,主要是做如下工作:The virtual sound card resource registration involved in the embodiment of the present invention mainly performs the following work:
定义了两组resource,它描述了一个虚拟声卡的资源,第1组描述了这个虚拟声卡所占用的总线地址范围,IORESOURCE_MEM表示第1组描述的是内存类型的资源信息,第2组描述了这个混音设备的中断号,IORESOURCE_IRQ表示第2组描述的是中断资源信息,虚拟声卡驱动会根据flags来获取相应的资源信息。Two sets of resources are defined, which describe the resources of a virtual sound card. The first group describes the bus address range occupied by the virtual sound card. IORESOURCE_MEM indicates that the first group describes the memory type resource information, and the second group describes this. The interrupt number of the mixing device, IORESOURCE_IRQ indicates that the second group describes the interrupt resource information, and the virtual sound card driver obtains the corresponding resource information according to the flags.
基于resource信息可以定义platform_device,定义platform_device结构体后可以调用函数platform_add_devices向Linux系统中添加虚拟声卡,之 后可以调用platform_device_register()进行对虚拟声卡进行注册,对于虚拟声卡Codec设备来说,只需要定义名称和ID标识符就可以。Based on the resource information, you can define platform_device. After defining the platform_device structure, you can call the function platform_add_devices to add a virtual sound card to the Linux system. The virtual sound card can be registered by calling platform_device_register(). For the virtual sound card Codec device, only the name and ID identifier need to be defined.
调用platform_add_devices添加了虚拟声卡以及虚拟声卡Codec设备成功之后,虚拟声卡以及虚拟声卡Codec就会添加到Linux系统的设备链表中。After calling the platform_add_devices to add the virtual sound card and the virtual sound card Codec device successfully, the virtual sound card and the virtual sound card Codec will be added to the Linux system's device list.
Linux内核中的soc_new_pcm函数会调用为虚拟声卡申请内存空间的函数,这个地址空间用来记录混音处理后的数据,在DMA的中断回调函数中,将混音处理过的内存缓冲区对应的物理地址配置给DMA,用来进行混音播放,而混音处理基于tasklet完成,tasklet每次读取DMA搬运来的麦克风数据和应用层下发的背景音乐进行混音处理,处理录制和播放的数据大小目前是每次处理1K的数据,混音后的数据也是1K。The soc_new_pcm function in the Linux kernel will call the function that requests the memory space for the virtual sound card. This address space is used to record the data after the mixing process. In the DMA interrupt callback function, the physics corresponding to the memory buffer processed by the mix is processed. The address is allocated to the DMA for mixing playback, and the mixing processing is completed based on the tasklet. The tasklet reads the DMA-transferred microphone data and the background music sent by the application layer for the mixing process, and processes the recorded and played data. The size is currently 1K of data per processing, and the data after mixing is also 1K.
当完成上述步骤时,用户可以通过读写/dev/snd/pcmC2D0p进行混音播放,可以通过dev/snd/pcmC2D0c进行混音录制。When the above steps are completed, the user can play back the mix by reading and writing /dev/snd/pcmC2D0p, and the mix can be recorded by dev/snd/pcmC2D0c.
经实际测试,基于本发明实施例的技术方案混音播放的耳返时间较减少至60ms,可以满足产品的需求。After the actual test, the ear return time of the mixing scheme based on the technical solution of the embodiment of the present invention is reduced to 60 ms, which can meet the demand of the product.
本发明实施例还记载一种计算机存储介质,所述计算机存储介质中存储有可执行指令,所述可执行指令用于执行图1或图2所示的音频处理方法。The embodiment of the invention further describes a computer storage medium, wherein the computer storage medium stores executable instructions, and the executable instructions are used to execute the audio processing method shown in FIG. 1 or FIG.
本发明实施例记载一种基于Linux内核的音频处理设备,基于运行的Linux内核在内核层面进行混音处理,如图8所示,设备包括:The embodiment of the invention describes an audio processing device based on the Linux kernel, which performs mixing processing at the kernel level based on the running Linux kernel. As shown in FIG. 8, the device includes:
缓冲区单元100,配置为为直接内存读取DMA缓冲区分配内存空间,所述DMA缓冲区包括混音播放缓冲区和混音录制缓冲区;The buffer unit 100 is configured to allocate a memory space for the direct memory read DMA buffer, where the DMA buffer includes a mix play buffer and a mix recording buffer;
软中断声明单元200,配置为声明处理混音的软中断的名称以及对应的处理函数;a soft interrupt declaration unit 200 configured to declare a name of a soft interrupt for processing a mix and a corresponding processing function;
软中断处理单元300,配置为在混音的软中断中获取播放缓冲区地址和 录制缓冲区地址,调用混音处理函数进行混音处理,将处理混音后的数据保存在所述混音播放缓冲区。Soft interrupt processing unit 300, configured to acquire a play buffer address and a soft interrupt in the mix Record the buffer address, call the mix processing function to perform the mixing process, and save the processed data in the mix play buffer.
作为一个示例,参见图9,所述设备还包括:As an example, referring to FIG. 9, the device further includes:
混音播放处理单元400,与软中断处理单元300连接,配置为将所述混音播放缓冲区的地址赋值给DMA功能指针的源地址;The mixing playback processing unit 400 is connected to the soft interrupt processing unit 300, and configured to assign an address of the sound mixing buffer to a source address of the DMA function pointer;
所述混音播放缓冲区的地址用于支持所述DMA功能从所述混音播放缓冲区的地址数据到虚拟声卡的先入先出FIFO队列。The address of the mix play buffer is used to support the DMA function from the address data of the mix play buffer to the first in first out FIFO queue of the virtual sound card.
作为一个示例,参见图9,所述设备还包括:As an example, referring to FIG. 9, the device further includes:
混音录制处理单元500,与软中断处理单元300连接,配置为在DMA功能的中断回调函数中,将所述混音播放缓冲区的数据拷贝到所述混音录制缓冲区中,所述混音录制缓冲区用于支持应用层通过打开虚拟声卡读取混音后的音频数据。The sound recording processing unit 500 is connected to the soft interrupt processing unit 300, and configured to copy the data of the sound mixing buffer into the sound recording buffer in the interrupt callback function of the DMA function, the mixing The tone recording buffer is used to support the application layer to read the mixed audio data by turning on the virtual sound card.
作为一个示例,参见图9,所述设备还包括:As an example, referring to FIG. 9, the device further includes:
注册单元600,与缓冲区单元100连接,用于在所述缓冲区单元100内存空间分配混音播放缓冲区和混音录制缓冲区之前,执行以下操作;注册虚拟声卡驱动和虚拟声卡;注册平台设备和平台设备驱动;注册编解码器Codec设备、Codec驱动和Codec数字音频接口DAI。The registration unit 600 is connected to the buffer unit 100, and configured to perform the following operations before registering the sound mixing buffer and the mixing recording buffer in the memory space of the buffer unit 100; registering the virtual sound card driver and the virtual sound card; Device and platform device drivers; registered codec Codec devices, Codec drivers and Codec digital audio interfaces DAI.
作为一个示例,所述缓冲区单元100还配置为为所述DMA缓冲区分配内存空间正常播放缓冲区,所述正常播放缓冲区用于支持应用层通过打开虚拟声卡写入需要播放的音频数据;As an example, the buffer unit 100 is further configured to allocate a memory space normal play buffer for the DMA buffer, and the normal play buffer is used to support the application layer to write audio data to be played by opening the virtual sound card;
所述缓冲区单元100还配置为为所述DMA缓冲区分配正常录制缓冲区,所述正常录制缓冲区用于支持应用层通过打开所述虚拟声卡读取麦克风输入的原始音频数据。The buffer unit 100 is further configured to allocate a normal recording buffer to the DMA buffer, and the normal recording buffer is configured to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
上述各单元均为虚拟的功能单元,实际应用中可以由ASoC如机顶盒中的处理器(如ARM处理器)、逻辑可编程门阵列(FPGA)或专用集成电 路(ASIC)实现。Each of the above units is a virtual functional unit, and the actual application can be implemented by an ASoC such as a processor in a set top box (such as an ARM processor), a logic programmable gate array (FPGA), or a dedicated integrated power supply. Road (ASIC) implementation.
本发明实施例还提供一种计算机存储介质,所述计算机存储介质中存储有可执行指令,所述可执行指令用于执行本发明实施例记载的音频处理方法。The embodiment of the invention further provides a computer storage medium, wherein the computer storage medium stores executable instructions, and the executable instructions are used to execute the audio processing method described in the embodiment of the invention.
本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、随机存取存储器(RAM,Random Access Memory)、只读存储器(ROM,Read-Only Memory)、磁碟或者光盘等各种可以存储程序代码的介质。A person skilled in the art can understand that all or part of the steps of implementing the above method embodiments may be completed by using hardware related to the program instructions. The foregoing program may be stored in a computer readable storage medium, and the program is executed when executed. The foregoing storage medium includes: a mobile storage device, a random access memory (RAM), a read-only memory (ROM), a magnetic disk, or an optical disk. A medium that can store program code.
或者,本发明上述集成的单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明实施例的技术方案本质上或者说对相关技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机、服务器、或者网络设备等)执行本发明各个实施例所述方法的全部或部分。而前述的存储介质包括:移动存储设备、RAM、ROM、磁碟或者光盘等各种可以存储程序代码的介质。Alternatively, the above-described integrated unit of the present invention may be stored in a computer readable storage medium if it is implemented in the form of a software function module and sold or used as a standalone product. Based on such understanding, the technical solution of the embodiments of the present invention may be embodied in the form of a software product in essence or in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for making A computer device (which may be a personal computer, server, or network device, etc.) performs all or part of the methods described in various embodiments of the present invention. The foregoing storage medium includes various media that can store program codes, such as a mobile storage device, a RAM, a ROM, a magnetic disk, or an optical disk.
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。 The above is only a specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily think of changes or substitutions within the technical scope of the present invention. It should be covered by the scope of the present invention. Therefore, the scope of the invention should be determined by the scope of the appended claims.

Claims (11)

  1. 一种音频处理方法,所述方法包括:An audio processing method, the method comprising:
    为直接内存读取DMA缓冲区分配内存空间,所述DMA缓冲区包括混音播放缓冲区和混音录制缓冲区;Allocating a memory space for the direct memory read DMA buffer, the DMA buffer including a mix play buffer and a mix recording buffer;
    声明处理混音的软中断的名称以及对应的处理函数;Declare the name of the soft interrupt handling the mix and the corresponding handler function;
    在混音的软中断中获取播放缓冲区地址和录制缓冲区地址,调用混音处理函数进行混音处理,将处理混音后的数据保存在所述混音播放缓冲区。The play buffer address and the recording buffer address are obtained in the soft interrupt of the mix, the mix processing function is called to perform the mixing process, and the processed mixed data is saved in the mix play buffer.
  2. 如权利要求1所述的方法,其中,所述方法还包括:The method of claim 1 wherein the method further comprises:
    将所述混音播放缓冲区的地址赋值给DMA功能指针的源地址;Assigning the address of the mix play buffer to the source address of the DMA function pointer;
    所述混音播放缓冲区的地址配置为支持所述DMA功能从所述混音播放缓冲区的地址数据到虚拟声卡的先入先出FIFO队列。The address of the mix play buffer is configured to support the DMA function from the address data of the mix play buffer to the first in first out FIFO queue of the virtual sound card.
  3. 如权利要求1所述的方法,其中,所述方法还包括:The method of claim 1 wherein the method further comprises:
    在DMA功能的中断回调函数中,将所述混音播放缓冲区的数据拷贝到所述混音录制缓冲区中,所述混音录制缓冲区用于支持应用层通过打开虚拟声卡读取混音后的音频数据。In the interrupt callback function of the DMA function, the data of the sound mixing buffer is copied into the sound recording buffer, and the sound recording buffer is used to support the application layer to read the sound by opening the virtual sound card. After the audio data.
  4. 如权利要求1所述的方法,其中,在内存空间分配混音播放缓冲区和混音录制缓冲区之前,所述方法还包括:The method of claim 1 wherein prior to allocating the mix play buffer and the mix recording buffer in the memory space, the method further comprises:
    注册虚拟声卡驱动和虚拟声卡;Register a virtual sound card driver and a virtual sound card;
    注册平台设备和平台设备驱动;Register platform devices and platform device drivers;
    注册编解码器Codec设备、Codec驱动和Codec数字音频接口DAI。Register codec Codec device, Codec driver and Codec digital audio interface DAI.
  5. 如权利要求1至4任一项所述的方法,其中,所述方法还包括:The method of any of claims 1 to 4, wherein the method further comprises:
    为所述DMA缓冲区分配内存空间正常播放缓冲区,所述正常播放缓冲区用于支持应用层通过打开虚拟声卡写入需要播放的音频数据;Allocating a memory space normal play buffer for the DMA buffer, wherein the normal play buffer is used to support the application layer to write audio data to be played by opening the virtual sound card;
    为所述DMA缓冲区分配正常录制缓冲区,所述正常录制缓冲区用于支持应用层通过打开所述虚拟声卡读取麦克风输入的原始音频数据。 A normal recording buffer is allocated to the DMA buffer, and the normal recording buffer is used to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
  6. 一种音频处理设备,所述设备包括:An audio processing device, the device comprising:
    缓冲区单元,配置为为直接内存读取DMA缓冲区分配内存空间,所述DMA缓冲区包括混音播放缓冲区和混音录制缓冲区;a buffer unit configured to allocate a memory space for the direct memory read DMA buffer, where the DMA buffer includes a mix play buffer and a mix recording buffer;
    软中断声明单元,声明处理混音的软中断的名称以及对应的处理函数;a soft interrupt declaration unit that declares the name of the soft interrupt that handles the mix and the corresponding handler function;
    软中断处理单元,配置为在混音的软中断中获取播放缓冲区地址和录制缓冲区地址,调用混音处理函数进行混音处理,将处理混音后的数据保存在所述混音播放缓冲区。The soft interrupt processing unit is configured to acquire a play buffer address and a recording buffer address in the soft interrupt of the mix, call a mix processing function to perform a mixing process, and save the processed data in the mix play buffer. Area.
  7. 如权利要求6所述的系统,其中,所述设备还包括:The system of claim 6 wherein said device further comprises:
    混音播放处理单元,配置为将所述混音播放缓冲区的地址赋值给DMA功能指针的源地址;a mixing playback processing unit configured to assign an address of the sound mixing buffer to a source address of a DMA function pointer;
    所述混音播放缓冲区的地址用于支持所述DMA功能从所述混音播放缓冲区的地址数据到虚拟声卡的先入先出FIFO队列。The address of the mix play buffer is used to support the DMA function from the address data of the mix play buffer to the first in first out FIFO queue of the virtual sound card.
  8. 如权利要求6所述的系统,其中,所述设备还包括:The system of claim 6 wherein said device further comprises:
    混音录制处理单元,配置为在DMA功能的中断回调函数中,将所述混音播放缓冲区的数据拷贝到所述混音录制缓冲区中,所述混音录制缓冲区用于支持应用层通过打开虚拟声卡读取混音后的音频数据。a sound recording processing unit configured to copy data of the sound mixing buffer into the sound recording buffer in an interrupt callback function of the DMA function, wherein the sound recording buffer is used to support an application layer Read the mixed audio data by turning on the virtual sound card.
  9. 如权利要求6所述的系统,其中,所述设备还包括:The system of claim 6 wherein said device further comprises:
    注册单元,配置为在所述缓冲区单元内存空间分配混音播放缓冲区和混音录制缓冲区之前,执行以下操作;注册虚拟声卡驱动和虚拟声卡;注册平台设备和平台设备驱动;注册编解码器Codec设备、Codec驱动和Codec数字音频接口DAI。a registration unit configured to perform the following operations before the allocation of the mix play buffer and the mix recording buffer in the buffer unit memory space; registering the virtual sound card driver and the virtual sound card; registering the platform device and the platform device driver; registering the codec Codec device, Codec driver and Codec digital audio interface DAI.
  10. 如权利要求6至9任一项所述的系统,其中,A system according to any one of claims 6 to 9, wherein
    所述缓冲区单元还配置为为所述DMA缓冲区分配内存空间正常播放缓冲区,所述正常播放缓冲区用于支持应用层通过打开虚拟声卡写入需要播放的音频数据; The buffer unit is further configured to allocate a memory space normal play buffer for the DMA buffer, where the normal play buffer is used to support the application layer to write audio data to be played by opening the virtual sound card;
    所述缓冲区单元还用于为为所述DMA缓冲区分配正常录制缓冲区,所述正常录制缓冲区用于支持应用层通过打开所述虚拟声卡读取麦克风输入的原始音频数据。The buffer unit is further configured to allocate a normal recording buffer for the DMA buffer, and the normal recording buffer is configured to support the application layer to read the original audio data input by the microphone by opening the virtual sound card.
  11. 一种计算机存储介质,所述计算机存储介质中存储有可执行指令,所述可执行指令配置为执行权利要求1至5任一项所述的音频处理方法。 A computer storage medium having executable instructions stored therein, the executable instructions being configured to perform the audio processing method of any one of claims 1 to 5.
PCT/CN2016/076802 2015-07-03 2016-03-18 Audio processing method and device, and computer storage medium WO2017005010A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510390087.2 2015-07-03
CN201510390087.2A CN106325804B (en) 2015-07-03 2015-07-03 Audio-frequency processing method and system

Publications (1)

Publication Number Publication Date
WO2017005010A1 true WO2017005010A1 (en) 2017-01-12

Family

ID=57684848

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/076802 WO2017005010A1 (en) 2015-07-03 2016-03-18 Audio processing method and device, and computer storage medium

Country Status (2)

Country Link
CN (1) CN106325804B (en)
WO (1) WO2017005010A1 (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109600691A (en) * 2017-09-30 2019-04-09 深圳市魅鸟科技有限公司 A kind of vehicle intelligent WiFi microphone and its audio delay processing method
CN112615853A (en) * 2020-12-16 2021-04-06 瑞芯微电子股份有限公司 Android device audio data access method
CN112988249A (en) * 2021-03-23 2021-06-18 上海摩勤智能技术有限公司 Method and device for creating sound card, electronic equipment and storage medium
CN113409808A (en) * 2021-06-18 2021-09-17 上海盈方微电子有限公司 Echo cancellation time delay estimation method and echo cancellation method
CN113965844A (en) * 2021-12-22 2022-01-21 深圳市维海德技术股份有限公司 Low-delay audio transmission method and device, driving equipment and readable storage medium

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107483731A (en) * 2017-08-18 2017-12-15 广东欧珀移动通信有限公司 Control method, device and the storage medium and mobile terminal of audio broadcast sound volume
CN107992282B (en) * 2017-11-29 2020-11-03 珠海市魅族科技有限公司 Audio data processing method and device, computer device and readable storage device
CN110096250B (en) * 2018-01-31 2020-05-29 北京金山云网络技术有限公司 Audio data processing method and device, electronic equipment and storage medium
CN109462796A (en) * 2018-10-25 2019-03-12 歌尔股份有限公司 A kind of audio processing system and audio frequency apparatus
CN109348297B (en) * 2018-11-28 2021-03-23 湖南快乐阳光互动娱乐传媒有限公司 Data acquisition method and device
CN110007975B (en) * 2019-04-02 2021-11-12 思必驰科技股份有限公司 Sound card self-adaptive loading method and system
CN111586529A (en) * 2020-05-08 2020-08-25 北京三体云联科技有限公司 Audio data processing method, device, terminal and computer readable storage medium
CN111654743B (en) * 2020-05-27 2022-04-22 海信视像科技股份有限公司 Audio playing method and display device
CN113038238B (en) * 2021-03-22 2023-07-07 格兰菲智能科技有限公司 Transmission stream data code recording system and transmission stream data code recording method
CN113282271A (en) * 2021-07-22 2021-08-20 北京麟卓信息科技有限公司 Audio processing method and device for android application on Linux platform

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060010267A1 (en) * 2001-05-18 2006-01-12 Jorge Abullarade Method and apparatus for playing analog audio to multiple codec outputs
CN101661748A (en) * 2009-09-15 2010-03-03 福州瑞芯微电子有限公司 Method for realizing audio mixing in audio device
US20130212341A1 (en) * 2012-02-15 2013-08-15 Microsoft Corporation Mix buffers and command queues for audio blocks
CN103578512A (en) * 2013-10-18 2014-02-12 三星电子(中国)研发中心 Method and device for rapidly playing back records
CN104637488A (en) * 2013-11-07 2015-05-20 华为终端有限公司 Sound processing method and terminal device

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN100511154C (en) * 2006-09-05 2009-07-08 中兴通讯股份有限公司 Audio driver sound management method
KR20120108570A (en) * 2011-03-24 2012-10-05 삼성전자주식회사 Audio device, and method of operating the same

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060010267A1 (en) * 2001-05-18 2006-01-12 Jorge Abullarade Method and apparatus for playing analog audio to multiple codec outputs
CN101661748A (en) * 2009-09-15 2010-03-03 福州瑞芯微电子有限公司 Method for realizing audio mixing in audio device
US20130212341A1 (en) * 2012-02-15 2013-08-15 Microsoft Corporation Mix buffers and command queues for audio blocks
CN103578512A (en) * 2013-10-18 2014-02-12 三星电子(中国)研发中心 Method and device for rapidly playing back records
CN104637488A (en) * 2013-11-07 2015-05-20 华为终端有限公司 Sound processing method and terminal device

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109600691A (en) * 2017-09-30 2019-04-09 深圳市魅鸟科技有限公司 A kind of vehicle intelligent WiFi microphone and its audio delay processing method
CN112615853A (en) * 2020-12-16 2021-04-06 瑞芯微电子股份有限公司 Android device audio data access method
CN112988249A (en) * 2021-03-23 2021-06-18 上海摩勤智能技术有限公司 Method and device for creating sound card, electronic equipment and storage medium
CN112988249B (en) * 2021-03-23 2024-05-28 上海摩勤智能技术有限公司 Method and device for creating sound card, electronic equipment and storage medium
CN113409808A (en) * 2021-06-18 2021-09-17 上海盈方微电子有限公司 Echo cancellation time delay estimation method and echo cancellation method
CN113409808B (en) * 2021-06-18 2024-05-03 上海盈方微电子有限公司 Echo cancellation time delay estimation method and echo cancellation method
CN113965844A (en) * 2021-12-22 2022-01-21 深圳市维海德技术股份有限公司 Low-delay audio transmission method and device, driving equipment and readable storage medium

Also Published As

Publication number Publication date
CN106325804B (en) 2019-05-31
CN106325804A (en) 2017-01-11

Similar Documents

Publication Publication Date Title
WO2017005010A1 (en) Audio processing method and device, and computer storage medium
US11861203B2 (en) Method, apparatus and electronic device for cloud service migration
US8738884B2 (en) Efficient loading of data into memory of a computing system
WO2019127114A1 (en) Audio playback method for virtual machine and device thereof, and mobile terminal
US20140029764A1 (en) Virtual machine-based sound control for computerized devices in a networked computing environment
CN114302040B (en) Method for sharing single camera by multiple applications and related products
CN104104705B (en) The cut-in method and equipment of distributed memory system
WO2023179388A1 (en) Hot migration method for virtual machine instance
US20230336624A1 (en) Persistent storage overlay
CN110058946A (en) Device virtualization method, apparatus, equipment and storage medium
CN116774933A (en) Virtualization processing method of storage device, bridging device, system and medium
CN112087471A (en) Data transmission method and FPGA cloud platform
US20140157289A1 (en) Hybrid platform-dependent simulation interface
CN109739487B (en) Business logic processing method and device and computer readable storage medium
US10585730B1 (en) Enqueue-related processing based on timing out of an attempted enqueue
WO2017054379A1 (en) Audio data processing method, apparatus and system
WO2017166036A1 (en) Method and device for resource statistics, and terminal
US7788463B2 (en) Cyclic buffer management
CN110096355B (en) Shared resource allocation method, device and equipment
CA3157242A1 (en) Capability management method and computer device
CN111314493A (en) Data processing method of heterogeneous cloud storage system and readable medium and system thereof
JP2015185103A (en) Storage device, information processing device, data access method and program
CN115297169B (en) Data processing method, device, electronic equipment and medium
CN113094320B (en) Parallel message arbitration device and method
US10990439B1 (en) Tracing task execution across services in microkernel-based operating systems

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16820665

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16820665

Country of ref document: EP

Kind code of ref document: A1