Music playback method, apparatus, device, and medium based on USB audio decoder

By acquiring the device information of the USB audio decoder and the media information of the target audio file, using FFmpeg to decode and transmitting lossless digital signals to the USB audio decoder in a multi-threaded mode, the problem of cumbersome operation and high power consumption when playing high-definition lossless music on Android phones is solved, achieving lossless playback and improved sound quality.

CN119479668BActive Publication Date: 2025-12-02IMUSIC CULTURE & TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411643467.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-18
Publication Date
2025-12-02
Estimated Expiration
2044-11-18

AI Technical Summary

Technical Problem

In existing technologies, playing high-definition lossless music on Android phones requires enabling ADB mode, which is cumbersome and consumes a lot of power, failing to meet the needs of music lovers.

Method used

By obtaining the device information of the USB audio decoder and the media information of the target audio file, FFmpeg is used to decode the lossless digital signal. The lossless digital signal is then transmitted to the USB audio decoder for decoding and playback through a locked circular queue and multi-threaded mode, avoiding the use of adb mode.

Benefits of technology

It enables lossless playback of high-definition music on the Android system, improving sound quality and reducing power consumption, thus enhancing the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119479668B_ABST
    Figure CN119479668B_ABST
Patent Text Reader

Abstract

This invention discloses a music playback method, apparatus, device, and medium based on a USB audio decoder, comprising: acquiring the original USB descriptor of the USB audio decoder; determining the device information of the USB audio decoder based on the original USB descriptor; acquiring the media information of a target audio file; configuring the USB audio decoder based on the media information and 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; 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; and then transmitting the lossless analog signal to an audio playback device for playback. This invention achieves lossless music playback, improves sound quality, reduces power consumption during lossless music playback, thereby improving the user experience, and can be widely applied in the field of audio processing technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of audio processing technology, and in particular to a music playback method, apparatus, device, and medium based on a USB audio decoder. Background Technology

[0002] When playing music on an Android phone, the digital audio signal undergoes multiple processing steps, such as sample rate conversion and volume control. While these steps facilitate audio processing, they also result in sound quality loss. Specifically, during the sample rate conversion process in the Android system, when the music quality exceeds 16bit / 48kHz (sampling bit depth / sampling frequency), the Android system resamples the digital signal and reduces it to below 16bit / 48kHz to ensure compatibility with the phone's DAC chip. This renders ultra-high-definition lossless music as standard-resolution audio, failing to meet the needs of music lovers. Therefore, a solution is needed that allows Android phones to play high-definition lossless music.

[0003] Existing technology includes a USB audio decoder that can directly decode the raw digital audio stream and convert it into an analog signal. The decoded analog signal has a high audio signal-to-noise ratio. Android phones can use this USB decoder to directly play ultra-high-definition lossless music. However, most existing solutions for playing lossless music using a USB decoder on Android systems require enabling ADB mode, which has two drawbacks:

[0004] 1) The operation is cumbersome. Starting ADB mode on an Android system requires a series of operations in the system settings:

[0005] 2) High power consumption: When the Android system enters adb mode for audio transmission, the system will incur additional overhead.

[0006] In conclusion, there is an urgent need to develop a solution suitable for the Android system that can transmit lossless digital signals of high-definition lossless digital music to a USB decoder without using ADB mode, and can also play the music with low power consumption.

[0007] Terminology Explanation:

[0008] USB: Universal Serial Bus (USB) is a serial bus standard and a technical specification for input / 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 an audio decoder are to convert the read digital audio information into analog audio signals for output, and to decode and restore the multi-channel audio information that has been encoded during recording.

[0010] Sampling rate, also known as sampling speed or sampling frequency, defines the number of samples extracted from a continuous signal and used to assemble a discrete signal per unit time. It 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 simple terms, the sampling frequency refers to how many signal samples a computer can acquire per unit time.

[0011] Sampling bit depth: Also known as bit depth or quantization precision, it refers to the number of bits occupied by each sample point in digital audio. Simply put, it's the number of bits used to represent a sample value. This parameter determines the dynamic range and precision of digital audio, that is, the distance between the maximum and minimum amplitude 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 one value to another.

[0013] A digital-to-analog converter (DAC), also known as a D / A converter, is a device that converts digital signals into analog signals. A D / A converter basically consists of four parts: a weighted resistor network, an operational amplifier, a reference power supply, and analog switches. Analog-to-digital converters (ADCs) generally use digital-to-analog converters (A / D converters), which convert continuous analog signals into discrete digital signals.

[0014] adb: Short for Android Debug Bridge, it acts as a debugging bridge. Using adb, you can debug Android programs within Eclipse via DDMS; essentially, it's a debugging tool.

[0015] Multithreading refers to the technique of implementing concurrent execution of multiple threads through software or hardware. Computers with multithreading capabilities can execute more than one thread at a time due to hardware support, thereby improving overall processing performance. Systems with this capability include symmetric multiprocessors, multi-core processors, and chip-level multiprocessor or simultaneous multithreaded processors. In a program, these independently running program segments are called "threads," and the concept of programming using them is called "multithreaded processing."

[0016] A circular queue, also known as a circular queue, is a special storage structure for queues. In this structure, the front and rear of the queue are connected, forming a closed loop.

[0017] Object pooling is an efficient memory management technique, particularly suitable for scenarios that require frequent object creation and destruction. Using object pooling reduces the system overhead of creating each object from scratch.

[0018] The Producer-Consumer Pattern is a classic multithreaded design pattern used to solve the coordination problem between producers and consumers in a multithreaded environment. This pattern typically involves two or more threads: a producer thread responsible for generating data and placing it into a buffer; and a consumer thread responsible for retrieving data from the buffer and processing it.

[0019] JNI: JNI stands for Java Native Interface. By using Java native interfaces to write programs, it ensures that the code is easily portable across different platforms. Starting with Java 1.1, the JNI standard became part of the Java platform, allowing Java code to interact with code written in other languages. JNI was initially designed for natively compiled languages, especially C and C++, but it doesn't prevent you from using other programming languages, as long as the calling conventions are supported.

[0020] Audio gain: Audio gain is a physics term that refers to the degree of increase in current, voltage, or power of a component, circuit, device, or system.

[0021] FFmpeg: An open-source computer program that can be used to record, convert, and stream digital audio and video.

[0022] USB Version: This refers to the version number of the USB (Universal Serial Bus) transmission protocol.

[0023] USB Clock: The USB clock is the clock signal used in USB (Universal Serial Bus) for synchronizing data transmission.

[0024] USB Unit ID: This refers to the USB (Universal Serial Bus) processing unit ID, which is the number of the USB processing unit. Summary of the Invention

[0025] The purpose of this invention is to at least partially solve one of the technical problems existing in the prior art.

[0026] Therefore, one objective of this invention is to provide a music playback method based on a USB audio decoder, which achieves lossless music playback, improves sound quality, reduces power consumption during lossless music playback, and thus enhances the user experience.

[0027] Another objective of this invention is to provide a music playback device based on a USB audio decoder.

[0028] To achieve the above-mentioned technical objectives, the technical solutions adopted in the embodiments of the present invention include:

[0029] On one hand, embodiments of the present invention provide a music playback method based on a USB audio decoder, comprising the following steps:

[0030] Obtain the raw USB descriptor of the USB audio decoder, and determine the device information of the USB audio decoder based on the raw USB descriptor;

[0031] Obtain the media information of the target audio file, and configure the USB audio decoder based on the media information and the device information;

[0032] 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;

[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, which is then transmitted to the audio playback device for playback.

[0034] Furthermore, in one embodiment of the present invention, obtaining the raw 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 permissions to the UsbDevice object using UsbManager.requestPermission;

[0037] Obtain the UsbDeviceConnection object corresponding to the UsbDevice object through UsbManager.openDevice;

[0038] Obtain the RawDescriptors object corresponding to the UsbDeviceConnection object using UsbDeviceConnection.getFileDescriptor, and determine the raw USB descriptor based on the RawDescriptors object.

[0039] Furthermore, in one embodiment of the present invention, determining the device information of the USB audio decoder based on the original USB descriptor specifically includes:

[0040] The original USB descriptor is parsed to obtain the version information, clock number, unit number, and interface information of the USB audio decoder;

[0041] Based on the version information and the clock number, query the list of baud rates supported by the USB audio decoder;

[0042] Based on the version information and the unit number, query the minimum and maximum volume gain of the USB audio decoder;

[0043] The minimum volume multiple is determined based on the minimum volume gain, and the maximum volume multiple is determined based on the maximum volume gain;

[0044] The volume adjustment step size is determined based on the minimum volume multiple and the maximum volume multiple.

[0045] Furthermore, in one embodiment of the present invention, the step of obtaining 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:

[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] Obtain the current device volume, and send a first USB gain adjustment command 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] The corresponding USB interface is determined based on the sampling bit depth and the interface information, and access permissions for the USB interface are obtained 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] A baud rate modification command is sent based on the version information and the clock number to make the baud rate of the USB audio decoder consistent with the sampling frequency;

[0051] The target volume gain corresponding to the current device volume is determined based on the minimum volume multiple, the current device volume, and the volume adjustment step size.

[0052] A second USB gain adjustment command is sent based on the version information and the unit number, causing the gain of the USB audio decoder to be adjusted to the target volume gain.

[0053] Furthermore, in one embodiment of the present invention, 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:

[0054] The FFmpeg decoding thread is designated as the producer thread.

[0055] The target audio file is decoded using FFmpeg's format decoder to obtain the lossless digital signal;

[0056] The lossless digital signal is cached in the locked circular queue by the producer thread;

[0057] The locked circular queue is implemented using a char array and two pointers.

[0058] Furthermore, in one embodiment of the present invention, reading the lossless digital signal from the locked circular queue and decoding the lossless digital signal using the USB audio decoder to obtain a lossless analog signal specifically includes:

[0059] Start a consumer thread for consuming the lossless digital signals in the locked circular queue;

[0060] Create an object pool that stores multiple USB data packet sending objects;

[0061] The consumer thread retrieves the lossless digital signal from the locked circular queue and obtains the USB data packet sending object from the object pool.

[0062] The lossless digital signal is encapsulated into the USB data packet sending object to obtain the target USB data packet.

[0063] The target USB data packet is sent to the USB audio decoder via ISO synchronous transmission mode, and the USB data packet is cleared to restore the USB data packet sending object. Then, the USB data packet sending object is added to the object pool.

[0064] The lossless digital signal is decoded by the USB audio decoder to obtain the lossless analog signal.

[0065] Furthermore, in one embodiment of the present invention, transmitting the lossless analog signal to an audio playback device for playback specifically includes:

[0066] The lossless analog signal is amplified by a power amplifier to obtain the target analog signal.

[0067] The target analog signal is played through headphones or speakers.

[0068] On the other hand, embodiments of the present invention provide a music playback device based on a USB audio decoder, comprising:

[0069] 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 based on the original USB descriptor.

[0070] The device configuration module is used to obtain media information of the target audio file and configure the USB audio decoder according to the media information and the device information.

[0071] 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;

[0072] The analog signal decoding module is used to read the lossless digital signal from the locked circular queue, 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, embodiments of the present invention provide an electronic device, the electronic device including a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for implementing communication between the processor and the memory, wherein the program, when executed by the processor, implements the music playback method based on the USB audio decoder as described above.

[0074] On the other hand, embodiments of the present invention also provide a storage medium, which is a computer-readable storage medium for computer-readable storage. The storage medium stores one or more programs, which 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 set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention:

[0076] This invention provides an embodiment of the method for obtaining the original USB descriptor of a USB audio decoder, determining the device information of the USB audio decoder based on the original USB descriptor, obtaining the media information of the target audio file, configuring the USB audio decoder based on the media information and device information, decoding the target audio file to obtain a lossless digital signal, adding the lossless digital signal to a preset locked circular queue, 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 is then transmitted to an audio playback device for playback. This invention allows the transmission of high-definition lossless digital music signals to a USB audio decoder for playback on an Android system without using ADB mode, achieving lossless music playback, improving sound quality, reducing power consumption during lossless music playback, and thus enhancing the user experience. Attached Figure Description

[0077] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the embodiments of the present invention are described below. It should be understood that the drawings described below are only for the convenience of clearly describing some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0078] Figure 1 A flowchart illustrating the steps of a music playback method based on a USB audio decoder provided in an embodiment of the present invention;

[0079] Figure 2 This is a schematic diagram of the overall process of a music playback method based on a USB audio decoder provided in an embodiment of the present invention;

[0080] Figure 3 A flowchart of step S101 provided in an embodiment of the present invention;

[0081] Figure 4 Another flowchart of step S101 provided in an embodiment of the present invention;

[0082] Figure 5 This is a schematic diagram of the overall process of step S101 provided in an embodiment of the present invention;

[0083] Figure 6 A flowchart of step S102 provided in an embodiment of the present invention;

[0084] Figure 7This is a schematic diagram of the overall process of step S102 provided in an embodiment of the present invention;

[0085] Figure 8 A flowchart of step S103 provided in an embodiment of the present invention;

[0086] Figure 9 A flowchart of step S104 provided in an embodiment of the present invention;

[0087] Figure 10 Another flowchart of step S104 provided in an embodiment of the present invention;

[0088] Figure 11 This is a schematic diagram of device connection provided in an embodiment of the present invention;

[0089] Figure 12 This is a schematic diagram of the structure of a music playback device based on a USB audio decoder provided in an embodiment of the present invention;

[0090] Figure 13 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention;

[0091] Figure 14 This is a schematic diagram of the structure of the storage medium provided in an embodiment of the present invention. Detailed Implementation

[0092] The embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application. It should be noted that although functional modules are divided in the system schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the system schematic diagram or the order in the flowchart. The step numbers in the following embodiments are only set for ease of explanation and do not limit the order between steps. The execution order of each step in the embodiments can be adaptively adjusted according to the understanding of those skilled in the art.

[0093] In the description of this invention, "multiple" means two or more. The use of "first" and "second" is for distinguishing technical features only and should not be construed as indicating or implying relative importance, the number of indicated technical features, or the order of the indicated technical features. Furthermore, unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0094] The music playback method based on a USB audio decoder provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, set-top box, etc.; the server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the music playback method based on a USB audio decoder, etc., but is not limited to the above forms.

[0095] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This 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. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0096] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards of the relevant countries and regions. In addition, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirects to confirmation pages. Only after obtaining the user's separate permission or consent is the necessary user-related data for the proper functioning of the embodiments of this application obtained.

[0097] like Figure 1 The diagram shows a flowchart of a music playback method based on a USB audio decoder provided in an embodiment of the present invention. (Refer to...) Figure 1 This invention provides a music playback method based on a USB audio decoder, specifically including the following steps:

[0098] S101. Obtain the original USB descriptor of the USB audio decoder, and determine the device information of the USB audio decoder based on the original USB descriptor;

[0099] S102. Obtain the media information of the target audio file, and configure the USB audio decoder according to the media information and device information.

[0100] S103. Decode the target audio file to obtain a lossless digital signal, and add the lossless digital signal to a preset locked circular queue;

[0101] S104. Read the lossless digital signal from the locked circular queue, decode the lossless digital signal to obtain the lossless analog signal through the USB audio decoder, and then transmit the lossless analog signal to the audio playback device for playback.

[0102] like Figure 2The diagram shows the overall flow of a music playback method based on a USB audio decoder provided in this embodiment of the invention. This embodiment adapts to the USB protocol of the USB audio decoder and utilizes technologies such as multithreading, a circular queue with thread locks, object pooling, producer-consumer pattern, and Android JNI. This allows for the transmission of lossless digital signals of high-definition lossless digital music to the USB audio decoder for playback on the Android system without using ADB mode. This achieves lossless music playback, improves sound quality, reduces power consumption during lossless music playback, and thus enhances the user experience. The method steps of this embodiment are further described below. It should be noted that step S101 of this embodiment is implemented in Java, while the remaining steps are implemented in C++ using Android JNI, which improves program efficiency.

[0103] like Figure 3 The diagram shown is a flowchart of step S101 provided in an embodiment of the present invention. (Refer to...) Figure 3 As an optional implementation, the raw USB descriptor of the USB audio decoder is obtained, specifically including:

[0104] S1011. Obtain the UsbDevice object corresponding to the USB audio decoder through the USB device API;

[0105] S1012. Obtain access permissions for the UsbDevice object through UsbManager.requestPermission;

[0106] S1013. Obtain the UsbDeviceConnection object corresponding to the UsbDevice object through UsbManager.openDevice;

[0107] S1014. Obtain the RawDescriptors object corresponding to the UsbDeviceConnection object through UsbDeviceConnection.getFileDescriptor, and determine the raw USB descriptor based on the RawDescriptors object.

[0108] like Figure 4 The diagram shown is another flowchart of step S101 provided in an embodiment of the present invention. (Refer to...) Figure 4 As an optional implementation, the device information of the USB audio decoder is determined based on the original USB descriptor, specifically including:

[0109] S1015. Parse the original USB descriptor to obtain the version information, clock number, unit number, and interface information of the USB audio decoder.

[0110] S1016. Query the list of baud rates supported by the USB audio decoder based on the version information and clock number;

[0111] S1017. Query the minimum and maximum volume gain of the USB audio decoder based on the version information and unit number.

[0112] S1018. Determine the minimum volume multiple based on the minimum volume gain, and determine the maximum volume multiple based on the maximum volume gain;

[0113] S1019. Determine the volume adjustment step size based on the minimum volume multiple and the maximum volume multiple.

[0114] like Figure 5 The diagram shown is a schematic representation of the overall process of step S101 provided in an embodiment of the present invention. The overall process of obtaining and initializing the USB audio decoder 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). This object represents the connected USB audio decoder.

[0116] (2) Determine whether the UsbDevice has been granted access permissions. If not, obtain the UsbDevice's access permissions through UsbManager.requirePermission.

[0117] (3) Use the UsbManager.openDevice method to obtain the UsbDeviceConnection object of UsbDevice, which represents the connection information of the USB audio decoder;

[0118] (4) By using UsbDeviceConnection.getFileDescriptor, we can obtain the device file descriptor FileDescriptor and then use FileDescriptor to obtain the C++ object of UsbDevice in JNI.

[0119] (5) Obtain the device's raw USB descriptors (RawDescriptors) through UsbDeviceConnection.getRawDescriptors. The raw descriptors contain device information for the USB audio decoder.

[0120] (6) Parse the obtained RawDescriptors to get the device information of the USB audio decoder:

[0121] 1) USB audio decoder version information UsbVersion;

[0122] 2) The clock ID of the USB audio decoder, UsbClockId;

[0123] 3) The unit number (UsbUnitID) of the USB audio decoder;

[0124] 4) The interface information of the USB audio decoder, UsbInterface_bitDepth, is stored as UsbInterface_16, UsbInterface_24, and UsbInterface_32 according to the different sampling bit depths of the audio, which represent interfaces that can transmit 16, 24, and 32 bits of audio, respectively.

[0125] (7) Based on UsbClockId and UsbVersion, send the ControlTransfer command to the USB audio decoder to query the list of baud rates 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 based on UsbVersion and UsbUnitID to query the minimum volume gain dbMi n and the maximum volume gain dbMax;

[0128] (10) According to the formulas dbMin=10log(pMin) and 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 parts, pStep = (pMax - pMin) / 100, and then adjust the volume linearly according to pStep.

[0130] like Figure 6 The diagram shown is a flowchart of step S102 provided in an embodiment of the present invention. (Refer to...) Figure 6 As an optional implementation, the media information of the target audio file is obtained, and the USB audio decoder is configured based on the media information and device information, specifically including:

[0131] S1021. Use 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. Obtain the current device volume, and send the first USB gain adjustment command according to the version information and unit number, so that the gain of the USB audio decoder is adjusted to the minimum volume gain.

[0133] S1023. Determine the corresponding USB interface based on the sampling bit depth and interface information, and obtain access permissions for the USB interface through UsbDeviceConnection.cl aimInterface;

[0134] S1024. Switch the interface of the UsbDeviceConnection object to the USB interface and determine the output endpoint of the USB interface;

[0135] S1025. Send a baud rate modification command according to the version information and clock number to make the baud rate of USB audio decoding consistent with the sampling frequency.

[0136] S1026. Determine the target volume gain corresponding to the current device volume based on the minimum volume multiple, the current device volume, and the volume adjustment step size;

[0137] S1027. Send a second USB gain adjustment command according to the version information and unit number, so that the gain of the USB audio decoder is adjusted to the target volume gain.

[0138] like Figure 7 The diagram shown is a schematic representation of the overall process of step S102 provided in 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 an embodiment of the present invention is as follows:

[0139] (1) Before transmitting audio to the 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 rate and sampling bit depth;

[0143] (5) Since changing the configuration information of the USB audio decoder may cause the external sound card to make a hissing sound, which will bring a bad experience to the user, the volume (i.e. gain) of the USB audio decoder needs to be turned to the lowest level before changing the configuration, and the volume should be turned 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) Based on UsbVersion and UsbUnitID, send the USB gain adjustment command of ControlTransfer via Control Transfer to adjust the gain of the USB audio decoder to dbMin;

[0146] (8) Select the corresponding USB interface UsbInterface_bitDepth according to the sampling bit depth bitDepth. For example, if the target audio sampling bit depth is 16, then obtain UsbInterface_16.

[0147] (9) Request access permissions for UsbInterface_bitDepth via UsbDeviceConnection.claimInterface;

[0148] (10) Switch the interface of UsbDeviceConnection to UsbInterface_bitDepth;

[0149] (11) Iterate through all ports of UsbInterface_bitDepth and find the endpoint UsbEndpointOut of type output;

[0150] (12) Based on UsbVersion and UsbClockId, send the ControlTransfer baud rate modification command through control transfer 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 equipment has been adjusted, the volume needs to be restored;

[0152] (14) Calculate the volume gain value db Save that needs to be restored according to the formula dbSave=10log(pMin+Volume*pStep);

[0153] (15) Based on UsbVersion and UsbUnitID, send the gain adjustment command of ControlTransfer through control transfer to adjust the gain of the USB audio decoder to dbSave.

[0154] The above steps complete the configuration of the USB audio decoder in a user-friendly manner.

[0155] like Figure 8 The diagram shown is a flowchart of step S103 provided in an embodiment of the present invention. (Refer to...) 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, specifically including:

[0156] S1031. Determine that the FFmpeg decoding thread is the producer thread;

[0157] S1032. Use FFmpeg's format decoder to decode the target audio file to obtain a lossless digital signal;

[0158] S1033. The lossless digital signal is cached into a locked circular queue through the producer thread;

[0159] The locked circular queue is implemented using a char array and two pointers.

[0160] like Figure 9 The diagram shown is a flowchart of step S104 provided in an embodiment of the present invention. (Refer to...) Figure 9 As an optional implementation, a lossless digital signal is read from a locked circular queue and decoded using a USB audio decoder to obtain a lossless analog signal, specifically including:

[0161] S1041. Start a consumer thread for consuming lossless digital signals in a locked circular queue;

[0162] S1042. Create an object pool. The object pool stores multiple USB data packet sending objects.

[0163] S1043. Obtain lossless digital signals from the locked circular queue through the consumer thread, and obtain USB data packet sending objects from the object pool;

[0164] S1044. Encapsulate the lossless digital signal into the USB data packet sending object to obtain the target USB data packet.

[0165] S1045. Send the target USB data packet to the USB audio decoder through ISO synchronous transmission mode, clear the USB data packet, restore the USB data packet sending object, and then add 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 Figure 10 The diagram shown is another flowchart of step S104 provided in an embodiment of the present invention. (Refer to...) Figure 10 As an optional further implementation, lossless analog signals are transmitted to an audio playback device for playback, specifically including:

[0168] S1047. The lossless analog signal is amplified by a power amplifier to obtain the target analog signal;

[0169] S1048. Play the target analog signal through headphones or speakers.

[0170] like Figure 11 The diagram shown is a device connection diagram provided in an embodiment of the present invention. The overall process of transmitting audio data through the USB port in this embodiment of the present invention is as follows:

[0171] (1) This process uses the producer-consumer model;

[0172] (2) Let Thread1 be the FFmpeg decoding thread, and use it as the producer thread;

[0173] (3) Use FFmpeg to find the decoder (Note: The decoder mentioned here is a decoder that converts audio formats such as wav to PCM format. It is essentially a digital signal to digital signal conversion and is fundamentally different from a 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 with a thread lock to buffer lossless digital signals;

[0177] (7) Among them, CircularQueue is implemented using a char array and two pointers, which balances safety and efficiency;

[0178] (8) Thread1 pushes lossless digital signals into the locked circular queue CircularQueue in real time;

[0179] (9) Start a thread Thread2 and make it execute in a loop as a consumer thread, specifically consuming lossless digital signals in CircularQueue;

[0180] (10) Create a USB data packet sending object TransferPool to store 1024 Transfers;

[0181] (11) Thread2 loop retrieves a lossless digital signal DataItem from CircularQueue each time, and then retrieves a Transfer object from TransferPool;

[0182] (12) Encapsulate the DataItem into a Transfer object;

[0183] (13) Use the ISO synchronous transfer mode of USB to send Transfer to the output endpoint UsbEndpointOut;

[0184] (14) After the Transfer is completed, the Transfer data is cleared and put back into the TransferPool, so that Thread2 thread can use it for the next transfer.

[0185] (15) The USB audio decoder converts lossless digital signals into lossless analog signals and transmits them 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) The headphones or speakers play lossless music.

[0188] The method steps of the embodiments of the present invention have been described above. It can be understood that lossless digital signals of high-definition lossless digital music can be transmitted to a USB audio decoder for playback on an Android system without using ADB mode, achieving lossless music playback, improving sound quality, reducing power consumption during lossless music playback, and thus enhancing the user experience.

[0189] Compared with the prior art, the embodiments of the present invention also have the following advantages:

[0190] 1. Compared to playing music directly on an Android system, this invention uses a USB audio decoder to play lossless music;

[0191] 2. Compared with using adb mode to connect to a USB audio decoder, this invention is simple and user-friendly to operate, without complicated settings; it does not require the use of adb mode, and improves program running efficiency through multi-threading, circular queues with thread locks, object pools, producer-consumer patterns, Android JNI and other technologies.

[0192] like Figure 12 The diagram shown is a structural schematic of a music playback device based on a USB audio decoder provided in an embodiment of the present invention. (Refer to...) Figure 12 This invention provides a music playback 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 based on 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 based on the media information and device information.

[0195] The 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 lossless digital signals from a locked circular queue, decode the lossless digital signals to obtain lossless analog signals through a USB audio decoder, and then transmit the lossless analog signals to an audio playback device for playback.

[0197] The content of the above method embodiments is applicable to the device embodiments. The specific functions implemented by the 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] This invention also provides an electronic device, comprising: a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for communication between the processor and the memory. When the program is executed by the processor, it implements the aforementioned music playback method based on a USB audio decoder. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.

[0199] like Figure 13 The diagram shown is a hardware structure schematic of an electronic device provided in an embodiment of the present invention. (Refer to...) Figure 13 This invention provides an electronic device, comprising:

[0200] The processor 1301 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, 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 as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 1302 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1302 and is called and executed by the processor 1301 to execute the music playback method based on the USB audio decoder of the embodiments of this invention.

[0202] The input / output interface 1303 is used to implement information input and output;

[0203] The communication interface 1304 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).

[0204] Bus 1305 transmits information between various components of the device (e.g., processor 1301, memory 1302, input / output interface 1303, and communication interface 1304);

[0205] The processor 1301, memory 1302, input / output interface 1303 and communication interface 1304 are connected to each other within the device via bus 1305.

[0206] like Figure 14 The diagram shown is a structural schematic of the storage medium provided in an embodiment of the present invention. (Refer to...) Figure 14 The present invention also provides a storage medium, which is a computer-readable storage medium for computer-readable storage. The storage medium stores one or more programs 1401, which can be executed by one or more processors to implement the above-described music playback method based on a USB audio decoder.

[0207] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.

[0208] This invention also discloses a computer program product or computer program, which includes computer instructions 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, causing the computer device to perform... Figure 1 The method shown.

[0209] In some alternative embodiments, the functions / operations mentioned in the block diagrams may not occur in the order shown in the operation diagrams. For example, depending on the functions / operations involved, two consecutively shown blocks may actually be executed substantially simultaneously, or the aforementioned blocks may sometimes be executed in reverse order. Furthermore, the embodiments presented and described in the flowcharts of this invention are provided by way of example to provide a more comprehensive understanding of the technology. The disclosed methods are not limited to the operations and logic flows presented herein. Alternative embodiments are contemplated in which the order of various operations is changed and sub-operations described as part of a larger operation are executed independently.

[0210] Furthermore, although the invention has been described in the context of functional modules, it should be understood that, unless otherwise stated, one or more of the aforementioned functions and / or features may be integrated into a single physical device and / or software module, or one or more functions and / or features may 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 invention. Rather, given the properties, functions, and internal relationships of the various functional modules in the apparatus disclosed herein, the actual implementation of the module will be understood within the scope of conventional skill of an engineer. Therefore, those skilled in the art can implement the invention as set forth in the claims using ordinary techniques without excessive experimentation. It is also understood that the specific concepts disclosed are merely illustrative and not intended to limit the scope of the invention, which is determined by the full scope of the appended claims and their equivalents.

[0211] If the aforementioned functions are implemented as 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 this invention, or the part that contributes to the prior art, or a 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, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this 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), random access memory (RAM), magnetic disks, or optical disks.

[0212] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.

[0213] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the aforementioned program can be printed, because the aforementioned program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or, if necessary, processing in other suitable ways, and then stored in computer memory.

[0214] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0215] In the foregoing description of this specification, references to terms such as "one embodiment," "another embodiment," or "some embodiments" indicate that a specific feature, structure, material, or characteristic described in connection with an embodiment or example is included in at least one embodiment or example of the present invention. In this specification, illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0216] Although embodiments of the invention have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.

[0217] The above is a detailed description of the preferred embodiments of the present invention. However, the present invention is not limited to the above embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.

Claims

1. A music playback method based on a USB audio decoder, characterized in that, Includes the following steps: Obtain the raw USB descriptor of the USB audio decoder, and determine the device information of the USB audio decoder based on the raw USB descriptor; Obtain the media information of the target audio file, and configure the USB audio decoder based on the media information and the device information; 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; 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 is then transmitted to an audio playback device for playback. The process 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: The FFmpeg decoding thread is designated as the producer thread. The target audio file is decoded using FFmpeg's format decoder to obtain the lossless digital signal; The lossless digital signal is cached in the locked circular queue by the producer thread; The locked circular queue is implemented using a char array and two pointers. 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, specifically including: Start a consumer thread for consuming the lossless digital signals in the locked circular queue; Create an object pool that stores multiple USB data packet sending objects; The consumer thread retrieves the lossless digital signal from the locked circular queue and obtains the USB data packet sending object from the object pool. The lossless digital signal is encapsulated into the USB data packet sending object to obtain the target USB data packet. The target USB data packet is sent to the USB audio decoder via ISO synchronous transmission mode, and the USB data packet is cleared to restore the USB data packet sending object. Then, the USB data packet sending object is added to the object pool. The lossless digital signal is decoded by the USB audio decoder to obtain the lossless analog signal.

2. The music playback method based on a USB audio decoder according to claim 1, characterized in that, The process of obtaining the raw 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 permissions to the UsbDevice object using UsbManager.requestPermission; Obtain the UsbDeviceConnection object corresponding to the UsbDevice object through UsbManager.openDevice; Obtain the RawDescriptors object corresponding to the UsbDeviceConnection object using UsbDeviceConnection.getFileDescriptor, and determine the raw USB descriptor based on the RawDescriptors object.

3. The music playback method based on a USB audio decoder according to claim 1, characterized in that, The step of determining the device information of the USB audio decoder based on the original USB descriptor specifically includes: The original USB descriptor is parsed to obtain the version information, clock number, unit number, and interface information of the USB audio decoder; Based on the version information and the clock number, query the list of baud rates supported by the USB audio decoder; Based on the version information and the unit number, query the minimum and maximum volume gain of the USB audio decoder; The minimum volume multiple is determined based on the minimum volume gain, and the maximum volume multiple is determined based on the maximum volume gain; The volume adjustment step size is determined based on the minimum volume multiple and the maximum volume multiple.

4. The music playback method based on a 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 based on 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; Obtain the current device volume, and send a first USB gain adjustment command 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; The corresponding USB interface is determined based on the sampling bit depth and the interface information, and access permissions for the USB interface are obtained through UsbDeviceConnection.claimInterface. Switch the interface of the UsbDeviceConnection object to the USB interface, and determine the output endpoint of the USB interface; A baud rate modification command is sent based on the version information and the clock number to make the baud rate of the USB audio decoder consistent with the sampling frequency; The target volume gain corresponding to the current device volume is determined based on the minimum volume multiple, the current device volume, and the volume adjustment step size. A second USB gain adjustment command is sent based on the version information and the unit number, causing the gain of the USB audio decoder to be adjusted to the target volume gain.

5. A music playback method based on a USB audio decoder according to any one of claims 1 to 4, characterized in that, The step of transmitting the lossless analog signal to an audio playback device for playback specifically includes: The lossless analog signal is amplified by a power amplifier to obtain the target analog signal. The target analog signal is played through headphones or speakers.

6. A music playback device based on a USB audio decoder, characterized in that, A music playback method based on a USB audio decoder as described in any one of claims 1 to 5 includes: 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 based on the original USB descriptor. The device configuration module is used to obtain media information of the target audio file and configure the USB audio decoder according to the media information and the device information. 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; The analog signal decoding module is used to read the lossless digital signal from the locked circular queue, decode the lossless digital signal to obtain a lossless analog signal through the USB audio decoder, and transmit the lossless analog signal to the audio playback device for playback.

7. 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 establishing communication between the processor and the memory. When the program is executed by the processor, it implements the steps of the music playback method based on a USB audio decoder as described in any one of claims 1 to 5.

8. A storage medium, said storage medium being a computer-readable storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the music playback method based on a USB audio decoder as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Mobile phone, system and implementation method of mobile sound card

    CN106488044A

  • Audio processing method and electronic equipment

    CN116052701A