ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING MP3 and Opus audio player. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Audio equipment This article describes a homemade portable player for music files of common formats from a microSD memory card. It is assembled on the STM32F407VGT6 microcontroller in a case from a NOKIA 1100 cell phone. The player scheme is shown in fig. 1. It makes maximum use of the electronic components available on the STM32F4DISCOVERY development board. These include the STM32F407VGT6 (DD1) microcontroller, LD3985M25R (DA1) and LD3985M33R (DA3) integrated voltage regulators, CS43L22 (DD2) codec, as well as the necessary passive components. From the cell phone NOKIA 1100, in addition to the case and the battery, a connector for connecting XS3 headphones, a front panel with an LCD HG1, membranes for buttons SB1-SB17 formed by concentric contact pads on a printed circuit board, and a connector for connecting a G1 battery were used. In addition, the player's board contains a holder for a microSD memory card TFC-WPCE-08 (XS1), a group of contact pads for connecting the Xp1 programmer, a miniUSB-B 5075BMR-05-SM (XS2) connector.
Diode assemblies VD1, VD4, VD5, VD6 are used to protect against electrostatic discharge circuits connected to connectors XS2 and XS3. The remaining connectors are located inside the battery compartment and do not need protection. Chip (DA2) is a G1 lithium-ion battery charge controller with a maximum voltage of 4,2 V. Resistor R9 reduces the voltage drop on this chip during charging, causing it to heat up. Resistor R10 set the maximum charging current Isal.max according to formula Iper ap.max = 1000/R10. With resistance R10 set in kiloohms, the value of the charging current is obtained in milliamps. It is recommended to charge a lithium-ion battery with a current of no more than 1C, where C is the battery capacity. The capacity of the used BL-5C battery is about 1000 mAh, the maximum allowable charging current for the LTC4054ES5-4.2 chip is 800 mA. Since charging is carried out from the USB bus, its load capacity (500 mA) must also be taken into account. Thus, the recommended value of R10 is 2 kOhm. In addition, by measuring the voltage across R10, you can determine the current value of the battery charging current using the formula Izar= 1000 UR10/ R10 (current - in milliamps, voltage - in volts, resistance - in kiloohms). When the XS2 connector is connected to the USB bus, the field-effect transistor VT1 disconnects the battery G1 from the player's power circuit. A voltage of 5 V from pin 1 of connector XS2 opens transistor VT5, the gate voltage of transistor VT3 becomes negative relative to its source. Transistor VT3 opens, including the player. When there is no voltage on pin 1 of connector XS2, the gate potential of transistor VT3 is close to its source potential and the transistor is closed. Pressing the SB1 button also opens the transistor VT3, the microcontroller starts working and checks the status of this button every 10 ms. If it is held down for more than 2 seconds, the microcontroller will set a high voltage level at the base of transistor VT2, opening it and keeping transistor VT3 open. After that, the player goes into working condition, and the button can be released. Turn off the player by pressing and holding the SB1 button again. After switching on, the microcontroller initializes the HG1 LCD and the microSD card inserted into the XS1 holder, checks for the presence of the player.ini configuration file in the root directory of the card (FAT12, FAT16, FAT32 file systems are supported). This is a regular ini file, which is a set of "key - value" lines. It stores information about the audio file selected for playback at the time the player was last turned off, the position in it and the volume set. The program tries to restore this state. In case of failure (for example, if the card has been replaced), the first audio file (with the extension .mp3 or .opus) on the card is searched. The search starts from the root directory, the files are searched in the order in which they are listed in the file allocation table on the map. During playback, the MainThread function of the current decoder is periodically called, which performs reading from the card as needed (each codec is responsible for buffering itself, since the formats of the audio packet containers for .opus and .mp3 are different) and decoding. The need to perform these operations is determined by the fullness of the circular AudioBuffer buffer, from which the audio codec asynchronously reads information. Upon completion of decoding the current audio file, the next one is searched according to the principle described above. If file system traversal is completed, playback stops. The player interacts with the user using a graphic monochrome HG1 LCD with a resolution of 96x65 px and buttons SB 1 -SB 17. A software simulation of the text display mode is used with the screen split into eight lines of 8 px height. The remaining 1px horizontal bar at the bottom of the screen is used to visually display the current position in the file during playback. The first line from the top displays (from left to right) battery voltage, player status, volume. The status is characterized by the characters "0" - playback, "-" - pause, "<<" or ">>" - fast rewind or fast forward, respectively, within the file. The symbol in the form of a rectangle means an error in the communication of the DD1 and DD2 microcircuits via the I interface2C. Lines 2-6 show the full path to the audio file being played. Line 8 displays the current playback time on the left, and the duration of the audio file on the right. The SB1 button switches between playback and pause modes, the SB3 button increases the volume, and the SB5 button decreases the volume, the SB4 button turns on, and the keypad lock is turned off with the SB15 button. When the keypad is locked, "Locked" is displayed in the center of line 7 of the display. Pressing the SB6 button leads to the transition to the playback of the previous file, and the SB8 button - the next. Pressing and holding these buttons for more than a second puts the player into fast-forward mode, rewinding or forwarding, respectively. Pressing the SB9 or SB11 button loads the first and last files of the current directory for playback, respectively. Connector XS3 - available in the housing used for connecting a headset. The headset itself has a jack for a standard audio plug with a diameter of 3,5 mm, to which headphones are connected. The headset also provides a button that, when pressed, connects the BTN and GND circuits, and the resistance between the contacts of the released button is about a kiloohm. In the player, the BTN line is connected to the 3,3 V circuit through a resistor R21, therefore, by measuring the voltage on this line, one can judge both the presence of a connected headset and the state of its button. The function of the headset button is similar to the function of the SB1 player button - you can switch it from playback to pause mode, and vice versa, and also turn it off. However, you can not turn on the player using it. When the keyboard is locked, the headset button remains active. The XS2 connector takes the place of the LED flashlight lens in the phone. When a high logic level is detected at the PA1 input of the microcontroller connected to pin 9 of this connector, the program starts to display the battery charging current in amperes in the upper right corner of the display. In addition, this event automatically turns on the player if it was turned off. By default, after that, the player works in normal playback mode, which allows you to listen to music and charge the battery at the same time. When you press the SB13 button, the program saves the player's state in the player.ini file and configures the USB microcontroller module to work in MSC (Mass Storage Class) mode. In this mode, the computer recognizes the player connected to the USB connector as a removable storage device, the contents of which match those recorded on the microSD card inserted into the player. Information is exchanged with the computer only in Full Speed mode with a bandwidth of no more than 12 Mbps. The display still shows the current value of the charging current, in line 3 - the inscription "USB Disk", in lines 4 and 5 - respectively, the speed of reading and writing. By pressing the SB12 button, the device returns to the player mode. The drawing of the printed circuit board of the player is shown in fig. 2. Its dimensions and shape are identical to the board of the NOKIA 1100 cell phone, in which case it is placed (Fig. 3). The board must be manufactured according to the technology with metallized holes, otherwise it is necessary to insert and solder pieces of tinned wire on both sides into all vias (with pads on both sides of the board) and solder them on both sides. The location of the parts on the board is shown in fig. 4 in 2:1 scale. It also shows masks made of heat-resistant insulating varnish, which must be used to protect the printed conductors. If the masks are not applied, then it is necessary to isolate at least the areas where the conductors approach the printed contacts of the buttons and the area under the metal case of the microSD XS1 card holder.
The codes from the walkgeek-v1.2-n1100-with-mp3.hex file attached to the article must be entered into the memory of the microcontroller installed on the board. The source code of the player program and all its components is distributed under the New BSD License (and other compatible ones), which allows its use in closed commercial projects. The exception is the Mp3dec library, the addition of which to the final product requires the disclosure of all source codes. The project is constantly updated, and its updated versions are posted in [1]. As already mentioned, the player provides the ability to play Opus files. This is a recently released stable version of a software codec [2] for lossy audio compression developed by the Xiph.org project, known for such solutions as Vorbis, FLAC (Free Lossless Audio Codec - codec for lossless audio compression) and Speex (speech codec). You can also call it Ogg - a universal media container that is used by default to pack a compressed stream in Opus files. Since the Opus codec is quite new, there are not many implementations of it on systems with a small amount of RAM. One of them is Rockbox. In the process of working with the codec, it turned out that the Ogg library dynamically allocates memory for caching the entire page (the theoretical maximum size is 65 KB, the real one is about 26 KB), as well as for granulepos caching of all page packets (about 16 KB), which for a device, having 192 KB of RAM, a lot. Moreover, the library by default allocates a small area of memory for the page buffer, expanding it during operation and each time allocating memory "with a margin". The same happens with the buffer for lacing values - information about the distribution of packages on the page. Thus, if the dynamic memory pool is small, it soon leads to its significant fragmentation and the impossibility of further allocation of memory of the required amount. As a result of the changes made to the libraries, caching is performed at the packet level (the maximum size of a packet of stereo information transmitted at a rate of 512 Kbps is, in practice, 1276 bytes). The maximum buffer size for lacing values is 256 double-byte cells, and they can also be made single-byte. Thus, all structures associated with the Ogg container, after modification, take up less than 2 KB of RAM. Some assumptions were made in the modification: packets cannot cross page boundaries, page checksums are not checked (none of these were found in any of the Opus files). Work with files containing more than one stream, and with the number of channels different from two has not been tested. The total amount of memory consumed by the Opus codec is 65088 bytes, of which 3856 bytes are occupied by the output buffer. The results of codec profiling at different information flow rates are shown in Table. 1. Table 1
The concept of "complexity" in it refers to the processor performance required for successful decoding. It was estimated by simple calculation using a hardware timer of the difference between the moments of entry into the decoding procedure of each frame and exit from it (with preemptive multitasking disabled and interrupts disabled). The test showed that the MP3 codec requires less computational effort. But Opus is royalty-free, and the sound quality is better when using it than when using MP3 and the same bit rate. There is a version of the player program for the STM32F4DISCOVERY debug board. The codes that need to be entered into the memory of the microcontroller installed on it are in the file walkgeek-v1. 1 -stm32f4discovery-with-mp3.hex (also attached to the article). In this case, audio files are played from a USB flash drive connected to the board's CN5 connector via an adapter. The player acts as USB bus master. Its status is displayed by orange, red, blue and green LEDs on the board. Red indicates no, green indicates the presence of a connected FLASH drive, orange indicates an audio file is being loaded, playback has stopped or a program error, blinking blue indicates playback mode. Most of the buttons available in the diagram in Fig. 1, connected to the debug board according to the table. 2 (the second contact of each button is connected to a common wire). The role of the SB8 button is performed by the "User" button of the board. The display from the NOKIA 1100 phone is connected to the debug board in accordance with the table. 3. Table 2
Table 3
Literature
Author: O. Tsaregorodtsev See other articles Section Audio equipment. Read and write useful comments on this article. Latest news of science and technology, new electronics: Machine for thinning flowers in gardens
02.05.2024 Advanced Infrared Microscope
02.05.2024 Air trap for insects
01.05.2024
Other interesting news: ▪ Dual independent analog NLAST9431 ▪ The driver will not fall asleep on the road ▪ Smell generator for virtual reality helmet ▪ Netgear Nighthawk M1 Mobile Router News feed of science and technology, new electronics
Interesting materials of the Free Technical Library: ▪ section of the site Note to the student. Article selection ▪ article Theory of Accounting. Lecture notes ▪ article What is the most common metal in the earth's crust? Detailed answer ▪ article Self-propelled monoski. Personal transport ▪ article Turning water into blood. Chemical experience
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |