Audio data reading alignment method and device for multi-sound card, equipment and medium
By obtaining the sampling attributes configured in ALSA to determine the audio data reading time, and adding thread sleep and synchronous startup mechanisms, the problem of misalignment in reading audio data from multiple sound cards was solved, and time-aligned audio data transmission in a multi-threaded environment was realized.
Patent Information
- Application Number
- CN202211392309.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-08
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2042-11-08
AI Technical Summary
In a multi-threaded environment, when an application reads audio data from multiple sound cards simultaneously, it cannot guarantee the time alignment of the audio data, leading to functional abnormalities.
The audio data reading time is determined by obtaining the sampling attributes configured in ALSA. Based on this time, the thread sleep duration is determined and the thread remains in a sleep state. A multi-threaded synchronous startup mechanism is used to start threads at the same time. The ALSA-API is used to read the sound card audio data and store it in the user buffer.
This ensures that multiple sound cards transmit audio data to the application simultaneously at the same time, achieving time alignment of audio data and supporting the normal operation of time-aligned functions.
Smart Images

Figure CN115599562B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of audio data processing technology, and in particular to an audio data reading and alignment method, apparatus, computer device, and storage medium for multiple sound cards. Background Technology
[0002] Currently, ALSA (Advanced Linux Sound Architecture) has become the mainstream audio architecture for Linux. At the kernel device driver layer, ALSA provides alsa-driver (sound card driver) to couple and manage audio drivers. At the application layer, ALSA provides alsa-lib (user space library). Applications can associate with alsa-driver and complete the control of the underlying audio hardware by simply calling the API (Application Programming Interface) of alsa-lib.
[0003] Currently, controlling audio data sampling for each sound card typically involves the application creating multiple sub-threads. These sub-threads then use the ALSA API to control the audio data sampling of each sound card. For example, when the application executes the `read()` interface, the audio data stored in the kernel buffer is copied to the application's user buffer before being used. However, when the application reads audio data in a multi-threaded environment, there is a delay in audio data acquisition and transmission. This means that if the application tries to read audio data from multiple sound cards simultaneously at a given time, it cannot guarantee that all sound cards will transmit audio data to the application at the same time. Consequently, the audio data read by the application is not time-aligned, causing malfunctions in functions developed based on time-aligned audio data. Summary of the Invention
[0004] This invention provides a method, apparatus, computer device, and storage medium for aligning audio data read from multiple sound cards. It aims to solve the problem in the prior art where, when an application reads audio data from multiple sound cards at the same time, it cannot be guaranteed that all sound cards can transmit audio data to the application simultaneously, resulting in the application reading audio data that is not time-aligned.
[0005] In a first aspect, embodiments of the present invention provide an audio data reading alignment method for multiple sound cards, comprising:
[0006] The application starts and creates at least two threads;
[0007] Obtain the sampling attributes configured by the application using ALSA, and determine the audio data reading time based on the sampling attributes;
[0008] The thread sleep duration is determined based on the audio data reading time, and the at least two threads are kept in a sleep state for the duration of the thread sleep.
[0009] At least two threads are started at the same time according to the multi-threaded synchronous startup mechanism;
[0010] The at least two threads read the audio data of the corresponding sound card through the ALSA-API;
[0011] The audio data is stored in the user cache area corresponding to the at least two threads in the application.
[0012] Secondly, embodiments of the present invention provide an audio data reading and alignment device for multiple sound cards, comprising:
[0013] A startup unit is used to launch the application and creates at least two threads;
[0014] The time consumption determination unit is used to obtain the sampling attributes configured by the application using ALSA, and determine the audio data reading time based on the sampling attributes;
[0015] A sleep unit is used to determine the thread sleep duration based on the audio data reading time, and to keep the at least two threads in a sleep state for the duration of the thread sleep.
[0016] A synchronous startup unit is used to start the at least two threads at the same time according to a multi-threaded synchronous startup mechanism;
[0017] An audio data reading unit is used for the at least two threads to read audio data from the corresponding sound card via the ALSA-API;
[0018] An audio data storage unit is used to store the audio data in the user cache area corresponding to the at least two threads in the application.
[0019] Thirdly, embodiments of the present invention provide a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the audio data reading and alignment method for multiple sound cards described in the first aspect.
[0020] Fourthly, embodiments of the present invention also provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, which, when executed by a processor, causes the processor to perform the audio data reading and alignment method for multiple sound cards described in the first aspect.
[0021] This invention provides a method, apparatus, computer device, and storage medium for aligning audio data reads across multiple sound cards. The method includes: starting an application and creating at least two threads; obtaining sampling attributes configured by the application using ALSA, and determining the audio data read time based on the sampling attributes; determining the thread sleep duration based on the audio data read time, and keeping at least two threads in a sleep state for the specified duration; starting at least two threads simultaneously according to a multi-threaded synchronous startup mechanism; having at least two threads read audio data from their respective sound cards via the ALSA-API; and storing the audio data in the user buffer corresponding to the at least two threads within the application. This invention ensures that multiple sound cards can simultaneously transmit audio data to the application when it reads audio data in a multi-threaded environment, resulting in time-aligned audio data read by the application. Attached Figure Description
[0022] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0023] Figure 1 This is a flowchart illustrating the audio data reading and alignment method for multiple sound cards provided in an embodiment of the present invention.
[0024] Figure 2 A schematic block diagram of an audio data reading and alignment device for multiple sound cards provided in an embodiment of the present invention;
[0025] Figure 3 A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation
[0026] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0027] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0028] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0029] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0030] This invention provides a method, apparatus, device, and medium for aligning audio data reading from multiple sound cards. The method for aligning audio data reading from multiple sound cards in this invention is applied to an in-vehicle infotainment system. The in-vehicle infotainment system includes a processor, a memory, and an application program. The application program is stored in the memory and configured to be executed by the processor to implement the method for aligning audio data reading from multiple sound cards, thereby enabling functions developed based on time-aligned audio data reading (such as voice wake-up function) to function normally.
[0031] like Figure 1 As shown, Figure 1 This is a flowchart illustrating the audio data reading and alignment method for multiple sound cards provided in an embodiment of the present invention. The method includes steps S101 to S106.
[0032] S101. The application starts and creates at least two threads.
[0033] In this embodiment, when the vehicle infotainment system needs to acquire time-aligned audio data, the application in the system starts and creates at least two threads to read the audio data in a multi-threaded environment. Each of the at least two threads reads audio data from one sound card channel. For example, when using the voice wake-up function, the application starts and creates two threads, thread A and thread B. Thread A reads audio data from the microphone sound card channel, and thread B reads audio data from the re-sampling sound card channel.
[0034] S102. Obtain the sampling attributes configured by the application using ALSA, and determine the audio data reading time based on the sampling attributes.
[0035] In this embodiment, the ALSA driver is used for the sound card. At the kernel device driver layer, ALSA provides the alsa-driver to operate the sound card hardware. Simultaneously, at the application layer, ALSA provides the alsa-lib. Applications can associate with the alsa-driver simply by calling the alsa-lib API, thereby controlling the sound card hardware. When the application reads audio data in a multi-threaded environment, there will be a certain delay in acquiring and transmitting audio data via the ALSA-driver. However, the vehicle system can determine the audio data reading time based on the sampling attributes configured by the application using ALSA, i.e., the audio data reading time is the delay time for the alsa-driver to acquire and transmit audio data.
[0036] In one embodiment, step S102 includes:
[0037] Obtain a pre-stored data read time conversion strategy, and convert the sampling attribute into audio data read time according to the data read time conversion strategy.
[0038] In this embodiment, sampling attributes can be converted into audio data reading times using a pre-stored data reading time conversion strategy, thereby quickly obtaining the audio data reading time. The pre-stored data reading time conversion strategy can be a mapping table between sampling attributes and audio data reading times; the corresponding audio data reading time can be quickly obtained by looking up the table based on the sampling attributes.
[0039] S103. Determine the thread sleep duration based on the audio data reading time, and keep the at least two threads in a sleep state for the specified thread sleep duration.
[0040] In this embodiment, the thread sleep duration can be determined based on the audio data reading time. At least two threads are kept in a sleep state for the specified duration, ensuring that the at least two threads created by the application sleep for an appropriate amount of time. Adding an appropriate sleep duration before the application's multi-threaded audio data reading allows time for the alsa-driver to complete the acquisition of audio data and the transfer and copying of the buffered audio data. This ensures immediate response when reading audio data from the buffer later, guaranteeing that multiple sound cards can simultaneously transmit audio data to the application.
[0041] In one embodiment, step S103 includes:
[0042] The thread sleep duration is obtained by reducing the audio data reading time by a preset duration.
[0043] Keep at least two threads in a sleep state for the duration of the sleep.
[0044] In this embodiment, the audio data reading time determined by the sampling attributes configured by ALSA is the ideal delay time for the alsa-driver to acquire audio data and transmit / copy the audio data under ideal conditions. The continuous sleep duration of the at least two threads in the sleep state needs to be slightly less than the audio data reading time. Specifically, the audio data reading time is reduced by a preset duration (such as setting the preset duration to 50ms, 80ms, 100ms, etc., although the actual implementation is not limited to the above durations, and can be set according to actual needs) to obtain the thread sleep duration, thereby ensuring that the at least two threads sleep for an appropriate time.
[0045] S104. Start the at least two threads at the same time according to the multi-threaded synchronous startup mechanism.
[0046] In this embodiment, after the at least two threads finish sleeping, a multi-threaded synchronization startup mechanism needs to be added between them. This mechanism ensures that the at least two threads start at the same time. By starting the at least two threads at the same time according to the multi-threaded synchronization startup mechanism, it can be guaranteed that the reading actions of the multiple threads start at the same time, thus ensuring that the audio data read is recorded at the same time.
[0047] In one embodiment, step S104 includes:
[0048] If it is detected that any one of the at least two threads has entered the ready state, then it is detected whether the other threads of the at least two threads have all entered the ready state;
[0049] If it is detected that all other threads in the at least two threads have entered the ready state, then all threads in the at least two threads will be started simultaneously.
[0050] In this embodiment, after the at least two threads finish sleeping, a multi-threaded synchronous startup mechanism is used to control the simultaneous startup of the at least two threads. Specifically, if any one of the at least two threads is detected to have entered the ready state, it is then checked whether all other threads in the at least two threads have entered the ready state. Only when all other threads in the at least two threads have entered the ready state, i.e., all threads have entered the ready state, are all threads in the at least two threads started simultaneously. This use of conditional checks combined with mutex locks to achieve synchronous startup between multiple threads ensures that the audio data read is recorded at the same point in time.
[0051] S105, the at least two threads read the audio data of the corresponding sound card through ALSA-API.
[0052] In this embodiment, after the at least two threads start synchronously, they read the audio data of the corresponding sound card through the ALSA-API. This ensures that when the application reads audio data from multiple sound cards simultaneously at a certain point in time, all sound cards can transmit audio data to the application at the same time. Here, ALSA-API is the API (Application Programming Interface) of ALSA. Each thread can determine the specific sound card through the ALSA API and then read the audio data of that sound card.
[0053] In one embodiment, step S105 includes:
[0054] Obtain the sound card address corresponding to each of the at least two threads;
[0055] Each of the at least two threads reads the corresponding audio data according to the corresponding sound card address and preset reading duration.
[0056] In this embodiment, when the at least two threads read audio data from the corresponding sound card via the ALSA-API, they first need to obtain the sound card address corresponding to each of the at least two threads through the ALSA API. The sound card address allows them to locate the corresponding sound card information and thus read the corresponding audio data. Then, each of the at least two threads reads the corresponding audio data based on the corresponding sound card address and a preset reading duration. The preset reading duration can be set to 10ms, 20ms, 50ms, etc., ensuring that each thread reads audio data at the same time point.
[0057] S106. Store the audio data in the user cache area corresponding to the at least two threads in the application.
[0058] In this embodiment, the audio data read after the at least two threads are started synchronously is copied to the user cache of the application so that the vehicle system can use it, ensuring that functions developed based on time-aligned audio data can function properly. For example, in the voice wake-up function, the audio data from the device's microphone sound card channel at the same time point is used to filter out the audio data from the back-collected sound card channel, obtaining the wake-up sound from the external environment, thereby waking up the device.
[0059] In one embodiment, step S106 is followed by:
[0060] A message indicating that cache generation is complete will be displayed.
[0061] In this embodiment, after the read audio data is stored in the application's user cache, the system generates a cache completion prompt message and displays the message to indicate to the user that each thread has completed reading the audio data.
[0062] This invention provides a method for aligning audio data reading across multiple sound cards. This method ensures that when an application reads audio data in a multi-threaded environment, multiple sound cards can simultaneously transmit audio data to the application, ensuring that the audio data read by the application is time-aligned. This allows functions developed based on time-aligned audio data to function properly.
[0063] This invention also provides an audio data reading and alignment device for multiple sound cards. This device is used to execute any embodiment of the aforementioned audio data reading and alignment method for multiple sound cards. For details, please refer to... Figure 2 , Figure 2 This is a schematic block diagram of an audio data reading and alignment device for multiple sound cards provided in an embodiment of the present invention. The audio data reading and alignment device 100 for multiple sound cards provided in an embodiment of the present invention includes a startup unit 101, a time consumption determination unit 102, a sleep unit 103, a synchronous startup unit 104, an audio data reading unit 105, and an audio data storage unit 106.
[0064] Startup unit 101 is used to start the application and create at least two threads.
[0065] In this embodiment, when the vehicle infotainment system needs to acquire time-aligned audio data, the application in the system starts and creates at least two threads to read the audio data in a multi-threaded environment. Each of the at least two threads reads audio data from one sound card channel. For example, when using the voice wake-up function, the application starts and creates two threads, thread A and thread B. Thread A reads audio data from the microphone sound card channel, and thread B reads audio data from the re-sampling sound card channel.
[0066] The time consumption determination unit 102 is used to obtain the sampling attributes configured by the application using ALSA, and determine the audio data reading time based on the sampling attributes.
[0067] In this embodiment, the ALSA driver is used for the sound card. At the kernel device driver layer, ALSA provides the alsa-driver to operate the sound card hardware. Simultaneously, at the application layer, ALSA provides the alsa-lib. Applications can associate with the alsa-driver simply by calling the alsa-lib API, thereby controlling the sound card hardware. When the application reads audio data in a multi-threaded environment, there will be a certain delay in acquiring and transmitting audio data via the ALSA-provided alsa-driver. Furthermore, the vehicle system can determine the audio data reading time based on the sampling attributes configured by the application using ALSA, meaning that the audio data reading time is the time spent by the alsa-driver acquiring and transmitting audio data.
[0068] In one embodiment, the time consumption determination unit 102 is specifically used for:
[0069] Obtain a pre-stored data read time conversion strategy, and convert the sampling attribute into audio data read time according to the data read time conversion strategy.
[0070] In this embodiment, sampling attributes can be converted into audio data reading times using a pre-stored data reading time conversion strategy, thereby quickly obtaining the audio data reading time. The pre-stored data reading time conversion strategy can be a mapping table between sampling attributes and audio data reading times; the corresponding audio data reading time can be quickly obtained by looking up the table based on the sampling attributes.
[0071] The sleep unit 103 is used to determine the thread sleep duration based on the audio data reading time, keep the at least two threads in a sleep state and continue the thread sleep duration.
[0072] In this embodiment, the thread sleep duration can be determined based on the audio data reading time. At least two threads are kept in a sleep state for the specified duration, ensuring that the at least two threads created by the application sleep for an appropriate amount of time. Adding an appropriate sleep duration before the application's multi-threaded audio data reading allows time for the alsa-driver to complete the acquisition of audio data and the transfer and copying of the buffered audio data. This ensures immediate response when reading audio data from the buffer later, guaranteeing that multiple sound cards can simultaneously transmit audio data to the application.
[0073] In one embodiment, the sleep unit 103 is specifically used for:
[0074] The thread sleep duration is obtained by reducing the audio data reading time by a preset duration.
[0075] Keep at least two threads in a sleep state for the duration of the sleep.
[0076] In this embodiment, the audio data reading time determined by the sampling attributes configured by ALSA is the ideal time for the alsa-driver to acquire audio data and transmit / copy the audio data under ideal conditions. The continuous sleep duration of the at least two threads in a sleep state needs to be slightly less than the audio data reading time. Specifically, the audio data reading time is reduced by a preset duration (such as setting the preset duration to 50ms, 80ms, 100ms, etc., although the actual implementation is not limited to the above durations and can be set according to actual needs) to obtain the thread sleep duration, thereby ensuring that the at least two threads sleep for an appropriate time.
[0077] The synchronous startup unit 104 is used to start the at least two threads at the same time according to the multi-threaded synchronous startup mechanism.
[0078] In this embodiment, after the at least two threads finish sleeping, a multi-threaded synchronization startup mechanism needs to be added between them. This mechanism ensures that the at least two threads start at the same time. By starting the at least two threads at the same time according to the multi-threaded synchronization startup mechanism, it can be guaranteed that the reading actions of the multiple threads start at the same time, thus ensuring that the audio data read is recorded at the same time.
[0079] In one embodiment, the synchronous startup unit 104 is specifically used for:
[0080] If it is detected that any one of the at least two threads has entered the ready state, then it is detected whether the other threads of the at least two threads have all entered the ready state;
[0081] If it is detected that all other threads in the at least two threads have entered the ready state, then all threads in the at least two threads will be started simultaneously.
[0082] In this embodiment, after the at least two threads finish sleeping, a multi-threaded synchronous startup mechanism is used to control the simultaneous startup of the at least two threads. Specifically, if any one of the at least two threads is detected to have entered the ready state, it is then checked whether all other threads in the at least two threads have entered the ready state. Only when all other threads in the at least two threads have entered the ready state, i.e., all threads have entered the ready state, are all threads in the at least two threads started simultaneously. This use of conditional checks combined with mutex locks to achieve synchronous startup between multiple threads ensures that the audio data read is recorded at the same point in time.
[0083] The audio data reading unit 105 is used for the at least two threads to read the audio data of the corresponding sound card through the ALSA-API.
[0084] In this embodiment, after the at least two threads start synchronously, they read the audio data of the corresponding sound card through the ALSA-API. This ensures that when the application reads audio data from multiple sound cards simultaneously at a certain point in time, all sound cards can transmit audio data to the application at the same time. Here, ALSA-API is the API (Application Programming Interface) of ALSA. Each thread can determine the specific sound card through the ALSA API and then read the audio data of that sound card.
[0085] In one embodiment, the audio data reading unit 105 is specifically used for:
[0086] Obtain the sound card address corresponding to each of the at least two threads;
[0087] Each of the at least two threads reads the corresponding audio data according to the corresponding sound card address and preset reading duration.
[0088] In this embodiment, when the at least two threads read audio data from the corresponding sound card via the ALSA-API, they first need to obtain the sound card address corresponding to each of the at least two threads through the ALSA API. The sound card address allows them to locate the corresponding sound card information and thus read the corresponding audio data. Then, each of the at least two threads reads the corresponding audio data based on the corresponding sound card address and a preset reading duration. The preset reading duration can be set to 10ms, 20ms, 50ms, etc., ensuring that each thread reads audio data at the same time point.
[0089] The audio data storage unit 106 is used to store the audio data in the user cache area corresponding to the at least two threads in the application.
[0090] In this embodiment, the audio data read after the at least two threads are started synchronously is copied to the user cache of the application so that the vehicle system can use it, ensuring that functions developed based on time-aligned audio data can function properly. For example, in the voice wake-up function, the audio data from the device's microphone sound card channel at the same time point is used to filter out the audio data from the back-collected sound card channel, obtaining the wake-up sound from the external environment, thereby waking up the device.
[0091] In one embodiment, the audio data reading alignment device 100 for multiple sound cards further includes:
[0092] The display unit is used to generate and display a cache completion message.
[0093] In this embodiment, after the read audio data is stored in the application's user cache, the system generates a cache completion prompt message and displays the message to indicate to the user that each thread has completed reading the audio data.
[0094] This invention provides an audio data reading alignment device for multiple sound cards, used to execute any of the aforementioned audio data reading alignment methods for multiple sound cards. It can ensure that multiple sound cards can transmit audio data to the application simultaneously when the application reads audio data in a multi-threaded environment, so that the audio data read by the application is time-aligned, thereby enabling functions developed based on time-aligned audio data to be used normally.
[0095] The aforementioned audio data reading and alignment device for multiple sound cards can be implemented as a computer program, which can, for example... Figure 3 It runs on the computer device shown.
[0096] Please see Figure 3 , Figure 3 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a device bus 501, wherein the memory may include a storage medium 503 and internal memory 504.
[0097] The storage medium 503 may store the operating device 5031 and the computer program 5032. When the computer program 5032 is executed, it causes the processor 502 to execute the audio data reading alignment method of the multi-sound card.
[0098] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.
[0099] The internal memory 504 provides an environment for the operation of the computer program 5032 in the storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute the audio data reading alignment method of the multi-sound card.
[0100] This network interface 505 is used for network communication, such as providing data transmission. Those skilled in the art will understand that... Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the computer device 500 to which the present invention is applied. The specific computer device 500 may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0101] The processor 502 is used to run a computer program 5032 stored in a memory to implement the audio data reading and alignment method for multiple sound cards disclosed in this embodiment of the invention.
[0102] Those skilled in the art will understand that Figure 3 The embodiments of the computer device shown do not constitute a limitation on the specific configuration of the computer device. In other embodiments, the computer device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. For example, in some embodiments, the computer device may include only memory and a processor. In such embodiments, the structure and function of the memory and processor are different from those shown. Figure 3 The embodiments shown are consistent and will not be repeated here.
[0103] It should be understood that, in this embodiment of the invention, the processor 502 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0104] In another embodiment of the present invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when executed by a processor, the computer program implements the audio data reading and alignment method for multiple sound cards disclosed in the embodiments of the present invention.
[0105] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.
[0106] In the embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Units with the same function may be grouped into one unit. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, or may be electrical, mechanical, or other forms of connection.
[0107] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.
[0108] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0109] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a backend server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks.
[0110] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for aligning audio data reads from multiple sound cards, characterized in that, include: The application starts and creates at least two threads; Obtain the sampling attributes configured by the application using ALSA, and determine the audio data reading time based on the sampling attributes; The thread sleep duration is determined based on the audio data reading time, and the at least two threads are kept in a sleep state for the duration of the thread sleep. At least two threads are started at the same time according to the multi-threaded synchronous startup mechanism; The at least two threads read the audio data of the corresponding sound card through the ALSA-API; The audio data is stored in the user cache area corresponding to the at least two threads in the application.
2. The audio data reading and alignment method for multiple sound cards according to claim 1, characterized in that, The step of obtaining the sampling attributes configured by the application using ALSA and determining the audio data reading time based on the sampling attributes includes: Obtain a pre-stored data read time conversion strategy, and convert the sampling attribute into audio data read time according to the data read time conversion strategy.
3. The audio data reading and alignment method for multiple sound cards according to claim 1, characterized in that, The step of determining the thread sleep duration based on the audio data reading time, and keeping the at least two threads in a sleep state for the specified duration, includes: The thread sleep duration is obtained by reducing the audio data reading time by a preset duration. Keep at least two threads in a sleep state for the duration of the sleep.
4. The audio data reading and alignment method for multiple sound cards according to claim 1, characterized in that, The step of starting at least two threads at the same time according to the multi-threaded synchronous startup mechanism includes: If it is detected that any one of the at least two threads has entered the ready state, then it is detected whether the other threads of the at least two threads have all entered the ready state; If it is detected that all other threads in the at least two threads have entered the ready state, then all threads in the at least two threads will be started simultaneously.
5. The audio data reading and alignment method for multiple sound cards according to claim 1, characterized in that, The at least two threads read audio data from the corresponding sound card via the ALSA-API, including: Obtain the sound card address corresponding to each of the at least two threads; Each of the at least two threads reads the corresponding audio data according to the corresponding sound card address and preset reading duration.
6. The audio data reading and alignment method for multiple sound cards according to claim 1, characterized in that, After storing the audio data in the user cache area corresponding to the at least two threads in the application, the method further includes: A message indicating that cache generation is complete will be displayed.
7. An audio data reading and alignment device for multiple sound cards, characterized in that, include: A startup unit is used to launch the application and creates at least two threads; The time consumption determination unit is used to obtain the sampling attributes configured by the application using ALSA, and determine the audio data reading time based on the sampling attributes; A sleep unit is used to determine the thread sleep duration based on the audio data reading time, and to keep the at least two threads in a sleep state for the duration of the thread sleep. A synchronous startup unit is used to start the at least two threads at the same time according to a multi-threaded synchronous startup mechanism; An audio data reading unit is used for the at least two threads to read audio data from the corresponding sound card via the ALSA-API; An audio data storage unit is used to store the audio data in the user cache area corresponding to the at least two threads in the application.
8. The audio data reading and alignment device for multiple sound cards according to claim 7, characterized in that, The time consumption determination unit is specifically used for: Obtain a pre-stored data read time conversion strategy, and convert the sampling attribute into audio data read time according to the data read time conversion strategy.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the audio data reading alignment method for multiple sound cards as described in any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the audio data reading alignment method for multiple sound cards as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Audio playing equipment sound mixing method, device, equipment and storage medium
CN111026353A
Low-delay audio transmission method and device, driving equipment and readable storage medium
CN113965844A