Audio routing management method, system and electronic device
By constructing audio track lines in the Linux ALSA sound card architecture and using shared memory and ring buffers to process audio data, the problems of data out-of-synchronization and poor compatibility are solved, real-time performance and compatibility are improved, development complexity is reduced, and development efficiency is improved. Customer experience and economic benefits.
Patent Information
- Application Number
- CN202210943846.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-04
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2042-08-04
AI Technical Summary
The existing Linux ALSA sound card architecture has problems such as data asynchronousness, low real-time performance, high software development complexity, low reusability and unreasonable routing management during mixing processing, resulting in high device-side delay and poor compatibility.
By building audio track lines, including acquisition track nodes, playback track nodes and mixing nodes, and using shared memory and ring buffers for data processing and synchronization, multi-channel audio data can be separated and merged to improve the real-time performance of audio data. and compatibility.
It improves the real-time performance of intercoms, improves customer experience, enhances software reusability and audio device compatibility, reduces software development complexity, and improves economic benefits.
Smart Images

Figure CN115312072B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of audio processing, and in particular to an audio routing management method, system and electronic equipment. Background Art
[0002] In the existing Linux ALSA sound card architecture, when audio data from different devices are mixed and processed, problems such as data asynchrony, low real-time performance, high software development complexity, low reusability, and unreasonable routing management usually occur. Summary of the invention
[0003] In view of the above defects, the embodiments of the present invention disclose an audio routing management method, system and electronic device, which solve the problems of high device-side delay and poor compatibility of device-side software with different audio devices during real-time intercom, improve the real-time performance of intercom, enhance customer experience, improve software reusability and audio device compatibility, reduce software development complexity and improve economic benefits.
[0004] A first aspect of an embodiment of the present invention discloses an audio routing management method, the method comprising:
[0005] Determine a target audio output device and a target audio input device that sends audio data to the target audio output device;
[0006] Constructing an audio track circuit based on the target audio output device and the target audio input device, each audio track circuit including at least one acquisition audio track node, at least one playback audio track node and one mixing node;
[0007] Write the audio data collected by the target audio input device into the collection track node;
[0008] The audio data written into the acquisition track node is read and recorded as the first audio data, and all the first audio data are mixed and written into the playback track node;
[0009] The audio data written into the playback track node is read and recorded as the second audio data, and the second audio data is sent to the target audio output device.
[0010] As an optional implementation, in the first aspect of the embodiment of the present invention, when one or more of the target audio input devices has a multi-channel audio source, the audio data of each channel is obtained through a multi-channel audio source separation mechanism, and the audio data of each channel is written into the corresponding acquisition track node.
[0011] As an optional implementation, in the first aspect of the embodiment of the present invention, when there are multiple acquisition track nodes:
[0012] resampling the first audio data;
[0013] or / and,
[0014] Taking any collected audio track node as the synchronization source, all first audio data are synchronized.
[0015] As an optional implementation, in the first aspect of the embodiment of the present invention, when the target audio output device receives multiple second audio data, the multiple second audio data are merged through a multi-channel audio merging mechanism and then sent to the target audio output device.
[0016] As an optional implementation, in the first aspect of the embodiment of the present invention, any playback audio track node is used as the synchronization source, all second audio data received by the target audio output device are synchronized, and then the multiple second audio data are merged through a multi-channel audio merging mechanism and sent to the target audio output device.
[0017] As an optional implementation, in the first aspect of the embodiment of the present invention, a shared memory area is created for each target audio track node, and a circular buffer is constructed in the shared memory area using the data structure of the queue; a write subscript and a read subscript are set for each target audio track node, wherein when audio data with a length of L1 is written to the target audio track node, the value of the write subscript is increased by L1, and when audio data with a length of L2 is read from the target audio track node, the value of the read subscript is increased by L2; the target audio track node is a collection audio track node or a playback audio track node.
[0018] As an optional implementation, in a first aspect of an embodiment of the present invention, a method for writing audio data into a target track node includes:
[0019] Based on the values of WritePos and (WritePos+WriteSize)%RingSize, determine whether the write subscript exceeds the boundary after adding the audio data to be written, where WritePos is the value of the write subscript, WriteSize is the length of the audio data to be written, and RingSize is the size of the ring buffer;
[0020] If WritePos is less than (WritePos+WriteSize)%RingSize, the audio data to be written is directly written into the ring buffer, and the length of the write subscript is updated: WritePos=(WritePos+WriteSize)%RingSize;
[0021] If WritePos is greater than (WritePos+WriteSize)%RingSize, the audio data to be written is divided into first audio data to be written and second audio data to be written in chronological order, wherein the length of the first audio data to be written is (RingSize-WritePos), and the length of the second audio data to be written is WriteSize-(RingSize-WritePos); the first audio data to be written is first written into the ring buffer, and then the second audio data to be written is written into the ring buffer, and finally the length of the write subscript is updated: WritePos=(WritePos+WriteSize)%RingSize.
[0022] As an optional implementation manner, in a first aspect of an embodiment of the present invention, a method for reading audio data in the target track node includes:
[0023] Based on the size of WritePos and ReadPos, determine whether there is a boundary in the audio data to be read, where WritePos is the value of the write subscript and ReadPos is the value of the read subscript;
[0024] If WritePos is greater than ReadPos, the audio data to be read is directly read, and the read subscript is updated: ReadPos = (ReadPos + ReadSize) % RingSize, where ReadSize is the length of the audio data to be read, and RingSize is the size of the ring buffer;
[0025] If WritePos is less than ReadPos, the audio data to be read is divided into the first audio data to be read and the second audio data to be read in chronological order, wherein the length of the first audio data to be read is (RingSize-ReadPos), and the length of the second audio data to be read is ReadSize-(RingSize-ReadPos); first read the first audio data to be written from the ring buffer, and then read the second audio data to be written from the ring buffer, and finally update the length of the read subscript: ReadPos=(ReadPos+ReadSize)%RingSize.
[0026] A second aspect of an embodiment of the present invention discloses an audio routing management system, which includes:
[0027] a determining unit, configured to determine a target audio output device and a target audio input device to send audio data to the target audio output device;
[0028] A creation unit, configured to construct a track line based on the target audio output device and the target audio input device, each track line comprising at least one acquisition track node, at least one playback track node and one mixing node;
[0029] A first processing unit, configured to write the audio data collected by the target audio input device into a collection track node;
[0030] A mixing unit is used to read the audio data written into the acquisition track node, recorded as the first audio data, and write all the first audio data into the playback track node after mixing;
[0031] The second processing unit is used to read the audio data written into the playback track node, record it as the second audio data, and send the second audio data to the target audio output device.
[0032] A third aspect of an embodiment of the present invention discloses an electronic device, comprising: a memory storing executable program code; a processor coupled to the memory; the processor calls the executable program code stored in the memory to execute an audio routing management method disclosed in the first aspect of the embodiment of the present invention.
[0033] A fourth aspect of an embodiment of the present invention discloses a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute an audio routing management method disclosed in the first aspect of an embodiment of the present invention.
[0034] A fifth aspect of an embodiment of the present invention discloses a computer program product. When the computer program product is run on a computer, the computer executes an audio routing management method disclosed in the first aspect of an embodiment of the present invention.
[0035] A sixth aspect of an embodiment of the present invention discloses an application publishing platform, which is used to publish a computer program product. When the computer program product runs on a computer, the computer executes an audio routing management method disclosed in the first aspect of an embodiment of the present invention.
[0036] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0037] In the embodiment of the present invention, the present invention solves the problem of high device-side delay and poor compatibility of device-side software with different audio devices during real-time intercom by constructing an audio track line, thereby improving the real-time performance of intercom and enhancing customer experience; at the same time, it improves software reusability and audio device compatibility, reduces software development complexity, and improves economic benefits. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technical personnel in this field, other drawings can be obtained based on these drawings without creative work.
[0039] Figure 1 is a schematic diagram of a virtual sound card queue disclosed in an embodiment of the present invention;
[0040] Figure 2 It is a flowchart of an audio routing management method disclosed in an embodiment of the present invention;
[0041] Figure 3 It is a structural diagram of the audio track acquisition node disclosed in an embodiment of the present invention;
[0042] Figure 4 is a schematic diagram of the structure of a playback track node disclosed in an embodiment of the present invention;
[0043] Figure 5 is a schematic diagram of audio routing in an intercom scenario disclosed in an embodiment of the present invention;
[0044] Figure 6 is a schematic diagram of an audio routing for initiating a broadcast scenario disclosed in an embodiment of the present invention;
[0045] Figure 7 It is a schematic diagram of audio routing in a Bluetooth intercom scenario disclosed in an embodiment of the present invention;
[0046] Figure 8 It is a flowchart of the operation of writing a track node disclosed in an embodiment of the present invention;
[0047] Fig. 9 It is a flowchart of the audio track node reading operation disclosed in an embodiment of the present invention;
[0048] Fig.10 It is an example of a routing diagram disclosed in an embodiment of the present invention;
[0049] Fig.11 is a schematic diagram of audio transmission of an audio routing disclosed in an embodiment of the present invention;
[0050] Fig.12 is a flow chart of audio transmission of audio routing disclosed in an embodiment of the present invention;
[0051] Fig.13 is a structural block diagram of an audio routing management system disclosed in an embodiment of the present invention;
[0052] Fig.14is an architecture diagram of an audio routing management system disclosed in an embodiment of the present invention;
[0053] Fig.15 This is a structural block diagram of an electronic device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0054] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technical personnel in the field without creative work are within the scope of protection of the present invention.
[0055] It should be noted that the terms "first", "second", "third", "fourth", etc. in the specification and claims of the present invention are used to distinguish different objects rather than to describe a specific order. The terms "including" and "having" in the embodiments of the present invention and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0056] The embodiment of the present invention is based on ALSA (Advanced Linux Sound Architecture), introduces Linux system inter-process communication, logical relationship of linked lists, multi-threaded processing and other technologies, realizes an audio routing management method, system and electronic device, optimizes the routing management of multiple audio data sources in the real-time intercom system, so as to achieve the advantages of high real-time audio transmission, high application reusability, intelligent mixing, etc. The problem of high device-side delay and poor compatibility of device-side software with different audio devices in the real-time intercom process is solved, the real-time performance of the intercom is improved, and the customer experience is enhanced; at the same time, the software reusability and audio device compatibility are improved, the complexity of software development is reduced, and the economic benefits are improved. The following is a detailed description with reference to the accompanying drawings.
[0057] Glossary:
[0058] Virtual sound card: abstracts various devices or data streams with audio input or output functions into a virtual sound card. The audio properties of the virtual sound card include the number of channels opened by the sound card, sampling rate, quantization accuracy, number of bytes per sample, etc.
[0059] The device-side audio codec is abstracted as the local sound card, the external Bluetooth headset device is abstracted as the Bluetooth sound card, the device-side WiFi chip is abstracted as the WiFi sound card, the Ethernet audio data stream is abstracted as the network sound card, etc. The linked list data structure is used to add different virtual sound cards to the sound card queue (such as Figure 1 ), the virtual sound card can be quickly inserted and accessed, and the fastest insertion and access time complexity can reach O(1).
[0060] Track node: An audio stream of a virtual sound card is abstracted as a track node.
[0061] Track circuit: The processing method for multiple track node links is abstracted as a track circuit.
[0062] Sound card beat: A hardware feature of the Linux sound card. The time it takes to read audio data of the same length and properties from the Linux system sound card is fixed.
[0063] Embodiment 1
[0064] See also Figure 2 , Figure 2 1 is a flow chart of an audio routing management method disclosed in an embodiment of the present invention. The method described in the embodiment of the present invention is applicable to the Linux ALSA sound card architecture. Figure 2 As shown, the audio routing management method includes the following steps:
[0065] S110: Determine a target audio output device and a target audio input device that sends audio data to the target audio output device.
[0066] The target audio output device is a sound card device that outputs audio data, which can be a local sound card, a Bluetooth sound card, a wifi sound card, a network sound card, or other virtual sound cards. The target audio input device is one or more virtual sound cards of the same or different types, which are used to collect audio data and send it to the target audio output device through the corresponding link for real-time playback or playback.
[0067] The link can be set according to the number of all audio output devices and audio input devices to form a link data table. After the target audio output device and the target audio input device are determined, the audio track link between the two is formed. The audio track link can be manually selected or automatically generated by the link data table and the corresponding logic.
[0068] S120, constructing an audio track line based on the target audio output device and the target audio input device, each audio track line including at least one acquisition audio track node, at least one playback audio track node and one mixing node.
[0069] The track line is the track link mentioned above. In the track link, it includes at least one acquisition track node, at least one playback track node and one mixing node.
[0070] The data processing process of each track node (acquisition track node or playback track node) is the reading and writing of shared memory. Shared memory is the fastest inter-process communication method in Linux system, so it can maximize the real-time performance of audio data.
[0071] Please refer to Figure 3 As shown, a shared memory area is created for a collection track node, and a circular buffer is constructed in the shared memory area using a queue data structure (the circular buffer is recorded as a collection track node). The process of writing the data collected by the virtual sound card to the collection track node represents the collection track node write operation; reading data from the collection track node (D001) represents the collection track node read operation. During the read and write operations of all collection track nodes, it is necessary to determine whether it is readable and writable by writing and reading the subscript, and at the same time, it is necessary to refer to the synchronization signal for data alignment processing.
[0072] Similarly, please refer to Figure 4 As shown, a shared memory area is created for a playback track node, and a circular buffer is constructed in the shared memory area using a queue data structure (the circular buffer is recorded as a playback track node). The process of writing audio data (D001) to the corresponding playback track node represents the write operation of the playback track node; the process of reading data from the playback track node and then mixing it and sending it to the playback track represents the read operation of the playback track node. During the read and write operations of all playback track nodes, it is necessary to determine whether it is readable and writable by writing and reading the subscript, and at the same time, it is necessary to refer to the synchronization signal for data alignment processing.
[0073] When one or more of the target audio input devices has a multi-channel audio source, the audio data of each channel is obtained through the multi-channel audio source separation mechanism, and the audio data of each channel is written into the corresponding acquisition track node.
[0074] When multiple audio output devices correspond to the same target audio input device, these audio output devices can supply the same track line (different audio output devices only correspond to different playback track nodes).
[0075] After setting the audio track line according to product requirements, the audio routing is set. The collection of several audio track lines represents the audio route. Each time a track line is created, a thread is created, and the two are in a one-to-one correspondence. Each thread will process the audio data on the track line at a fixed time interval through the corresponding sound card beat, that is, collect audio data from the target input device and write it into the acquisition sound card track node, and then send the audio data to the mixing node for resampling, echo cancellation, EQ, DRC, mixing and other processing, and finally send the audio data to the playback track node to play it from the corresponding device.
[0076] The track circuit links all track nodes through a linked list, and the track nodes can be quickly accessed when creating, searching, deleting track nodes, etc. If the system resources are sufficient, the track circuit can be expanded arbitrarily, and the track nodes in the track circuit can also be expanded arbitrarily.
[0077] The audio routing in the intercom scenario is as follows Figure 5 As shown, audio track line 1 processes the audio data uploaded by the local machine to the network end (uplink), and audio track line 2 processes the audio data transmitted from the network to the local machine (downlink).
[0078] The audio routing in the broadcast scenario is as follows Figure 6 As shown, track line 1 processes upstream audio data.
[0079] When using Bluetooth or other input and output sound card devices, the following scenarios are used: Figure 7 As shown in the figure, track line 1 processes the uplink audio data, and track line 2 processes the downlink audio data.
[0080] S130, writing the audio data collected by the target audio input device into the collected audio track node.
[0081] The location where the start and end of the shared memory in the ring buffer are connected is the memory boundary. Boundary copy problems may occur when audio data is copied (written or read). In order to solve this problem, the concepts of write subscript and read subscript are introduced. When writing audio data of length L1 to a track node (acquisition track node or playback track node), the write subscript increases the length of L1. Correspondingly, when reading audio data of length L2 from a track node, the read subscript increases the length of L2.
[0082] Please refer to Figure 8 As shown, writing audio data into the capture track node includes the following steps:
[0083] S001. Determine whether the synchronization signal is acquired. If acquired, execute step S004. Otherwise, execute step S002.
[0084] The acquisition of synchronization signal is to use the beat of any target sound card as the synchronization source, synchronize the signal of the virtual sound card (recorded as the sound card to be synchronized) to be written to the acquisition track node, set the sampling rate of the sound card to be synchronized to Ra, the cumulative number of local trigger sampling to Tc; the target sampling rate is Rd, the cumulative number of target sampling is Ds, the target sampling length is Sz, and the last target cumulative sampling technology is Sc. The synchronization process includes the following steps:
[0085] 1. The number of trigger samples increases: Tc = Tc + Sz;
[0086] 2. Target cumulative sampling number: Ds = Tc*Rd / Ra;
[0087] 3. Current filling sampling number: Ds = Ds – Sc;
[0088] 4. The signal trigger sampling number increases Sc=Sc+Ds.
[0089] Assuming that the sampling rate of the synchronization source is 48K and 20ms of data is collected at a time, the number of samples is: 48000 / 50=960; assuming that the audio source to be synchronized is a file input with a sampling rate of 8k, the collection interval also needs to be 20ms, and the corresponding number of file audio samples is: 8000 / 50=160.
[0090] A0: Synchronous source sampling cumulative number = 0 (initial state)
[0091] First signal
[0092] A11: The cumulative number of synchronous source samples = the cumulative number of local samples + 960 = 0 + 960 = 960;
[0093] A12: Number of file samples = result of step A11 * file sampling rate / local sound card sampling rate = 960 * 8000 / 48000 = 160;
[0094] A13: Current file sampling number = cumulative file sampling number in step A12 = 160-0 = 160;
[0095] A14: The cumulative number of sampled files = the cumulative number of sampled files + the result of step A13 = 160 + 0;
[0096] Second signal
[0097] A21: The cumulative number of samples collected by this machine = the cumulative number of samples collected by this machine + 960 = 960 + 960 = 1920;
[0098] A22: Number of file samples = result of step A21 * file sampling rate / local sound card sampling rate = 1920 * 8000 / 48000 = 320;
[0099] A23: Current file sampling number = cumulative file sampling number in step A22 = 320-160 = 160;
[0100] A24: The cumulative number of sampled files = the cumulative number of sampled files + the result of step A23 = 160 + 160;
[0101] The third signal
[0102] A31: The total number of samples collected by this machine = the total number of samples collected by this machine + 960 (1920 + 960 = 2880)
[0103] A32: Number of file samples = result of step A31 * file sampling rate / local sound card sampling rate = 2880 * 8000 / 48000 = 480;
[0104] A33: Current file sampling number = cumulative file sampling number in step A32 = 480-320 = 160;
[0105] A34: The cumulative number of file samples = the cumulative number of file samples + the result of step A33 = 320 + 160.
[0106] The signal is sent every 20ms, and the file audio track is read and written every 20ms. The sampling number is 160 to complete synchronization with the synchronization source.
[0107] S002: Check whether the waiting timeout has occurred. If the waiting timeout has occurred, return to write length 0. Otherwise, execute step S001.
[0108] In some embodiments, if the number of waiting timeouts exceeds a threshold number, for example, 5 times, it can be considered as a synchronization failure, and synchronization operations can be performed through other synchronization sources, or a reminder message can be sent.
[0109] S003. Return the write length as 0.
[0110] S004. Based on the size of WritePos and (WritePos+WriteSize)%RingSize, determine whether the write subscript exceeds the boundary after adding the audio data to be written, where WritePos is the value of the write subscript, WriteSize is the length of the audio data to be written, and RingSize is the size of the ring buffer; if WritePos is less than (WritePos+WriteSize)%RingSize, execute step S005; otherwise, if WritePos is greater than (WritePos+WriteSize)%RingSize, execute step S006.
[0111] S005. Write the audio data to be written directly into the ring buffer, and update the length of the write subscript: WritePos=(WritePos+WriteSize)%RingSize. After writing is completed, execute step S007.
[0112] S006, dividing the audio data to be written into first audio data to be written and second audio data to be written in chronological order, wherein the length of the first audio data to be written is (RingSize-WritePos), and the length of the second audio data to be written is WriteSize-(RingSize-WritePos); first writing the first audio data to be written into the ring buffer, and then writing the second audio data to be written into the ring buffer, after writing is completed, executing step S007
[0113] S007. Update the length of the write subscript: WritePos = (WritePos + WriteSize) % RingSize.
[0114] The process of steps S004-S007 is explained and illustrated by an example:
[0115] Set the audio track sampling rate to 48000 and the ring buffer size to 48000 / 10+1; the buffer can buffer 100ms of audio data (plus 1 to prevent out-of-bounds), that is, RingSize=4801, assuming that the length of the audio data written each time (WriteSize) is 960.
[0116] 1. Initially, WritePos = 0, the length of the first audio data to be written is 960, WritePos < (WritePos + WriteSize) % RingSize, execute step S005, and update the write subscript:
[0117] WritePos=(WritePos+WriteSize)%RingSize=(0+960)%4801=960;
[0118] 2. Similarly, WritePos=960, the length of the audio data to be written for the second time is 960, and step S005 is executed to update the write subscript:
[0119] WritePos = 1920;
[0120] And so on.
[0121] 3. After writing 960 for the fifth time, execute step S005, and update and write the subscript:
[0122] WritePos = 4800;
[0123] 4. When writing 960 for the sixth time, the following appears:
[0124] WritePos = 4800;
[0125] (WritePos+WriteSize)%RingSize=(4800+960)%4801=959;
[0126] WritePos>(WritePos+WriteSize)%RingSize, then execute step S006, first write 1 (i.e. 4801-4800) length to the buffer, then write 960-1 length, and then execute step S007, WritePos=(WritePos+WriteSize)%RingSize=(4800+960)%4801=959.
[0127] The cycle continues.
[0128] S140, reading the audio data written into the acquisition track node, recording it as the first audio data, and writing all the first audio data into the playback track node after mixing.
[0129] If there are multiple acquisition track nodes, the first audio data is resampled; or / and, any acquisition track node is used as a synchronization source to synchronize all the first audio data.
[0130] The track line uses the sound card beat (synchronization source) to send synchronization signals to the track nodes without the sound card beat, which can solve the problem of audio source synchronization. When the same sound card needs to output audio with different sampling rates, the acquisition track node can output the corresponding sampling rate audio through resampling.
[0131] The synchronization method is similar to that in the above step S130, and will not be described in detail here. In the mixing node, according to the data quality of the audio data, the audio data may be subjected to echo cancellation, EQ (equalizer), DRC (dynamic compression) and other operations before mixing.
[0132] For methods to read and write audio data from a capture track node, please refer to Fig. 9 As shown, the following steps are included:
[0133] S111. Determine whether the read index has reached the write index. If WritePos is equal to ReadPos, it is determined that the read index has reached the write index, and step S112 is executed. Otherwise, step S114 is executed. ReadSize is the length of the audio data to be read, and RingSize is the size of the ring buffer.
[0134] S112, determine whether the synchronization signal is acquired, if acquired, execute step S114, otherwise, execute step S113.
[0135] S113: Check whether the waiting timeout has occurred. If the waiting timeout has occurred, return to write length 0. Otherwise, execute step S112.
[0136] Steps S112 and S113 are similar to the above-mentioned steps S001 and S002 and will not be described in detail here.
[0137] S114. Determine whether there is a boundary in the audio data to be read based on the size of WritePos and ReadPos, where WritePos is the value of the write subscript and ReadPos is the value of the read subscript; if WritePos is greater than ReadPos, execute step S116, otherwise, execute step S115.
[0138] S115, dividing the audio data to be read into first audio data to be read and second audio data to be read in chronological order, wherein the length of the first audio data to be read is (RingSize-ReadPos), and the length of the second audio data to be read is ReadSize-(RingSize-ReadPos); first read the first audio data to be written from the ring buffer, and then read the second audio data to be written from the ring buffer, and finally update the length of the read subscript: ReadPos=(ReadPos+ReadSize)%RingSize, and execute step S117;
[0139] S116, directly read the audio data to be read, and execute step S117;
[0140] S117. Update the read index: ReadPos=(ReadPos+ReadSize)%RingSize.
[0141] The process of steps S114-S117 is explained and illustrated below through an example.
[0142] Set the audio track sampling rate to 48000 and the ring buffer size to 48000 / 10+1. The buffer can buffer 100ms of audio data (plus 1 to prevent out-of-bounds). RingSize = 4801. ReadPos is the read index (the starting position of readable data in the ring buffer); each read is 960 length.
[0143] 1. When no data is written, ReadPos = WritePos = 0, and the return value is 0;
[0144] 2. After writing 960 for the first time,
[0145] ReadPos(0)>WritePos(960), execute step S116, read out the written data with a length of 960 (i.e., perform a read copy), and then execute step S117, ReadPos=(0+960)%4801=960.
[0146] 3. Write 960 for the second time, ReadPos(960)>WritePos(1920), execute step S116, read out the written data with a length of 960 (that is, perform a read copy), and then execute step S117, ReadPos=(960+960)%4801=1920.
[0147] And so on.
[0148] 3. After the fifth write to 960, ReadPos = (960 + 3880) % 4801 = 4800
[0149] 4. After the sixth writing of 960, WritePos=959 (as can be seen from step S007), at this time:
[0150] ReadPos(4800)>WritePos(959), then execute step S115: first read the length of 1(4801-4800) from the buffer, then read the length of 960-1, and then execute step S117: ReadPos=(4800+960)%4801=959.
[0151] The cycle continues.
[0152] The process of writing a playback track node is basically the same as the process of writing a capture track node. Please refer to steps S001-S007, which will not be repeated here.
[0153] S150, reading the audio data written into the playback track node, recording it as second audio data, and sending the second audio data to the target audio output device.
[0154] The process of reading the audio data of the playback track node is basically the same as the process of reading the acquisition track node. Please refer to steps S111-S117, which will not be repeated here.
[0155] When the target audio output device receives multiple second audio data, the multiple second audio data are merged through the multi-channel audio merging mechanism and sent to the target audio output device. At the same time, any playback track node is used as the synchronization source, all the second audio data received by the target audio output device are synchronized, and then the multiple second audio data are merged through the multi-channel audio merging mechanism and sent to the target audio output device.
[0156] It should be noted that: when the sampling rate of the target audio output device is different from the sampling rate of the second audio data, the second audio data needs to be resampled to match the sampling rate of the target audio output device.
[0157] Fig.10 An example of an application scenario of the audio routing management method of the present invention is shown. The present invention does not limit the number of input devices and output devices, and has no restriction on the expansion of audio routing. It only requires that the input devices and output devices connected to the system have the ability to input or output audio.
[0158] The implementation process is as follows Fig.11 and Fig.12 As shown, taking the local sound card and file input as an example, the audio data collected by the local sound card is first separated into three channels of audio data through a multi-channel sound source separation mechanism, and written into the collection track node 0, the collection track node 1 and the collection track node 2 respectively. The audio data input by the file is directly written into the collection track node 3, and then the collection track node 0 (of course, it can also be other collection track nodes, for example, here the sound card beat is used for synchronization operation, therefore, the synchronization signal reference source must be the local sound card track node, that is, the collection track nodes 0-2) is used as the synchronization source to calculate and send the synchronization signal , so that the data of the four acquisition track nodes are synchronized, the audio data in the four acquisition track nodes are read, and then the sampling rate of the audio data in the four acquisition track nodes is made the same through resampling operation, and then after echo cancellation, EQ and DRC processing, the audio data is mixed using the mixing node, and then written into playback track node 1, playback track node 2 and playback track node 3. After reading the audio data of playback track node 1 and playback track node 2, it is sent to the local sound card for playback through the dual-channel sound source merging mechanism, and the audio data of playback track node 3 is written into the network track node.
[0159] In some other embodiments, if the sampling rate of the target audio output device is different from the sampling rate of the audio data read from the playback track node, the audio data read from the playback track node needs to be resampled. For example, assuming that the sampling rate of the local sound card is 48000 and the sampling rate of the file input is 8000, the sampling rate of the audio data read from the sampling track node 3 needs to be converted from 8000 to 48000 through resampling during mixing. After mixing, if the sampling rate of the network track node is 16000, the sampling rate of the audio data read from the playback track node 3 needs to be converted to 16000 through resampling before it can be written to the playback track node 3.
[0160] Embodiment 2
[0161] See also Fig.13 , Fig.13Schematic diagram of the structure of an audio routing management system disclosed in an embodiment of the present invention. Fig.13 As shown, the audio routing management system may include:
[0162] A determination unit 210, configured to determine a target audio output device and a target audio input device that sends audio data to the target audio output device;
[0163] A creation unit 220, configured to construct a track line based on the target audio output device and the target audio input device, each track line including at least one acquisition track node, at least one playback track node and one mixing node;
[0164] The first processing unit 230 is used to write the audio data collected by the target audio input device into the collected audio track node;
[0165] The mixing unit 240 is used to read the audio data written into the acquisition track node, recorded as the first audio data, and write all the first audio data into the playback track node after mixing;
[0166] The second processing unit 250 is used to read the audio data written into the playback track node, record it as second audio data, and send the second audio data to the target audio output device.
[0167] The architecture of the audio routing management system is as follows Fig.14 As shown in the figure, audio data is sent from the sound source to the track node in the routing module through the ALSA sound card synchronization signal. Each pipe line1 in the figure represents a Fig.10 The combination of multiple pipeline lines represents audio routing. Different weights are assigned to each sound card in the pipeline line, and the weight of the sound card is adjusted according to the volume of the sound card.
[0168] The volume level for each sound card is expressed as:
[0169]
[0170] Where V n Indicates the volume level of sound card n in the mixing sound card, L n It represents the weight of sound card n in the mixing sound card, k represents the number of mixing sound cards, and T represents the maximum volume level limited by the system. When performing mixing, if you need to reduce or increase the volume level of a sound card, you can adjust the weight value to complete the intelligent control of the volume and enhance the clarity and brightness of the sound.
[0171] Embodiment 3
[0172] See also Fig.15 , Fig.15Schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. Fig.15 As shown, the electronic device may include:
[0173] A memory 310 storing executable program codes;
[0174] a processor 320 coupled to the memory 310;
[0175] The processor 320 calls the executable program code stored in the memory 310 to execute part or all of the steps in the audio routing management method in the first embodiment.
[0176] An embodiment of the present invention discloses a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute part or all of the steps in an audio routing management method in the first embodiment.
[0177] The embodiment of the present invention further discloses a computer program product, wherein when the computer program product is run on a computer, the computer is enabled to execute part or all of the steps in the audio routing management method in the first embodiment.
[0178] An embodiment of the present invention further discloses an application publishing platform, wherein the application publishing platform is used to publish a computer program product, wherein when the computer program product runs on a computer, the computer executes part or all of the steps in an audio routing management method in embodiment one.
[0179] In various embodiments of the present invention, it should be understood that the size of the serial numbers of the processes does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0180] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place or distributed over multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0181] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0182] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a memory and includes several requests for a computer device (which can be a personal computer, a server or a network device, etc., specifically a processor in a computer device) to perform some or all of the steps of the method described in each embodiment of the present invention.
[0183] In the embodiments provided by the present invention, it should be understood that "B corresponding to A" means that B is associated with A, and B can be determined according to A. However, it should also be understood that determining B according to A does not mean determining B only according to A, and B can also be determined according to A and / or other information.
[0184] A person of ordinary skill in the art can understand that some or all of the steps in the various methods of the embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0185] The above is a detailed introduction to an audio routing management method, system and electronic device disclosed in an embodiment of the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for a person skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. An audio routing management method, characterized in that: include: Determine a target audio output device and a target audio input device that sends audio data to the target audio output device; Constructing an audio track circuit based on the target audio output device and the target audio input device, each audio track circuit including at least one acquisition audio track node, at least one playback audio track node and one mixing node; Write the audio data collected by the target audio input device into the collection track node; The audio data written into the acquisition track node is read and recorded as the first audio data, and all the first audio data are mixed and written into the playback track node; Read the audio data written into the playback track node, record it as the second audio data, and send the second audio data to the target audio output device; When the target audio output device receives multiple second audio data, any playback track node is used as the synchronization source, all the second audio data received by the target audio output device are synchronized, and then the multiple second audio data are merged through the multi-channel audio merging mechanism and sent to the target audio output device.
2. The audio routing management method according to claim 1, characterized in that: When one or more of the target audio input devices has a multi-channel audio source, the audio data of each channel is obtained through the multi-channel audio source separation mechanism, and the audio data of each channel is written into the corresponding acquisition track node.
3. The audio routing management method according to claim 1, characterized in that: When there are multiple audio track nodes: resampling the first audio data; or / and, Taking any collected audio track node as the synchronization source, all first audio data are synchronized.
4. The audio routing management method according to claim 1, characterized in that: A shared memory area is created for each target track node, and a circular buffer is constructed in the shared memory area using a queue data structure; a write subscript and a read subscript are set for each target track node, wherein when audio data with a length of L1 is written to the target track node, the value of the write subscript is increased by L1, and when audio data with a length of L2 is read from the target track node, the value of the read subscript is increased by L2; the target track node is a collection track node or a playback track node.
5. The audio routing management method according to claim 4, characterized in that: The method of writing audio data to the target audio track node includes: Based on the values of WritePos and (WritePos+WriteSize)%RingSize, determine whether the write subscript exceeds the boundary after adding the audio data to be written, where WritePos is the value of the write subscript, WriteSize is the length of the audio data to be written, and RingSize is the size of the ring buffer; If WritePos is less than (WritePos+WriteSize)%RingSize, the audio data to be written is directly written into the ring buffer, and the length of the write subscript is updated: WritePos=(WritePos+WriteSize)%RingSize; If WritePos is greater than (WritePos+WriteSize)%RingSize, the audio data to be written is divided into first audio data to be written and second audio data to be written in chronological order, wherein the length of the first audio data to be written is (RingSize-WritePos), and the length of the second audio data to be written is WriteSize-(RingSize-WritePos); the first audio data to be written is first written into the ring buffer, and then the second audio data to be written is written into the ring buffer, and finally the length of the write subscript is updated: WritePos=(WritePos+WriteSize)%RingSize.
6. The audio routing management method according to claim 4, characterized in that: The method for reading the audio data in the target audio track node comprises: Based on the size of WritePos and ReadPos, determine whether there is a boundary in the audio data to be read, where WritePos is the value of the write subscript and ReadPos is the value of the read subscript; If WritePos is greater than ReadPos, the audio data to be read is directly read, and the read subscript is updated: ReadPos = (ReadPos + ReadSize) % RingSize, where ReadSize is the length of the audio data to be read, and RingSize is the size of the ring buffer; If WritePos is less than ReadPos, the audio data to be read is divided into the first audio data to be read and the second audio data to be read in chronological order, wherein the length of the first audio data to be read is (RingSize-ReadPos), and the length of the second audio data to be read is ReadSize-(RingSize-ReadPos); first read the first audio data to be written from the ring buffer, and then read the second audio data to be written from the ring buffer, and finally update the length of the read subscript: ReadPos=(ReadPos+ReadSize)%RingSize.
7. An audio routing management system, characterized in that: It includes: a determining unit, configured to determine a target audio output device and a target audio input device to send audio data to the target audio output device; A creation unit, configured to construct a track line based on the target audio output device and the target audio input device, each track line comprising at least one acquisition track node, at least one playback track node and one mixing node; A first processing unit, configured to write the audio data collected by the target audio input device into a collection track node; A mixing unit is used to read the audio data written into the acquisition track node, recorded as the first audio data, and write all the first audio data into the playback track node after mixing; A second processing unit is used to read the audio data written into the playback track node, record it as second audio data, and send the second audio data to a target audio output device; When the target audio output device receives multiple second audio data, any playback track node is used as the synchronization source, all the second audio data received by the target audio output device are synchronized, and then the multiple second audio data are merged through the multi-channel audio merging mechanism and sent to the target audio output device.
8. An electronic device, characterized in that: include: A memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the audio routing management method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Implementation method for audio and video recording based on routing server and routing server
CN103581611A
Programmable graphics processor and method for performing sound mixing on multipath audio through programmable graphics processor
CN104143334A
Real-time audio processing method and device and intelligent terminal
CN106293659A
Audio processing method and system
CN106325804A
Audio multi-channel synchronous output method, computer device and computer readable storage medium
CN109828742A
