Music playing method, system and device based on PWM (Pulse Width Modulation) and medium

Through the audio playback method based on PWM dynamic threshold division and time domain and frequency domain feedback mechanism, the problem of poor playback effect of traditional PWM technology in resource-constrained devices is solved, and efficient, low-cost and high-quality audio playback is achieved.

CN120602842APending Publication Date: 2025-09-05GUANGZHOU GUANGYOU COMM EQUIP
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202510702167.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-28
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

Traditional PWM technology has difficulty adapting to the dynamic changes of audio signals when processing complex audio signals, resulting in poor playback effects. In addition, existing methods are costly, power-intensive, and have large delays, making it difficult to meet the low-cost, low-power, and miniaturization requirements of resource-constrained devices.

Method used

A PWM-based music playback method is adopted to generate a PWM signal corresponding to the audio data through dynamic threshold division and time domain and frequency domain feedback mechanism to drive the speaker to output sound, reduce dependence on cache space, and optimize system startup speed.

Benefits of technology

This achieves efficient, high-fidelity, and low-cost audio playback in resource-constrained devices, reduces sound latency, improves sound quality, and simplifies circuit complexity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120602842A_ABST
    Figure CN120602842A_ABST
Patent Text Reader

Abstract

The invention discloses a music playing method, system and device based on PWM and a medium, and the method comprises the steps: obtaining to-be-played audio data, carrying out the preprocessing of the audio data, and obtaining the time domain information and frequency domain information of the audio data; determining a first threshold group to which the audio data belongs according to the time domain information; generating a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information and the first threshold group; and driving the loudspeaker to output sound according to the PWM signal. Through dynamic threshold division and a feedback mechanism based on a time domain and a frequency domain, the problems of an existing voice or music playing method in the aspects of cost, tone quality, power consumption, delay and circuit complexity are solved, efficient, high-fidelity and low-cost playing of voice or music in resource-limited equipment is achieved, and the method can be widely applied to the technical field of audio playing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of audio playback technology, and in particular to a PWM-based music playback method, system, device, and medium. Background Art

[0002] With the advancement of technology, audio playback devices are becoming increasingly popular, and people's demands for audio quality are also increasing. Traditional audio playback methods have limitations when processing voice and music signals. For example, analog audio amplifiers are susceptible to noise and distortion and have low efficiency. While digital audio playback technology offers advantages in accuracy, it also faces the challenge of more accurately reproducing the audio signal when converting the digital signal to analog to drive the speakers.

[0003] PWM technology is widely used in audio playback due to its advantages in digital control and power conversion. By controlling the duty cycle of the PWM signal, audio signals of varying amplitudes can be simulated. However, traditional PWM technology struggles to adapt to the dynamic changes of complex audio signals, resulting in suboptimal playback performance.

[0004] Existing technologies also suffer from the drawback of relying on specialized DSPs and audio decoding chips. These traditional approaches suffer from high costs, high power consumption, significant latency, and complex circuits. This makes them particularly difficult to meet the low-cost, low-power, and miniaturized requirements of resource-constrained devices, such as IoT devices and small embedded systems. Summary of the Invention

[0005] 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.

[0006] To this end, an object of an embodiment of the present invention is to provide a PWM-based music playback method, which solves the problems of existing voice or music playback methods in terms of cost, sound quality, power consumption, delay and circuit complexity through dynamic threshold division and feedback mechanism based on time domain and frequency domain, and realizes efficient, high-fidelity and low-cost playback of voice or music in resource-constrained devices.

[0007] Another object of an embodiment of the present invention is to provide a music playing system based on PWM.

[0008] In order to achieve the above technical objectives, the technical solutions adopted by the embodiments of the present invention include:

[0009] In a first aspect, an embodiment of the present invention provides a music playing method based on PWM, comprising:

[0010] Acquire audio data to be played, preprocess the audio data, and obtain time domain information and frequency domain information of the audio data;

[0011] determining a first threshold group to which the audio data belongs according to the time domain information;

[0012] generating a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group;

[0013] The speaker is driven to output sound according to the PWM signal.

[0014] Furthermore, the preprocessing of the audio data to obtain time domain information and frequency domain information of the audio data includes:

[0015] Performing format conversion and resampling on the audio data according to a preset sampling rate and sampling accuracy to obtain digital audio data of uniform specifications, and determining the time domain information based on the digital audio data;

[0016] Perform frequency domain transformation on the digital audio data to obtain the frequency domain information.

[0017] Further, determining the first threshold group to which the audio data belongs according to the time domain information includes:

[0018] determining an amplitude interval of the audio data according to the time domain information;

[0019] The first threshold group is determined according to the amplitude interval and a preset threshold grouping rule.

[0020] Furthermore, generating a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group includes:

[0021] Within a plurality of preset sliding time windows, calculating a time domain variation amplitude of the audio data according to the time domain information, and calculating a energy distribution variation amplitude of the audio data according to the frequency domain information;

[0022] When the time domain variation amplitude exceeds a preset first threshold, the threshold value group corresponding to the current time domain information is used as the first threshold value group;

[0023] When the frequency domain energy distribution variation of the audio data exceeds a preset second threshold, performing coefficient correction on the first threshold group according to the frequency domain information;

[0024] A modulation parameter of the PWM signal is determined according to the time domain information, the frequency domain information, and the first threshold value group, and the PWM signal is generated according to the modulation parameter.

[0025] Furthermore, calculating the time domain variation amplitude of the audio data according to the time domain information and calculating the energy distribution variation amplitude of the audio data according to the frequency domain information within a plurality of preset sliding time windows includes:

[0026] Calculating a root mean square value of the audio data in each sliding time window according to the time domain information, and determining the time domain variation amplitude according to the root mean square value;

[0027] Energy distribution data of the audio data at specific frequency points in each sliding time window is calculated according to the frequency domain information, and the energy distribution variation amplitude is determined according to each energy distribution data.

[0028] Furthermore, the modulation parameters include a duty cycle, a modulation frequency, and a modulation accuracy. Determining the modulation parameters of the PWM signal according to the time domain information, the frequency domain information, and the first threshold value group, and generating the PWM signal according to the modulation parameters includes:

[0029] determining a duty cycle of the PWM signal according to the time domain information;

[0030] determining a modulation frequency of the PWM signal according to the frequency domain information;

[0031] determining a modulation accuracy of the PWM signal according to the first threshold value group;

[0032] The PWM signal is generated according to the duty cycle, the modulation frequency, and the modulation accuracy.

[0033] Furthermore, driving the speaker to output sound according to the PWM signal includes:

[0034] Performing low-pass filtering on the PWM signal to obtain an analog audio signal;

[0035] The analog audio signal is pre-amplified and power-amplified to drive the speaker to output sound.

[0036] In a second aspect, an embodiment of the present invention provides a PWM-based music playback system, comprising:

[0037] An audio preprocessing module, configured to obtain audio data to be played, preprocess the audio data, and obtain time domain information and frequency domain information of the audio data;

[0038] a threshold grouping module, configured to determine a first threshold group to which the audio data belongs based on the time domain information;

[0039] a PWM signal modulation module, configured to generate a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group;

[0040] The music playing module is used to drive the speaker to output sound according to the PWM signal.

[0041] In a third aspect, an embodiment of the present invention provides a device, including:

[0042] at least one processor;

[0043] at least one memory for storing at least one program;

[0044] When the at least one program is executed by the at least one processor, the at least one processor implements the above-mentioned PWM-based music playing method.

[0045] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium storing a program executable by a processor, wherein the program executable by the processor is used to execute the above-mentioned PWM-based music playback method when executed by the processor.

[0046] The advantages and benefits of the present invention will be described in part in the following description and will become apparent from the following description or learned through practice of the present invention:

[0047] The embodiment of the present invention uses PWM-based real-time data processing technology to directly convert audio data into PWM signals for playback while receiving it, thereby reducing sound delay and lowering dependence on cache space. The PWM modulation algorithm is designed through dynamic threshold division and a feedback mechanism based on the time domain and frequency domain, which can adjust the modulation strategy according to the real-time characteristics of the audio signal, thereby achieving high-quality music playback that is closer to the original sound. The system startup speed is optimized through the collaborative design of software and hardware. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 A schematic diagram of the steps of a PWM-based music playing method provided by an embodiment of the present invention;

[0049] Figure 2 A schematic diagram of a software workflow for an implementation scenario provided by an embodiment of the present invention;

[0050] Figure 3 A schematic diagram of a hardware workflow for an implementation scenario provided by an embodiment of the present invention;

[0051] Figure 4 A schematic diagram of a PWM-based music playback system provided by an embodiment of the present invention;

[0052] Figure 5 A schematic structural diagram of a device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0053] The embodiments of the present invention are described in detail below. 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 invention and are not to be construed as limiting the present invention. The step numbers in the following embodiments are provided for ease of explanation only and do not limit the order of the steps. The order of execution of the steps in the embodiments can be adaptively adjusted according to the understanding of those skilled in the art.

[0054] In the description of the present invention, "a plurality" means two or more. The terms "first" and "second" are used solely to distinguish technical features and are not to be construed as indicating or implying relative importance, or as implicitly indicating the number of the indicated technical features, or as implicitly indicating the order of the indicated technical features. Furthermore, unless otherwise defined, all technical and scientific terms used herein have the same meanings as commonly understood by those skilled in the art.

[0055] Glossary:

[0056] PWM (Pulse Width Modulation): PWM is a technology that controls the output average voltage by adjusting the high-level duration (duty cycle) of the signal within a fixed period.

[0057] Figure 1 A schematic diagram of the steps of a PWM-based music playing method provided by an embodiment of the present invention, referring to Figure 1 , an embodiment of the present invention provides a music playing method based on PWM, comprising:

[0058] S101, obtaining audio data to be played, preprocessing the audio data, and obtaining time domain information and frequency domain information of the audio data;

[0059] In some optional embodiments, preprocessing the audio data to obtain time domain information and frequency domain information of the audio data includes:

[0060] S1011, performing format conversion and resampling on the audio data according to a preset sampling rate and sampling accuracy to obtain digital audio data of uniform specifications, and determining time domain information based on the digital audio data;

[0061] S1012: Perform frequency domain transformation on the digital audio data to obtain frequency domain information.

[0062] Specifically, digital audio data or raw audio data of speech or music can be obtained from a storage medium or network transmission channel, the obtained audio data can be parsed, and the sampling and data normalization processing can be performed according to the audio format, and uniformly converted to the set sampling rate and data accuracy. In this embodiment, the time domain signal can be quantized into 16-bit data at a sampling rate of 44.1kHz, and the frequency domain signal can be simplified to the energy values ​​of three key frequency points of 1kHz, 3kHz, and 5kHz (quantized into 8-bit data), thereby reducing the amount of data processing.

[0063] S102. Determine a first threshold group to which the audio data belongs based on the time domain information;

[0064] In some optional embodiments, determining the first threshold group to which the audio data belongs based on the time domain information includes:

[0065] S1021, determining the amplitude range of the audio data according to the time domain information;

[0066] S1022: Determine a first threshold group according to the amplitude range and a preset threshold grouping rule.

[0067] Specifically, in this embodiment, eight basic thresholds T1-T8 are pre-stored in the microprocessor's on-chip flash memory. These thresholds are divided into four threshold groups based on the amplitude range of the audio signal. The threshold range to which the audio sampling point belongs is determined based on the amplitude of the audio sampling point in the current time window, thereby determining the corresponding threshold group. This serves as the basis for subsequent selection of PWM modulation parameters. Taking a 16-bit time domain signal as an example, the threshold groups can be divided into a silent group: {T1=0, T2=255}, a weak sound group: {T3=256, T4=3071}, a medium sound group: {T5=3072, T6=24575}, and a strong sound group: {T7=24576, T8=65535}. Each threshold group corresponds to a different PWM modulation parameter optimization scheme. For example, the weak sound group adopts a finer pulse width resolution, while the strong sound group focuses on fast response.

[0068] S103, generating a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group;

[0069] In some optional embodiments, generating a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group includes:

[0070] S1031. Within a plurality of preset sliding time windows, calculate the time domain variation amplitude of the audio data based on the time domain information, and calculate the energy distribution variation amplitude of the audio data based on the frequency domain information;

[0071] In some optional embodiments, within a plurality of preset sliding time windows, calculating the time domain variation amplitude of the audio data based on the time domain information and calculating the energy distribution variation amplitude of the audio data based on the frequency domain information includes:

[0072] S10311. Calculate the root mean square value of the audio data in each sliding time window based on the time domain information, and determine the time domain variation amplitude based on the root mean square value;

[0073] S10312. Calculate energy distribution data of the audio data at specific frequency points in each sliding time window based on the frequency domain information, and determine an energy distribution variation amplitude based on each energy distribution data.

[0074] S1032: When the time domain change amplitude exceeds a preset first threshold, the threshold group corresponding to the current time domain information is used as the first threshold group;

[0075] S1033: When the amplitude of the change in the frequency domain energy distribution of the audio data exceeds a preset second threshold, modify the coefficients of the first threshold group according to the frequency domain information;

[0076] Specifically, in this embodiment, the RMS value (root mean square value) of the amplitude of the audio signal in the current sliding window is calculated in real time as the time domain change amplitude, and it is determined whether the change in the RMS value exceeds the threshold. Assuming that the RMS value fluctuates by more than 30% within 10ms, it means that the threshold group corresponding to the amplitude interval of the audio data in the current time window has changed, and it is necessary to re-divide the threshold group according to the matching rules of the threshold group. For example, when the RMS value jumps from the mid-tone group range to the strong sound group range, it automatically switches to the strong sound group threshold. At the same time, the energy distribution of the audio signal at three key frequency points is monitored. When the energy ratio of the high frequency band (3kHz+5kHz) exceeds 60%, the coefficient of the current threshold group is corrected. For example, the current threshold is multiplied by a coefficient of 0.68 to enhance the modulation accuracy of the high-frequency signal.

[0077] S1034 : Determine modulation parameters of the PWM signal according to the time domain information, the frequency domain information, and the first threshold value group, and generate the PWM signal according to the modulation parameters.

[0078] In some optional embodiments, the modulation parameters include a duty cycle, a modulation frequency, and a modulation accuracy. Determining the modulation parameters of the PWM signal based on the time domain information, the frequency domain information, and the first threshold value group, and generating the PWM signal based on the modulation parameters includes:

[0079] S10341. Determine a duty cycle of the PWM signal according to the time domain information;

[0080] S10342. Determine a modulation frequency of the PWM signal according to the frequency domain information;

[0081] S10343. Determine a modulation accuracy of the PWM signal according to the first threshold value group;

[0082] S10344. Generate a PWM signal according to the duty cycle, modulation frequency, and modulation accuracy.

[0083] Specifically, in this embodiment, a microcontroller with PWM functionality (such as AVP32F335, GD32F103, etc.) can be used to establish a corresponding relationship between audio signals and PWM signals through a software program. The PWM duty cycle is adjusted based on the time domain characteristics of the audio signal, such as the amplitude (e.g., the audio data of the mid-range group is mapped to a duty cycle of 10%-49%). Based on the frequency domain characteristics of the audio signal, for example, in the low frequency range of 20Hz-500Hz, the PWM frequency is adaptively adjusted to 96kHz; in the mid-frequency range of 500Hz-3kHz, the PWM frequency is adaptively adjusted to 384kHz; and in the high frequency range of 3kHz-20kHz, the PWM frequency is adaptively adjusted to 512kHz. The corresponding data registers of the PWM module are updated in real time, and the corresponding PWM signals are output to ensure the quality and accuracy of audio playback. At the same time, each threshold group corresponds to a set of PWM modulation parameters, including the pulse width resolution of the PWM signal, the mapping range between the duty cycle and the audio amplitude, etc. The modulation accuracy is determined based on the modulation parameters corresponding to the threshold to which the current audio signal belongs, and the PWM signal is ultimately generated.

[0084] S104: Drive the speaker to output sound according to the PWM signal.

[0085] In some optional embodiments, driving a speaker to output sound according to a PWM signal includes:

[0086] S1041, low-pass filtering the PWM signal to obtain an analog audio signal;

[0087] S1042: Pre-amplify and power-amplify the analog audio signal to drive the speaker to output sound.

[0088] Specifically, in this embodiment, the generated PWM signal is passed through a low-pass filter to filter out the high-frequency components in the PWM signal and restore an approximate analog audio signal. The low-pass filter adopts an RC low-pass filter with low cost and very simple circuit. The resistance and capacitance parameters of the filter are reasonably selected to determine the cutoff frequency of the filter so that it can effectively filter out high-frequency noise and retain the effective frequency components of the audio signal. The filtered analog audio signal is pre-amplified and then power-amplified to drive the speaker to output sound. The analog audio signal is pre-amplified and a low-noise operational amplifier is selected for amplification; according to the rated power and impedance of the speaker, a suitable power amplifier is selected to ensure that the output power of the power amplifier can meet the working requirements of the speaker, and the gain of the power amplifier is adjusted according to the characteristics of the speaker and the required volume, so as to achieve clear playback of voice or music.

[0089] The present invention will be further described below with reference to a specific embodiment.

[0090] Figure 2 A software workflow diagram for an implementation scenario provided by the present invention, referring to Figure 2 In this embodiment, a microcontroller obtains audio data from a storage medium or a network via an SPI (synchronous serial peripheral interface); the microcontroller processes the audio data and converts it into a format suitable for PWM through dynamic threshold grouping and a dual-feedback adaptive adjustment mechanism to control the PWM module in the microprocessor to output a PWM signal; a simple RC (resistance-capacitance) low-pass filter circuit filters the PWM signal and converts it into an analog audio signal; a low-noise operational amplifier (NE5532) pre-amplifies the audio signal, and then a power amplifier (LM1875) amplifies the power to drive the speaker to output sound.

[0091] Figure 3 A software workflow diagram for an implementation scenario provided by the present invention, referring to Figure 3 In this embodiment, the system needs to be initialized first, the system clock is initialized, the GPIO is initialized, and the PWM output pin is configured to an appropriate function; the PWM module is initialized and the PWM period, duty cycle and other parameters are set; the timer is initialized to generate an interrupt and control the reading and processing of the duty cycle data; then, audio data is read from the audio data source and the audio data is sampled, the data is normalized, and dynamic threshold grouping is performed based on its amplitude range. A dual-feedback adaptive adjustment mechanism based on the time domain and frequency domain is used to calculate the appropriate PWM duty cycle and frequency according to the modulation parameters corresponding to the threshold group; when the timer overflows, an interrupt is triggered, the duty cycle data is read, and the corresponding data register of the PWM module is updated; the corresponding PWM signal is output through the PWM module; and the audio data is continuously read from the audio data source for processing.

[0092] It can be appreciated that the embodiments of the present invention utilize PWM-based real-time data processing technology, eliminating the need for a dedicated digital signal processor and audio decoding chip, and pre-storing a large amount of audio data in memory. Audio data can be received and directly converted into a PWM signal for playback, reducing sound delay while also reducing reliance on cache space. This makes the system particularly suitable for small embedded devices with limited memory resources. A PWM modulation algorithm is designed through dynamic threshold division and a feedback mechanism based on time and frequency domains, enabling modulation strategies to be adjusted based on the real-time characteristics of the audio signal, thereby achieving high-quality music playback that is closer to the original sound. Through a hardware-software collaborative PWM fast-start mechanism, the hardware optimizes the startup circuit of the PWM generator, enabling it to quickly enter a working state. The software simplifies the startup process, directly skipping unnecessary initialization steps. After receiving audio data, the system can convert the audio signal into a PWM signal and output it for playback in a very short time.

[0093] Reference Figure 4 , an embodiment of the present invention provides a PWM-based music playing system, comprising:

[0094] The audio preprocessing module is used to obtain the audio data to be played, preprocess the audio data, and obtain the time domain information and frequency domain information of the audio data;

[0095] a threshold grouping module, configured to determine a first threshold group to which the audio data belongs based on the time domain information;

[0096] a PWM signal modulation module, configured to generate a PWM signal corresponding to the audio data based on the time domain information, the frequency domain information, and the first threshold value group;

[0097] The music player module is used to drive the speaker to output sound according to the PWM signal.

[0098] The contents of the above method embodiments are all applicable to the present system embodiments. The functions specifically implemented by the present system 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.

[0099] Reference Figure 5 , an embodiment of the present invention provides a device, including:

[0100] at least one processor;

[0101] at least one memory for storing at least one program;

[0102] When the at least one program is executed by the at least one processor, the at least one processor implements the PWM-based music playing method.

[0103] An embodiment of the present invention further provides a computer-readable storage medium storing a program executable by a processor. When the program is executed by the processor, it is used to perform the above-mentioned PWM-based music playing method.

[0104] A computer-readable storage medium according to an embodiment of the present invention can execute a PWM-based music playback method provided by an embodiment of the present invention, can execute any combination of implementation steps of the embodiment of the method, and has the corresponding functions and beneficial effects of the method.

[0105] The embodiment of the present 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 device can read the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the device performs Figure 1 The PWM-based music playing method shown.

[0106] In some optional 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 in an exemplary manner for the purpose of providing a more comprehensive understanding of the technology. The disclosed method is not limited to the operation and logic flow presented herein. Optional embodiments are contemplated in which the order of the various operations is changed and the sub-operations described as a part of a larger operation are performed independently.

[0107] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise stated, 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 separate physical devices or software modules. It is also understood that a detailed discussion of the actual implementation of each module is not necessary for understanding the present invention. More specifically, given the properties, functions, and internal relationships of the various functional modules in the devices disclosed herein, the actual implementation of the module will be understood within the routine skills of an engineer. Therefore, a person skilled in the art can implement the present invention set forth in the claims using ordinary skills without undue experimentation. 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.

[0108] 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 and includes several instructions for enabling a device (which can be a personal computer, server, or 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 various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0109] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing the 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 (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device). For purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution system, apparatus, or device.

[0110] More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk cartridge (magnetic devices), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disc read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable media on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, deciphering, or processing in another suitable manner as necessary, and then stored in a computer memory.

[0111] It should be understood that various parts of the present invention can be implemented using hardware, software, firmware, or a combination thereof. In the above-described embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0112] In the above description of this specification, reference to the terms "one embodiment / example," "another embodiment / example," or "certain embodiments / examples" 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 suitable manner in any one or more embodiments or examples.

[0113] While 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 invention, and that the scope of the invention is defined by the claims and their equivalents.

[0114] 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 can 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 PWM, characterized in that: include: Acquire audio data to be played, preprocess the audio data, and obtain time domain information and frequency domain information of the audio data; determining a first threshold group to which the audio data belongs according to the time domain information; generating a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group; The speaker is driven to output sound according to the PWM signal.

2. The PWM-based music playing method according to claim 1, characterized in that: The preprocessing of the audio data to obtain time domain information and frequency domain information of the audio data includes: Performing format conversion and resampling on the audio data according to a preset sampling rate and sampling accuracy to obtain digital audio data of uniform specifications, and determining the time domain information based on the digital audio data; Perform frequency domain transformation on the digital audio data to obtain the frequency domain information.

3. The PWM-based music playing method according to claim 1, characterized in that: The determining, according to the time domain information, the first threshold group to which the audio data belongs includes: determining an amplitude interval of the audio data according to the time domain information; The first threshold group is determined according to the amplitude interval and a preset threshold grouping rule.

4. The PWM-based music playing method according to claim 1, characterized in that: The generating a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group includes: Within a plurality of preset sliding time windows, calculating a time domain variation amplitude of the audio data according to the time domain information, and calculating a energy distribution variation amplitude of the audio data according to the frequency domain information; When the time domain variation amplitude exceeds a preset first threshold, the threshold value group corresponding to the current time domain information is used as the first threshold value group; When the frequency domain energy distribution variation of the audio data exceeds a preset second threshold, performing coefficient correction on the first threshold group according to the frequency domain information; A modulation parameter of the PWM signal is determined according to the time domain information, the frequency domain information, and the first threshold value group, and the PWM signal is generated according to the modulation parameter.

5. The PWM-based music playing method according to claim 4, characterized in that: The step of calculating the time domain variation amplitude of the audio data according to the time domain information and calculating the energy distribution variation amplitude of the audio data according to the frequency domain information within a plurality of preset sliding time windows includes: Calculating a root mean square value of the audio data in each sliding time window according to the time domain information, and determining the time domain variation amplitude according to the root mean square value; Energy distribution data of the audio data at specific frequency points in each sliding time window is calculated according to the frequency domain information, and the energy distribution variation amplitude is determined according to each energy distribution data.

6. The PWM-based music playing method according to claim 4, characterized in that: The modulation parameters include a duty cycle, a modulation frequency, and a modulation accuracy. The determining the modulation parameters of the PWM signal according to the time domain information, the frequency domain information, and the first threshold value group, and generating the PWM signal according to the modulation parameters includes: determining a duty cycle of the PWM signal according to the time domain information; determining a modulation frequency of the PWM signal according to the frequency domain information; determining a modulation accuracy of the PWM signal according to the first threshold value group; The PWM signal is generated according to the duty cycle, the modulation frequency, and the modulation accuracy.

7. The PWM-based music playing method according to claim 1, characterized in that: The step of driving the speaker to output sound according to the PWM signal comprises: Performing low-pass filtering on the PWM signal to obtain an analog audio signal; The analog audio signal is pre-amplified and power-amplified to drive the speaker to output sound.

8. A music playing system based on PWM, characterized in that: include: An audio preprocessing module, configured to obtain audio data to be played, preprocess the audio data, and obtain time domain information and frequency domain information of the audio data; a threshold grouping module, configured to determine a first threshold group to which the audio data belongs based on the time domain information; a PWM signal modulation module, configured to generate a PWM signal corresponding to the audio data according to the time domain information, the frequency domain information, and the first threshold value group; The music playing module is used to drive the speaker to output sound according to the PWM signal.

9. A device, characterized in that: include: at least one processor; at least one memory for storing at least one program; When the at least one program is executed by the at least one processor, the at least one processor implements the PWM-based music playing method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a program executable by a processor, characterized in that: The processor-executable program is used to execute a PWM-based music playing method as described in any one of claims 1 to 7 when executed by the processor.

Citation Information

Patent Citations

  • Signal conversion system and method

    CN104272687A

  • Signal conversion system and method

    US20150015426A1

  • Audio signal processing device

    US20150245137A1

  • Class d power amplification modulation system for self-adaptive adjustment of audio signal, method, device, processor and storage medium

    US20230327616A1