Music playing method and device based on USB audio decoder, equipment and medium
By obtaining and parsing the device information of the USB audio decoder, configuring and decoding audio files, the problem that the Android system cannot play high-definition lossless music, achieving lossless playback and low power consumption.
Patent Information
- Application Number
- CN202411643467.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-11-18
AI Technical Summary
When playing music over 16bit/48kHz, Android system needs to resample and reduce the sound quality, which cannot meet the playback requirements of high-definition lossless music. The existing USB audio decoder playback solution for Android system requires the adb mode to be turned on, which is cumbersome and cumbersome. High power consumption.
By obtaining the original USB descriptor of the USB audio decoder, determining the device information, and reading the media information of the audio file through FFmpeg, device configuration, decoding lossless digital signals, and adding them to the locked loop queue, through the USB audio decoder Perform decoding and transmission to achieve lossless playback.
It realizes that high-definition lossless music can be played without using adb mode on Android system, which improves sound quality, reduces the power consumption of lossless music playback, and improves user experience.
Smart Images

Figure CN119479668A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of audio processing, and in particular to a music playing method, device, equipment and medium based on a USB audio decoder. Background Art
[0002] When playing music on an Android phone, the audio digital signal needs to go through multiple processing links of the system, such as sampling rate conversion, volume control, etc. Although these links provide convenience for audio processing, they will also cause loss of sound quality. In particular, in the sampling rate conversion link of the Android system, when the music quality exceeds 16bit / 48kHz (sampling bit depth / sampling frequency), the Android system will resample the digital signal and reduce it to below 16bit / 48kHz to be compatible with the DAC chip of the mobile phone. This will turn the original ultra-high-definition lossless music into music of ordinary clarity, which cannot meet the needs of music lovers. Therefore, a solution is needed to allow Android phones to play high-definition lossless music.
[0003] There is a USB audio decoder in the prior art that can directly decode the original audio stream of digital audio and convert it into an analog signal. The decoded analog signal has a high audio signal-to-noise ratio. Android phones can directly play ultra-high-definition lossless music using this USB decoder. However, most of the existing solutions for using USB decoders for Android systems to play lossless music require turning on the adb mode before use. This type of solution has two disadvantages:
[0004] 1) The operation is cumbersome. To start the adb mode on the Android system, you need to perform a series of operations in the system settings:
[0005] 2) The power consumption is relatively high. When the Android system enters adb mode for audio transmission, the system will incur additional overhead.
[0006] In summary, there is an urgent need to develop a solution suitable for the Android system that can transmit the lossless digital signal of high-definition lossless digital music to the USB decoder without using the adb mode and can play it with low power consumption.
[0007] Terminology explanation:
[0008] USB: Universal Serial Bus (USB) is a serial bus standard and a technical specification for input and output interfaces. It is widely used in information and communication products such as personal computers and mobile devices, and has been extended to other related fields such as photographic equipment, digital televisions (set-top boxes), and game consoles.
[0009] Audio decoder: The main functions of the audio decoder are to convert the read digital audio information into analog audio signal output, and to decode and restore the multi-channel audio information encoded during recording.
[0010] Sampling rate: also called sampling speed or sampling frequency, defines the number of samples extracted from a continuous signal to form a discrete signal per unit time, and is expressed in Hertz (Hz). The reciprocal of the sampling frequency is the sampling period or sampling time, which is the time interval between samples. In layman's terms, the sampling frequency refers to how many signal samples a computer can collect per unit time.
[0011] Sampling bit depth: Also known as bit depth or quantization accuracy, it refers to the number of bits occupied by each sampling point in digital audio. Simply put, it is the number of bits needed to represent a sampling value. This parameter determines the dynamic range and accuracy of digital audio, that is, the distance between the maximum and minimum amplitudes of the sound signal, and the degree to which the details and differences of the sound signal can be accurately expressed.
[0012] Sampling rate conversion: refers to the process of changing the sampling rate of audio from its original value to another value.
[0013] Digital-to-analog converter (DAC): also known as D / A converter, or DAC for short, is a device that converts digital quantities into analog quantities. D / A converters are basically composed of four parts, namely, weighted resistor network, operational amplifier, reference power supply, and analog switch. Digital-to-analog converters are generally used in analog-to-digital converters. Analog-to-digital converters are A / D converters, or ADC for short, which are devices that convert continuous analog signals into discrete digital signals.
[0014] adb: The full name is Android Debug Bridge, which acts as a debugging bridge. Through adb, you can debug Android programs through DDMS in Eclipse. To put it simply, it is a debugging tool.
[0015] Multithreading: refers to the technology of implementing multiple threads concurrently in software or hardware. Computers with multithreading capabilities can execute more than one thread at the same time due to hardware support, thereby improving overall processing performance. Systems with this capability include symmetric multiprocessors, multi-core processors, and chip-level multiprocessing or simultaneous multithreading processors. In a program, these independently running program fragments are called "threads", and the concept of programming using them is called "multithreading".
[0016] Ring queue: Also known as circular queue, it is a special storage structure of queue. In this structure, the head and tail of the queue are connected to form a closed loop.
[0017] Object Pool: It is an effective memory management technology, especially suitable for scenarios where objects need to be created and destroyed frequently. Using object pool can reduce the system overhead of creating each object from scratch.
[0018] Producer-Consumer Pattern: It is a classic multi-threaded design pattern used to solve the coordination problem between producers and consumers in a multi-threaded environment. This pattern usually involves two or more threads, one is the producer thread, which is responsible for generating data and putting it into the buffer; the other is the consumer thread, which is responsible for taking data out of the buffer for processing.
[0019] JNI: JNI is the abbreviation of Java Native Interface. By writing programs using the Java native interface, you can ensure that the code is easily portable on different platforms. Since Java 1.1, the JNI standard has become part of the Java platform, allowing Java code to interact with code written in other languages. JNI was originally designed for native compiled languages, especially C and C++, but it does not prevent you from using other programming languages as long as the calling convention is supported.
[0020] Audio gain: Audio gain is a physics term that refers to the degree to which the current, voltage or power of a component, circuit, device or system is increased.
[0021] FFmpeg: A set of open source computer programs that can be used to record, convert, and stream digital audio and video.
[0022] Usb Version: The USB version number, which is the transmission protocol version number of USB (Universal Serial Bus).
[0023] Usb Clock: USB clock is the clock signal used for synchronous data transmission in USB (Universal Serial Bus).
[0024] Usb Unit ID: USB (Universal Serial Bus) processing unit ID, which is the number of the USB processing unit. Summary of the invention
[0025] The purpose of the present invention is to solve one of the technical problems existing in the prior art to at least a certain extent.
[0026] To this end, an object of an embodiment of the present invention is to provide a music playback method based on a USB audio decoder, which realizes lossless playback of music, improves sound quality, reduces power consumption of lossless playback of music, and thus improves the user experience.
[0027] Another object of an embodiment of the present invention is to provide a music playing device based on a USB audio decoder.
[0028] In order to achieve the above technical objectives, the technical solutions adopted by the embodiments of the present invention include:
[0029] On the one hand, an embodiment of the present invention provides a music playing method based on a USB audio decoder, comprising the following steps:
[0030] Obtaining an original USB descriptor of a USB audio decoder, and determining device information of the USB audio decoder according to the original USB descriptor;
[0031] Acquire media information of a target audio file, and perform device configuration on the USB audio decoder according to the media information and the device information;
[0032] Decoding the target audio file to obtain a lossless digital signal, and adding the lossless digital signal to a preset locked circular queue;
[0033] The lossless digital signal is read from the locked circular queue, and the lossless digital signal is decoded by the USB audio decoder to obtain a lossless analog signal, and then the lossless analog signal is transmitted to an audio playback device for playback.
[0034] Further, in one embodiment of the present invention, the obtaining of the original USB descriptor of the USB audio decoder specifically includes:
[0035] Obtain the UsbDevice object corresponding to the USB audio decoder through the USB device API;
[0036] Obtain access rights to the UsbDevice object through UsbManager.requestPermission;
[0037] Obtain the UsbDeviceConnection object corresponding to the UsbDevice object through UsbManager.openDevice;
[0038] The RawDescriptors object corresponding to the UsbDeviceConnection object is obtained through UsbDeviceConnection.getFileDescriptor, and the original USB descriptor is determined according to the RawDescriptors object.
[0039] Further, in one embodiment of the present invention, determining the device information of the USB audio decoder according to the original USB descriptor specifically includes:
[0040] Parsing the original USB descriptor to obtain version information, clock number, unit number and interface information of the USB audio decoder;
[0041] Querying a baud rate list supported by the USB audio decoder according to the version information and the clock number;
[0042] Query the minimum volume gain and the maximum volume gain of the USB audio decoder according to the version information and the unit number;
[0043] Determining a minimum volume multiple according to the minimum volume gain, and determining a maximum volume multiple according to the maximum volume gain;
[0044] The volume adjustment step is determined according to the minimum volume multiple and the maximum volume multiple.
[0045] Further, in one embodiment of the present invention, the acquiring of the media information of the target audio file and the device configuration of the USB audio decoder according to the media information and the device information specifically include:
[0046] Use FFmpeg to read the media information of the target audio file to obtain the sampling frequency and sampling bit depth of the target audio file;
[0047] Acquire the current device volume, and send a first USB gain adjustment instruction according to the version information and the unit number, so that the gain of the USB audio decoder is adjusted to the minimum volume gain;
[0048] Determine the corresponding USB interface according to the sampling bit depth and the interface information, and obtain access rights to the USB interface through UsbDeviceConnection.claimInterface;
[0049] Switch the interface of the UsbDeviceConnection object to the USB interface, and determine the output endpoint of the USB interface;
[0050] Sending a baud rate modification instruction according to the version information and the clock number so that the baud rate of the USB audio decoding is consistent with the sampling frequency;
[0051] Determine a target volume gain corresponding to the current device volume according to the minimum volume multiple, the current device volume, and the volume adjustment step;
[0052] A second USB gain adjustment instruction is sent according to the version information and the unit number, so that the gain of the USB audio decoder is adjusted to the target volume gain.
[0053] Further, in one embodiment of the present invention, decoding the target audio file to obtain a lossless digital signal and adding the lossless digital signal to a preset locked circular queue specifically includes:
[0054] Determine the FFmpeg decoding thread as the producer thread;
[0055] Decoding the target audio file using a format decoder of FFmpeg to obtain the lossless digital signal;
[0056] Cache the lossless digital signal into the locked circular queue through the producer thread;
[0057] Wherein, the locked circular queue is realized by a char array plus a double pointer.
[0058] Further, in one embodiment of the present invention, the lossless digital signal is read from the locked circular queue, and the lossless digital signal is decoded by the USB audio decoder to obtain a lossless analog signal, which specifically includes:
[0059] Starting a consumer thread for consuming the lossless digital signal in the locked circular queue;
[0060] Creating an object pool, wherein the object pool stores a plurality of USB data packet sending objects;
[0061] Acquire the lossless digital signal from the locked circular queue through the consumer thread, and acquire the USB data packet sending object from the object pool;
[0062] Encapsulating the lossless digital signal into the USB data packet sending object to obtain a target USB data packet,
[0063] Sending the target USB data packet to the USB audio decoder through the ISO synchronous transmission mode, clearing the USB data packet, restoring the USB data packet sending object, and then adding the USB data packet sending object to the object pool;
[0064] The lossless digital signal is decoded by the USB audio decoder to obtain the lossless analog signal.
[0065] Further, in an embodiment of the present invention, the transmitting the lossless analog signal to an audio playback device for playback specifically includes:
[0066] Amplifying the power of the lossless analog signal by a power amplifier to obtain a target analog signal;
[0067] Play the target analog signal through headphones or speakers.
[0068] On the other hand, an embodiment of the present invention provides a music playing device based on a USB audio decoder, comprising:
[0069] A device information acquisition module, used to acquire an original USB descriptor of a USB audio decoder, and determine device information of the USB audio decoder according to the original USB descriptor;
[0070] A device configuration module, used for acquiring media information of a target audio file, and performing device configuration on the USB audio decoder according to the media information and the device information;
[0071] A digital signal decoding module, used for decoding the target audio file to obtain a lossless digital signal, and adding the lossless digital signal to a preset locked circular queue;
[0072] The analog signal decoding module is used to read the lossless digital signal from the locked circular queue, and decode the lossless digital signal through the USB audio decoder to obtain a lossless analog signal, and then transmit the lossless analog signal to the audio playback device for playback.
[0073] On the other hand, an embodiment of the present invention provides an electronic device, which includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the music playback method based on the USB audio decoder as described above is realized.
[0074] On the other hand, an embodiment of the present invention further provides a storage medium, which is a computer-readable storage medium used for computer-readable storage, and the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the music playback method based on the USB audio decoder as described above.
[0075] The advantages and beneficial effects of the present invention will be partly given in the following description, partly become apparent from the following description, or be understood through the practice of the present invention:
[0076] The embodiment of the present invention obtains the original USB descriptor of the USB audio decoder, determines the device information of the USB audio decoder according to the original USB descriptor, obtains the media information of the target audio file, configures the USB audio decoder according to the media information and the device information, decodes the target audio file to obtain a lossless digital signal, adds the lossless digital signal to a preset locked circular queue, reads the lossless digital signal from the locked circular queue, and decodes the lossless digital signal through the USB audio decoder to obtain a lossless analog signal, and then transmits the lossless analog signal to the audio playback device for playback. The embodiment of the present invention can transmit the lossless digital signal of high-definition lossless digital music to the USB audio decoder for playback on the Android system without using the adb mode, thereby realizing lossless playback of music, improving sound quality, and reducing power consumption of lossless playback of music, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0077] In order to more clearly illustrate the technical solution in the embodiments of the present invention, the following introduction is made to the drawings required for use in the embodiments of the present invention. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solution of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0078] Figure 1 A flowchart of a music playing method based on a USB audio decoder provided by an embodiment of the present invention;
[0079] Figure 2 A schematic diagram of the overall process of a music playing method based on a USB audio decoder provided in an embodiment of the present invention;
[0080] Figure 3 A step flow chart of step S101 provided in an embodiment of the present invention;
[0081] Figure 4 Another step flow chart of step S101 provided in an embodiment of the present invention;
[0082] Figure 5 The overall flow diagram of step S101 provided in the embodiment of the present invention;
[0083] Figure 6 A step flow chart of step S102 provided in an embodiment of the present invention;
[0084] Figure 7The overall flow diagram of step S102 provided in the embodiment of the present invention;
[0085] Figure 8 A step flow chart of step S103 provided in an embodiment of the present invention;
[0086] Fig. 9 A step flow chart of step S104 provided in an embodiment of the present invention;
[0087] Fig.10 Another step flow chart of step S104 provided in an embodiment of the present invention;
[0088] Fig.11 A schematic diagram of device connection provided in an embodiment of the present invention;
[0089] Fig.12 A schematic diagram of the structure of a music playing device based on a USB audio decoder provided in an embodiment of the present invention;
[0090] Fig.13 A schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention;
[0091] Fig.14 A schematic diagram of the structure of a storage medium provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0092] Embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as limitations on the present application. It should be noted that, although the functional module division is performed in the system schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described may be performed in a different order from the module division in the system schematic diagram or the flow chart. For the step numbers in the following embodiments, they are only set for the convenience of explanation, and the order between the steps is not limited in any way. The execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.
[0093] In the description of the present invention, the meaning of "a plurality" is two or more. If there is a description of the first or the second, it is only for the purpose of distinguishing the technical features, and it cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features. In addition, unless otherwise defined, all technical and scientific terms used in this document have the same meaning as those commonly understood by technicians in the technical field of this application. The terms used in this document are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0094] The music playing method based on USB audio decoder provided in the embodiment of the present application can be applied to the terminal, can also be applied to the server side, and can also be software running in the terminal or the server side. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, a set-top box, etc.; the server side can be configured as an independent physical server, or a server cluster or distributed system composed of multiple physical servers, and can also be configured as a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application that implements the music playing method based on USB audio decoder, etc., but is not limited to the above forms.
[0095] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0096] It should be noted that in each specific implementation of the present application, when it comes to the need to perform relevant processing based on data related to user identity or characteristics such as user information, user behavior data, user historical data, and user location information, the user's permission or consent will be obtained first, and the collection, use, and processing of these data will comply with the relevant laws, regulations, and standards of the relevant countries and regions. In addition, when the embodiment of the present application needs to obtain the user's sensitive personal information, the user's separate permission or consent will be obtained through a pop-up window or by jumping to a confirmation page. After clearly obtaining the user's separate permission or consent, the necessary user-related data for the normal operation of the embodiment of the present application will be obtained.
[0097] like Figure 1 FIG. 1 is a flowchart of a method for playing music based on a USB audio decoder according to an embodiment of the present invention. Figure 1 The present invention provides a method for playing music based on a USB audio decoder, which specifically includes the following steps:
[0098] S101, obtaining an original USB descriptor of a USB audio decoder, and determining device information of the USB audio decoder according to the original USB descriptor;
[0099] S102, obtaining media information of the target audio file, and configuring the USB audio decoder according to the media information and device information;
[0100] S103, decoding the target audio file to obtain a lossless digital signal, and adding the lossless digital signal to a preset locked circular queue;
[0101] S104, reading the lossless digital signal from the locked circular queue, decoding the lossless digital signal through a USB audio decoder to obtain a lossless analog signal, and then transmitting the lossless analog signal to an audio playback device for playback.
[0102] like Figure 2The figure shows the overall flow diagram of the music playing method based on USB audio decoder provided by the embodiment of the present invention. The embodiment of the present invention adapts the USB protocol of the USB audio decoder and uses multi-threading, circular queue with thread lock, object pool, producer-consumer mode, Android JNI and other technologies. Without using adb mode, the lossless digital signal of high-definition lossless digital music can be transmitted to the USB audio decoder for playback on the Android system, thereby realizing lossless playback of music, improving sound quality, and reducing power consumption of lossless playback of music, thereby improving the user experience. The method steps of the embodiment of the present invention are further explained below. It should be pointed out that step S101 of the embodiment of the present invention is implemented by Java, and the remaining steps are implemented by C++ of Android JNI, which can improve the running efficiency of the program.
[0103] like Figure 3 FIG. 1 is a flowchart of step S101 provided in an embodiment of the present invention, referring to FIG. Figure 3 , further as an optional implementation, obtaining the original USB descriptor of the USB audio decoder, which specifically includes:
[0104] S1011, obtaining the UsbDevice object corresponding to the USB audio decoder through the USB device API;
[0105] S1012, obtaining access rights of the UsbDevice object through UsbManager.requestPermission;
[0106] S1013. Obtain the UsbDeviceConnection object corresponding to the UsbDevice object through UsbManager.openDevice;
[0107] S1014. Obtain a RawDescriptors object corresponding to the UsbDeviceConnection object through UsbDeviceConnection.getFileDescriptor, and determine the original USB descriptor according to the RawDescriptors object.
[0108] like Figure 4 FIG. 1 is another step flow chart of step S101 provided in an embodiment of the present invention, referring to FIG. Figure 4 As an optional implementation, the device information of the USB audio decoder is determined according to the original USB descriptor, which specifically includes:
[0109] S1015, parsing the original USB descriptor to obtain version information, clock number, unit number and interface information of the USB audio decoder;
[0110] S1016, querying a baud rate list supported by the USB audio decoder according to the version information and the clock number;
[0111] S1017, querying the minimum volume gain and the maximum volume gain of the USB audio decoder according to the version information and the unit number;
[0112] S1018, determining a minimum volume multiple according to a minimum volume gain, and determining a maximum volume multiple according to a maximum volume gain;
[0113] S1019: Determine a volume adjustment step according to the minimum volume multiple and the maximum volume multiple.
[0114] like Figure 5 The figure is a schematic diagram of the overall process of step S101 provided in an embodiment of the present invention. The overall process of obtaining device information of a USB audio decoder and initializing the device information in an embodiment of the present invention is as follows:
[0115] (1) Obtain the UsbDevice object through the Android USB device API (UsbManager), which represents the connected USB audio decoder;
[0116] (2) Determine whether the access permission of the UsbDevice has been obtained. If not, obtain the permission to use the UsbDevice through UsbManager.requestPermission;
[0117] (3) Use the UsbManager.openDevice method to obtain the UsbDeviceConnection object of the UsbDevice, which represents the connection information of the USB audio decoder;
[0118] (4) Get the device file descriptor FileDescriptor through UsbDeviceConnection.getFileDescriptor. We can get the C++ object of UsbDevice through FileDescriptor in JNI;
[0119] (5) Get the device's original USB descriptor RawDe scriptors through UsbDeviceConnection.getRawDescriptors, which contains the device information of the USB audio decoder;
[0120] (6) Parse the obtained RawDescriptors to obtain the device information of the USB audio decoder:
[0121] 1) USB audio decoder version information UsbVersion;
[0122] 2) The clock number of the USB audio decoder UsbClockId;
[0123] 3) USB audio decoder unit number UsbUnitID;
[0124] 4) The interface information of the USB audio decoder UsbInterface_bitDepth is saved as UsbInterface_16, UsbInterface_24, and UsbInterface_32 according to the different audio sampling bit depths bitDept h, representing interfaces that can transmit 16, 24, and 32-bit audio respectively;
[0125] (7) According to UsbClockId and UsbVersion, send the ControlTransfer command to the USB audio decoder to query the baud rate list supported by the USB audio decoder;
[0126] (8)Generally, USB audio decoders support decoding audio with sampling rates of 44.1kHz, 48kHz, 88.2kHz, 96kHz, 176.4kHz, 192kHz, 352.8kHz, and 384kHz;
[0127] (9) Send a ControlTransfer command according to UsbVersion and UsbUnitID to query the minimum volume gain dbMi n and the maximum volume gain dbMax;
[0128] (10) According to the formula dbMin=10log(pMin), dbMax=10log(pMax), the minimum volume multiple pMin and the maximum volume multiple pMax are obtained;
[0129] (11) Divide the difference between pMin and pMax into 100 equal parts: pStep = (pMax - pMin) / 100. The volume can be adjusted linearly based on pStep.
[0130] like Figure 6 FIG. 1 is a flow chart of step S102 provided in an embodiment of the present invention, referring to FIG. Figure 6 As an optional implementation, the media information of the target audio file is obtained, and the USB audio decoder is configured according to the media information and the device information, which specifically includes:
[0131] S1021, using FFmpeg to read the media information of the target audio file, and obtain the sampling frequency and sampling bit depth of the target audio file;
[0132] S1022, obtaining the current device volume, and sending a first USB gain adjustment instruction according to the version information and the unit number, so that the gain of the USB audio decoder is adjusted to the minimum volume gain;
[0133] S1023, determining the corresponding USB interface according to the sampling bit depth and the interface information, and obtaining the access right of the USB interface through UsbDeviceConnection.cl aimInterface;
[0134] S1024, switching the interface of the UsbDeviceConnection object to a USB interface, and determining the output endpoint of the USB interface;
[0135] S1025, sending a baud rate modification instruction according to the version information and the clock number, so that the baud rate of the USB audio decoding is consistent with the sampling frequency;
[0136] S1026, determining a target volume gain corresponding to the current device volume according to the minimum volume multiple, the current device volume, and the volume adjustment step;
[0137] S1027: Send a second USB gain adjustment instruction according to the version information and the unit number, so that the gain of the USB audio decoder is adjusted to the target volume gain.
[0138] like Figure 7 The figure is a schematic diagram of the overall process of step S102 provided by an embodiment of the present invention. The overall process of changing the device configuration of the USB audio decoder according to the audio information in the embodiment of the present invention is as follows:
[0139] (1) Before transferring audio to a USB audio decoder, the USB audio decoder needs to be configured according to the media information of the target high-definition lossless audio file;
[0140] (2) Initialize FFmpeg;
[0141] (3) Use FFmpeg to open the target high-definition lossless audio file;
[0142] (4) Use FFmpeg to read the media information of the target high-definition lossless audio file and obtain its sampling frequency sampleRate and sampling bit depth bitDepth;
[0143] (5) Since changing the configuration information of the USB audio decoder may cause the external sound card to make a rustling sound, which will bring a bad user experience, it is necessary to adjust the volume (i.e., gain) of the USB audio decoder to the lowest level before changing the configuration, and then change the volume back to the original level after the configuration is changed;
[0144] (6) Record the volume set by the user, where 0≤Volume≤100;
[0145] (7) According to UsbVersion and UsbUnitID, the USB gain adjustment instruction of ControlTransfer is sent through Control Transfer to adjust the gain of the USB audio decoder to dbMin;
[0146] (8) According to the sampling bit depth bitDepth, select the corresponding USB interface UsbInterface_bitDepth. For example, if the target audio sampling bit depth is 16, obtain UsbInterface_16;
[0147] (9) Request access to UsbInterface_bitDepth through UsbDeviceConnection.claimInterface;
[0148] (10) Switch the interface of UsbDeviceConnection to UsbInterface_bitDepth;
[0149] (11) Traverse all ports of UsbInterface_bitDepth and find the endpoint UsbEndpointOut of type output;
[0150] (12) According to UsbVersion and UsbClockId, the baud rate modification instruction of ControlTransfer is sent through control transmission to set the current baud rate of the USB audio decoder to be consistent with the sampleRate of the target audio obtained by FFmpeg;
[0151] (13) After the device is adjusted, the volume needs to be restored;
[0152] (14) According to the formula dbSave=10log(pMin+Volume*pStep), calculate the volume gain value db Save that needs to be restored;
[0153] (15) According to UsbVersion and UsbUnitID, a gain adjustment instruction of ControlTransfer is sent through control transmission to adjust the gain of the USB audio decoder to dbSave.
[0154] The above configuration of the USB audio decoder can be completed in a user-friendly manner.
[0155] like Figure 8 FIG. 1 is a flow chart of step S103 provided in an embodiment of the present invention, referring to FIG. Figure 8 As an optional implementation, the target audio file is decoded to obtain a lossless digital signal, and the lossless digital signal is added to a preset locked circular queue, which specifically includes:
[0156] S1031, determining that the FFmpeg decoding thread is a producer thread;
[0157] S1032, using FFmpeg's format decoder to decode the target audio file to obtain a lossless digital signal;
[0158] S1033, caching the lossless digital signal into a locked circular queue through a producer thread;
[0159] Among them, the locked circular queue is implemented by a char array plus a double pointer.
[0160] like Fig. 9 FIG. 1 is a flowchart of step S104 provided in an embodiment of the present invention, referring to FIG. Fig. 9 As an optional implementation, the lossless digital signal is read from the locked circular queue, and the lossless digital signal is decoded by a USB audio decoder to obtain a lossless analog signal, which specifically includes:
[0161] S1041, start a consumer thread for consuming the lossless digital signal in the locked circular queue;
[0162] S1042, creating an object pool, the object pool storing multiple USB data packet sending objects;
[0163] S1043, obtaining a lossless digital signal from a locked circular queue through a consumer thread, and obtaining a USB data packet sending object from an object pool;
[0164] S1044, encapsulating the lossless digital signal into a USB data packet sending object to obtain a target USB data packet,
[0165] S1045, sending the target USB data packet to the USB audio decoder through the ISO synchronous transmission mode, clearing the USB data packet, restoring the USB data packet sending object, and then adding the USB data packet sending object to the object pool;
[0166] S1046. Decode the lossless digital signal using a USB audio decoder to obtain a lossless analog signal.
[0167] like Fig.10 FIG. 1 is another step flow chart of step S104 provided in an embodiment of the present invention, referring to FIG. Fig.10 As an optional implementation, the lossless analog signal is transmitted to an audio playback device for playback, which specifically includes:
[0168] S1047, amplifying the power of the lossless analog signal by a power amplifier to obtain a target analog signal;
[0169] S1048. Play the target analog signal through headphones or speakers.
[0170] like Fig.11 The figure is a schematic diagram of device connection provided by an embodiment of the present invention. The overall process of transmitting audio data through a USB port in an embodiment of the present invention is as follows:
[0171] (1) This process uses the producer-consumer model;
[0172] (2) Let FFmpeg decoding thread be Thread1, which is the producer thread;
[0173] (3) Use FFmpeg to obtain the decoder (Note: the decoder described here is a decoder that converts audio formats such as wav to PCM format. In essence, it is still a digital signal to digital signal conversion, which is fundamentally different from the DAC decoder);
[0174] (4) Use FFmpeg's decoder to decode the target high-definition lossless audio;
[0175] (5) Use FFmpeg to read the decoded lossless digital signal;
[0176] (6) Create a circular queue CircularQueue with a thread lock to cache lossless digital signals;
[0177] (7) CircularQueue is implemented using a char array plus a double pointer, taking into account both security and efficiency;
[0178] (8) Thread1 pushes the lossless digital signal into the locked circular queue CircularQueue in real time;
[0179] (9) Start a thread Thread2 and make it execute cyclically as a consumer thread, specifically consuming the lossless digital signal in the CircularQueue;
[0180] (10) Create a USB data packet sending object TransferPool object pool to store 1024 Transfers;
[0181] (11) Thread2 loops and takes out a lossless digital signal DataItem from the CircularQueue each time, and then takes out a Transfer object from the TransferPool;
[0182] (12) Encapsulate DataItem into a Transfer object;
[0183] (13) Use the USB ISO synchronous transfer mode to send Transfer to the output endpoint UsbEndpointOut;
[0184] (14) Transfer is finished, the Transfer data is cleared, and it is put back into the sending packet object pool TransferPool for the next sending by Thread2;
[0185] (15) The USB audio decoder converts the lossless digital signal into a lossless analog signal and transmits it to the power amplifier;
[0186] (16) The power amplifier amplifies the power of the lossless analog signal and pushes it to the headphones or speakers;
[0187] (17) Play lossless music through headphones or speakers.
[0188] The above is a description of the method steps of the embodiment of the present invention. It can be appreciated that the lossless digital signal of high-definition lossless digital music can be transmitted to the USB audio decoder for playback on the Android system without using the adb mode, thereby achieving lossless playback of music, improving the sound quality, and reducing the power consumption of lossless playback of music, thereby improving the user experience.
[0189] Compared with the prior art, the embodiments of the present invention also have the following advantages:
[0190] 1. Compared with playing music directly on the Android system, the present invention uses a USB audio decoder to play lossless music;
[0191] 2. Compared with the use of adb mode to connect a USB audio decoder, the present invention is simple and user-friendly to operate, without complicated settings; it does not need to use adb mode, and uses multi-threading, circular queues with thread locks, object pools, producer-consumer mode, Android JNI and other technologies to make the program run more efficiently.
[0192] like Fig.12 FIG. 1 is a schematic diagram of the structure of a music playing device based on a USB audio decoder provided in an embodiment of the present invention. Fig.12 , an embodiment of the present invention provides a music playing device based on a USB audio decoder, comprising:
[0193] The device information acquisition module is used to acquire the original USB descriptor of the USB audio decoder and determine the device information of the USB audio decoder according to the original USB descriptor;
[0194] The device configuration module is used to obtain the media information of the target audio file and configure the USB audio decoder according to the media information and device information;
[0195] A digital signal decoding module is used to decode the target audio file to obtain a lossless digital signal, and add the lossless digital signal to a preset locked circular queue;
[0196] The analog signal decoding module is used to read the lossless digital signal from the locked circular queue, and decode the lossless digital signal through the USB audio decoder to obtain a lossless analog signal, and then transmit the lossless analog signal to the audio playback device for playback.
[0197] The contents of the above method embodiments are all applicable to the present device embodiments. The functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0198] The embodiment of the present invention also provides an electronic device, which includes: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory, and when the program is executed by the processor, the above-mentioned music playing method based on the USB audio decoder is realized. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0199] like Fig.13 FIG. 1 is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention, referring to FIG. Fig.13 , an embodiment of the present invention provides an electronic device, including:
[0200] The processor 1301 may be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of the present invention.
[0201] The memory 1302 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device or a random access memory (RAM). The memory 1302 can store an operating system and other application programs. When the technical solution provided in the embodiment of this specification is implemented by software or firmware, the relevant program code is stored in the memory 1302, and the processor 1301 calls and executes the music playing method based on the USB audio decoder of the embodiment of the present invention;
[0202] Input / output interface 1303, used to implement information input and output;
[0203] The communication interface 1304 is used to realize the communication interaction between the device and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WIFI, Bluetooth, etc.);
[0204] A bus 1305 that transmits information between the various components of the device (e.g., the processor 1301, the memory 1302, the input / output interface 1303, and the communication interface 1304);
[0205] The processor 1301 , the memory 1302 , the input / output interface 1303 and the communication interface 1304 are connected to each other in communication within the device via a bus 1305 .
[0206] like Fig.14 FIG. 1 is a schematic diagram of a storage medium according to an embodiment of the present invention. Fig.14 The embodiment of the present invention further provides a storage medium, which is a computer-readable storage medium used for computer-readable storage. The storage medium stores one or more programs 1401, and the one or more programs 1401 can be executed by one or more processors to implement the above-mentioned music playback method based on the USB audio decoder.
[0207] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0208] The embodiment of the present invention also discloses a computer program product or a computer program, wherein the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes Figure 1 The method shown.
[0209] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the above-mentioned boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part for which is described as a larger operation is performed independently.
[0210] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise specified to the contrary, one or more of the above-mentioned functions and / or features can be integrated into a single physical device and / or software module, or one or more functions and / or features can be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the present invention. More specifically, in view of the properties, functions and internal relationships of the various functional modules in the device disclosed herein, the actual implementation of the module will be understood within the conventional skills of the engineer. Therefore, those skilled in the art can implement the present invention set forth in the claims without excessive experimentation using ordinary techniques. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present invention, which is determined by the full scope of the appended claims and their equivalents.
[0211] If the above functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the above methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0212] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.
[0213] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and editable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the above-mentioned program is printed, since the above-mentioned program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or processing in other suitable ways as necessary, and then stored in a computer memory.
[0214] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0215] In the above description of this specification, the description with reference to the terms "one embodiment / example", "another embodiment / example" or "certain embodiments / examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0216] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
[0217] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the above embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.
Claims
1. A music playing method based on USB audio decoder, characterized in that: The following steps are involved: Obtaining an original USB descriptor of a USB audio decoder, and determining device information of the USB audio decoder according to the original USB descriptor; Acquire media information of a target audio file, and perform device configuration on the USB audio decoder according to the media information and the device information; Decoding the target audio file to obtain a lossless digital signal, and adding the lossless digital signal to a preset locked circular queue; The lossless digital signal is read from the locked circular queue, and the lossless digital signal is decoded by the USB audio decoder to obtain a lossless analog signal, and then the lossless analog signal is transmitted to an audio playback device for playback.
2. A music playing method based on USB audio decoder according to claim 1, characterized in that: The obtaining of the original USB descriptor of the USB audio decoder specifically includes: Obtain the UsbDevice object corresponding to the USB audio decoder through the USB device API; Obtain access rights to the UsbDevice object through UsbManager.requestPermission; Obtain the UsbDeviceConnection object corresponding to the UsbDevice object through UsbManager.openDevice; The RawDescriptors object corresponding to the UsbDeviceConnection object is obtained through UsbDeviceConnection.getFileDescriptor, and the original USB descriptor is determined according to the RawDescriptors object.
3. The music playing method based on USB audio decoder according to claim 1, characterized in that: The determining the device information of the USB audio decoder according to the original USB descriptor specifically includes: Parsing the original USB descriptor to obtain version information, clock number, unit number and interface information of the USB audio decoder; Querying a baud rate list supported by the USB audio decoder according to the version information and the clock number; Query the minimum volume gain and the maximum volume gain of the USB audio decoder according to the version information and the unit number; Determining a minimum volume multiple according to the minimum volume gain, and determining a maximum volume multiple according to the maximum volume gain; The volume adjustment step is determined according to the minimum volume multiple and the maximum volume multiple.
4. A music playing method based on USB audio decoder according to claim 3, characterized in that: The step of acquiring the media information of the target audio file and configuring the USB audio decoder according to the media information and the device information specifically includes: Use FFmpeg to read the media information of the target audio file to obtain the sampling frequency and sampling bit depth of the target audio file; Acquire the current device volume, and send a first USB gain adjustment instruction according to the version information and the unit number, so that the gain of the USB audio decoder is adjusted to the minimum volume gain; Determine the corresponding USB interface according to the sampling bit depth and the interface information, and obtain access rights to the USB interface through UsbDeviceConnection.claimInterface; Switch the interface of the UsbDeviceConnection object to the USB interface, and determine the output endpoint of the USB interface; Sending a baud rate modification instruction according to the version information and the clock number so that the baud rate of the USB audio decoding is consistent with the sampling frequency; Determine a target volume gain corresponding to the current device volume according to the minimum volume multiple, the current device volume, and the volume adjustment step; A second USB gain adjustment instruction is sent according to the version information and the unit number, so that the gain of the USB audio decoder is adjusted to the target volume gain.
5. The music playing method based on USB audio decoder according to claim 1, characterized in that: The step of decoding the target audio file to obtain a lossless digital signal and adding the lossless digital signal to a preset locked circular queue specifically includes: Determine the FFmpeg decoding thread as the producer thread; Decoding the target audio file using a format decoder of FFmpeg to obtain the lossless digital signal; Cache the lossless digital signal into the locked circular queue through the producer thread; Wherein, the locked circular queue is realized by a char array plus a double pointer.
6. A music playing method based on USB audio decoder according to claim 5, characterized in that: The method further comprises: reading the lossless digital signal from the locked circular queue, and decoding the lossless digital signal through the USB audio decoder to obtain a lossless analog signal, which specifically includes: Starting a consumer thread for consuming the lossless digital signal in the locked circular queue; Creating an object pool, wherein the object pool stores a plurality of USB data packet sending objects; Acquire the lossless digital signal from the locked circular queue through the consumer thread, and acquire the USB data packet sending object from the object pool; Encapsulating the lossless digital signal into the USB data packet sending object to obtain a target USB data packet, Sending the target USB data packet to the USB audio decoder through the ISO synchronous transmission mode, clearing the USB data packet, restoring the USB data packet sending object, and then adding the USB data packet sending object to the object pool; The lossless digital signal is decoded by the USB audio decoder to obtain the lossless analog signal.
7. A music playing method based on a USB audio decoder according to any one of claims 1 to 6, characterized in that: The step of transmitting the lossless analog signal to an audio playback device for playback specifically includes: Amplifying the power of the lossless analog signal by a power amplifier to obtain a target analog signal; Play the target analog signal through headphones or speakers.
8. A music playing device based on a USB audio decoder, characterized in that: include: A device information acquisition module, used to acquire an original USB descriptor of a USB audio decoder, and determine device information of the USB audio decoder according to the original USB descriptor; A device configuration module, used for acquiring media information of a target audio file, and performing device configuration on the USB audio decoder according to the media information and the device information; A digital signal decoding module, used for decoding the target audio file to obtain a lossless digital signal, and adding the lossless digital signal to a preset locked circular queue; The analog signal decoding module is used to read the lossless digital signal from the locked circular queue, and decode the lossless digital signal through the USB audio decoder to obtain a lossless analog signal, and then transmit the lossless analog signal to the audio playback device for playback.
9. An electronic device, characterized in that: The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection and communication between the processor and the memory. When the program is executed by the processor, the steps of the music playback method based on the USB audio decoder as described in any one of claims 1 to 7 are realized.
10. A storage medium, the storage medium being a computer-readable storage medium, used for computer-readable storage, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of the music playing method based on the USB audio decoder as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Mobile phone, system and implementation method of mobile sound card
CN106488044A
Audio processing method and electronic equipment
CN116052701A
Substantially integrated digital network and broadcast radio method and apparatus
US7079807B1
Portable audio playback device and removable disk drive
WO2001033569A1