CN114968168B - Independent control method for output volume of android application - Google Patents

Independent control method for output volume of android application Download PDF

Info

Publication number
CN114968168B
CN114968168B CN202210919261.8A CN202210919261A CN114968168B CN 114968168 B CN114968168 B CN 114968168B CN 202210919261 A CN202210919261 A CN 202210919261A CN 114968168 B CN114968168 B CN 114968168B
Authority
CN
China
Prior art keywords
audio data
android application
android
volume value
volume
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210919261.8A
Other languages
Chinese (zh)
Other versions
CN114968168A (en
Inventor
温研
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Linzhuo Information Technology Co Ltd
Original Assignee
Beijing Linzhuo Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Linzhuo Information Technology Co Ltd filed Critical Beijing Linzhuo Information Technology Co Ltd
Priority to CN202210919261.8A priority Critical patent/CN114968168B/en
Publication of CN114968168A publication Critical patent/CN114968168A/en
Application granted granted Critical
Publication of CN114968168B publication Critical patent/CN114968168B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/16Sound input; Sound output
    • G06F3/165Management of the audio stream, e.g. setting of volume, audio stream path
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Multimedia (AREA)
  • Health & Medical Sciences (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • General Health & Medical Sciences (AREA)
  • Human Computer Interaction (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Reverberation, Karaoke And Other Acoustics (AREA)
  • Circuit For Audible Band Transducer (AREA)

Abstract

The invention discloses an independent control method for output volume of an android application, which is characterized in that the android application is bound with an AudioTrack, the adjusted volume value is transmitted by adopting the AudioTrack, the audio data is adjusted by adopting a control volume value after the audio data is resampled by an android system, and finally the output of the adjusted audio data is finished by adopting the corresponding AudioTrack, so that the independent control of the output volume of the android application is realized, and the user experience is improved.

Description

Independent control method for output volume of android application
Technical Field
The invention belongs to the technical field of android system development, and particularly relates to an independent control method for output volume of an android application.
Background
In an android system, when multiple android applications play audio, each android application creates an AudioTrack, each AudioTrack transfers data through a Track sharing a memory and a playing thread, the format of audio data sent by each android application may be different, and a sound card generally supports only several fixed formats, so that the audio data needs to be resampled and mixed in most cases, and the resampling refers to a processing process of converting an audio format which is not supported by hardware into an audio format which is supported by hardware.
The processing process is that the Audio track transmits data to a sound mixing thread through a shared memory, the sound mixing thread analyzes and judges whether the format of the audio data is supported by hardware, a Hook function of the audio data is set according to whether the format of the audio data is supported or not, and then a total Hook function is determined, specifically, the Hook function for resampling is set for the audio data with different formats; during sound mixing, all audio data can be processed only by calling a general Hook function, including resampling the audio data, then carrying out sound mixing processing on the processed audio data, and finally sending the data subjected to the sound mixing processing to hardware. The android system can provide support for independently controlling output volumes of different android applications by adopting the operation.
When running the android application on the desktop system, generally adopt the mode of installing the compatible environment of android on the desktop system, make the android application run in the compatible environment of android, the user can use the android application in the compatible environment of android, for example, the realization scheme of the compatible environment of existing android has xDroid, it includes xDroid UI and xDroid Server, xDroid UI is the application display element of android, xDroid Server is the compatible service of android application. However, the existing use mode does not support the user to independently control the output volume of the android application, which brings inconvenience to the user and influences the user experience.
Disclosure of Invention
In view of this, the present invention provides an independent control method for the output volume of an android application, which can realize independent control of the output volume of the android application running in an android compatible environment.
The invention provides an independent control method for output volume of an android application, which comprises the following steps:
step 1, when a user opens an android application in a desktop system, sending a taskID of the android application to an android compatible environment; when a user outputs audio by using an android application, the android compatible environment determines the type of an example Track of an AudioTrack required to be adopted by the android application, if the type of the Track is STREAM _ MUSIC, the received taskId is bound with the Track, and meanwhile, after a volume array of each channel volume value is added and stored for the Track, the creation of the Track is completed; if the type of the Track is non-STREAM _ MUSIC, the creation of the Track is completed;
step 2, when the user adjusts the output volume of the android application, judging whether the current operation object is the android application positioned on the uppermost layer of the desktop, if so, executing the step 3, otherwise, executing the step 2;
step 3, pausing sending the event for adjusting the output volume of the android application to an android application compatible service, and obtaining the volume value of the adjusted output volume of the android application, wherein the volume value is a floating point value with a value between 0 and 1; sending the volume value and taskId of the android application to an AudioFlinger in the android compatible environment;
step 4, the AudioFlinger finds the Track bound with the same taskId as a target Track, and assigns a value to each element in a volume array of the target Track by adopting a volume value; and adjusting the audio data based on the volume value and resampling the audio data to obtain new audio data, and outputting the new audio data by adopting the target Track.
Further, the manner of completing the adjustment of the audio data based on the volume value and the resampling of the audio data to obtain new audio data in the step 4 is as follows: and after a re-sampler built in the android system is started to re-sample the audio data, adjusting each byte of the audio data by adopting the volume value to obtain new audio data.
Further, the manner of obtaining new audio data after adjusting each byte of the audio data by using the volume value is as follows: and multiplying the volume value by each byte of the audio data to obtain new audio data.
Further, the manner of completing the adjustment of the audio data based on the volume value and the resampling of the audio data to obtain new audio data in the step 4 is as follows: and adjusting each byte of the audio data by adopting the volume value to obtain intermediate audio data, and starting a resampler to complete the processing of the intermediate audio data to obtain new audio data.
Further, the manner of obtaining the intermediate audio data after adjusting each byte of the audio data by using the volume value is as follows: and multiplying the volume value and each byte of the audio data to obtain intermediate audio data.
Further, when the user in the step 1 opens the android application in the desktop system, the taskId of the android application is sent to the android compatible environment by the android application display unit.
Further, the android application display unit is an xdroidus, and the android application compatible service is an xDroidServer.
Has the advantages that:
according to the invention, the android application and the AudioTrack are bound, the adjusted volume value is transmitted by adopting the AudioTrack, the audio data is adjusted by adopting the control volume value after the audio data is resampled by the android system, and finally, the adjusted audio data is output by adopting the corresponding AudioTrack, so that the independent control of the output volume of the android application is realized, and the user experience is improved.
Drawings
Fig. 1 is a flowchart of an independent control method for an output volume of an android application provided in the present invention.
Detailed Description
The invention is described in detail below by way of example with reference to the accompanying drawings.
The invention provides an independent control method for output volume of an android application, which has the core idea that: the volume value of the output audio of the android application is obtained, each byte of the output audio is processed by adopting the volume value, the processed audio is output, and the independent volume control of the android application is realized.
The invention provides an independent control method for output volume of an android application, the flow of which is shown in figure 1, and the method comprises the following steps:
step 1, when a user opens an android application in a desktop system, the android application display unit sends a taskID of the android application to an android compatible environment.
Step 2, when a user outputs audio by using an android application, the android compatible environment determines the type of an instance Track of the AudioTrack required to be adopted by the android application, if the type of the Track is STREAM _ MUSIC, the received taskId is bound with the Track, and meanwhile, after a volume array of each channel volume value is added and stored for the Track, the creation of the Track is completed; if the type of Track is non-STREAM _ MUSIC, the creation of Track is completed.
And 3, when the android application display unit monitors the operation of controlling the output volume of the android application by the user, judging whether the current operation object is the android application positioned on the uppermost layer of the desktop, if so, executing the step 4, otherwise, executing the step 3, and continuing monitoring.
Specifically, the method for detecting and outputting the volume control operation at the desktop system end by using the android application display unit comprises the following steps: detecting input of a multimedia keyboard volume key, detecting volume control through a system task bar, detecting a self-defined volume control shortcut key of an android application display unit, or detecting volume control through a right-click menu of an application window of the android application display unit.
Step 4, intercepting and controlling the operation of outputting volume by the android application display unit, and limiting the current operation to be sent to the android application compatible service; the android application display unit acquires a volume value after current operation execution, and the volume value is recorded as appVolume which is a floating point value with a value between 0 and 1; and the android application display unit sends the volume value and the taskId of the android application to the android application compatible service.
Step 5, the android application compatible service sends the volume value and the taskId of the android application to the AudioFlinger, the AudioFlinger traverses all the current tracks to find the Track bound with the same taskId as a target Track, and assigns a value to each element in the volume array of the target Track by adopting the volume value; after a re-sampler built in the android system is started to re-sample the audio data, new audio data is obtained after each byte of the audio data is adjusted by adopting a volume value, and the new audio data is output by adopting a target Track.
Example (b):
in this embodiment, a system-level modification is performed on the android system, so as to implement the independent control method for the output volume of the android application provided by the present invention, and the specific process is as follows:
and S1, modifying the AudioTrack class in the android system to realize the binding of the AudioTrack and the android application.
Adding a member variable mTaskId with type of long into the AudioTrack class, wherein the initial value of the mTaskId is-1, wherein, -1' indicates that no android application corresponding to the AudioTrack exists or the AudioTrack belongs to a system process of an android system.
Meanwhile, a floating-point group member variable mVolumes [ MAX _ CHANNEL _ COUNT ] is added in the AudioTrack class to store the volume value of each CHANNEL, the default value of mVolumes is that each element is 1, and MAX _ CHANNEL _ COUNT is the maximum number of CHANNELs. In the existing system, MAX _ CHANNEL _ COUNT is generally 2, that is, the existing system usually has only two CHANNELs, i.e. the android application outputs music and uses two CHANNELs. In the invention, the volume value of each sound channel in the mVolumes array is set by adopting the volume value sent by the android application display unit, and the purpose of expressing the volume by adopting the array is convenient for expansion.
The createTrack method for modifying AudioTrack class in the android system belongs to the libaudacryient module, runs in the audio playing application, and is modified as follows:
when the type of the Track to be created is STREAM _ MUSIC, acquiring the process ID of the current process, further acquiring the task ID, namely taskId, and setting mTaskId of the AudioTrack as taskId; when the type of the Track is non-STREAM _ MUSIC, the mTaskId of the AudioTrack is set to be-1; and finally, executing an android standard implementation step of createTrack.
S2, modifying the built-in audio Resampler (sampler) of the android system, wherein the modification is only effective for the audio output application using the built-in sampler of the android system, and the modification modifies the resampling function of the built-in audio Resampler (sampler), such as, for example, resampleMono16, resampleStereo16, etc., and comprises the following steps:
after performing the standard resampling process to complete resampling of the audio data, adjusting each byte of the audio data by using the volume value to obtain new audio data, for example, changing output buffer [ index ] = xxxx into output buffer [ index ] = volume xxxx by using the volume xxx method, thereby completing the operation of outputting the buffer output buffer.
S3, when the Linux/Windows end detects the volume control operation aiming at the android application, the xDreidUI detects the activity change of a plurality of android application Windows, responds to the Activate event of the Windows, when a certain android application window receives the event and is positioned at the uppermost layer of the desktop, the volume adjusting event is not transmitted to the xDreidServer in the android compatible environment, otherwise, the audio output volume of the whole android environment is influenced.
S4, transmitting the taskId and the changed volume value appVolume of the android application on the uppermost layer to the Audio Flanger of the android compatible environment through RPC, wherein the floating point value of appVolume of 0-1.0 corresponds to 0% -100%.
S5, the AudioFlinger traverses all the AudioTrack, and the values of all the elements of mVolumes of the AudioTrack with the same taskId as that of the current android application are set as appVolume.
S6, transferring the appVolume to the modified Resampler, the Resampler completes resampling on the audio data, adjusts the audio data by using the appVolume, and outputs the processed audio data by adopting the AudioTrack.
In addition, because the resampler adopted by the android system comprises the resampler built in the system and the resampler provided by the audio equipment, in order to further improve the applicability, the invention also provides an implementation mode which can be suitable for the two types of resamplers and adopts each byte of the volume value adjusting audio data.
In the existing android system, getNextBuffer of an AudioBufferProvider interface is called to acquire audio frame data during operation of a resompler, and the resompler provided by an audio device and the resompler built in the system can be both effective by modifying subclasses of the AudioBufferProvider responsible for audio output in the android system.
Specifically, by modifying the getNextBuffer function of the audiobuffervrovider sub-class in the android framework, such as resomplerbufferprovider, passthrusbuffervrovider, extensededaudiobuffervrovider, etc., the modified steps are as follows:
firstly, executing the standard step of getNextBuffer to obtain audio frame data inputBuffer;
then, acquiring an example Track of an AudioTrack class corresponding to the current AudioBufferProvider, and if the Track is of the STREAM _ MUSIC type, acquiring the value volume of mVolumes [0] of the Track;
and finally, performing the simplest operation on each byte in the audio frame data inputBuffer in the following way: inputBuffer [ i ] = volume × inputBuffer [ i ], and thus audio data adjusted with the volume value is obtained.
In summary, the above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (7)

1. An independent control method for output volume of an android application is characterized by comprising the following steps:
step 1, when a user opens an android application in a desktop system, sending a taskID of the android application to an android compatible environment; when a user outputs audio by using an android application, the android compatible environment determines the type of an example Track of an AudioTrack required to be adopted by the android application, if the type of the Track is STREAM _ MUSIC, the received taskId is bound with the Track, and meanwhile, after a volume array of each channel volume value is added and stored for the Track, the creation of the Track is completed; if the type of the Track is non-STREAM _ MUSIC, the creation of the Track is completed;
step 2, when the user adjusts the output volume of the android application, judging whether the current operation object is the android application positioned on the uppermost layer of the desktop, if so, executing the step 3, otherwise, executing the step 2;
step 3, pausing sending the event for adjusting the output volume of the android application to an android application compatible service, and obtaining the volume value of the adjusted output volume of the android application, wherein the volume value is a floating point value with a value between 0 and 1; sending the volume value and taskId of the android application to an AudioFlinger in the android compatible environment;
step 4, the AudioFlinger finds the Track bound with the same taskId as a target Track, and assigns a value to each element in a volume array of the target Track by adopting a volume value; and adjusting the audio data based on the volume value and resampling the audio data to obtain new audio data, and outputting the new audio data by adopting the target Track.
2. The independent control method according to claim 1, wherein the step 4 of adjusting the audio data based on the volume value and resampling the audio data to obtain new audio data comprises: and after a re-sampler built in the android system is started to re-sample the audio data, adjusting each byte of the audio data by adopting the volume value to obtain new audio data.
3. The independent control method according to claim 2, wherein the new audio data is obtained by adjusting each byte of the audio data by the volume value by: and multiplying the volume value by each byte of the audio data to obtain new audio data.
4. The independent control method according to claim 1, wherein the step 4 of adjusting the audio data based on the volume value and resampling the audio data to obtain new audio data comprises: and adjusting each byte of the audio data by adopting the volume value to obtain intermediate audio data, and starting the resampler to complete the processing of the intermediate audio data to obtain new audio data.
5. The independent control method according to claim 4, wherein the adjusting each byte of the audio data by the volume value to obtain the intermediate audio data comprises: and multiplying the volume value and each byte of the audio data to obtain intermediate audio data.
6. The independent control method according to claim 1, wherein when the user opens the android application in the desktop system in step 1, the android application display unit sends the taskID of the android application to the android compatible environment.
7. The independent control method according to claim 6, wherein the android application display unit is an xdroid ui and the android application compatible service is an xdroid server.
CN202210919261.8A 2022-08-02 2022-08-02 Independent control method for output volume of android application Active CN114968168B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210919261.8A CN114968168B (en) 2022-08-02 2022-08-02 Independent control method for output volume of android application

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210919261.8A CN114968168B (en) 2022-08-02 2022-08-02 Independent control method for output volume of android application

Publications (2)

Publication Number Publication Date
CN114968168A CN114968168A (en) 2022-08-30
CN114968168B true CN114968168B (en) 2022-09-27

Family

ID=82969381

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210919261.8A Active CN114968168B (en) 2022-08-02 2022-08-02 Independent control method for output volume of android application

Country Status (1)

Country Link
CN (1) CN114968168B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116860201B (en) * 2023-09-05 2023-11-28 麒麟软件有限公司 Independent volume adjustment control method and device for android application in Linux system

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104484152A (en) * 2014-12-31 2015-04-01 珠海全志科技股份有限公司 High sampling rate direct-connection audio output method and device based on Android
CN107566595A (en) * 2017-08-18 2018-01-09 广东欧珀移动通信有限公司 Method for controlling volume, device and the storage medium and mobile terminal of mobile terminal
CN114333933A (en) * 2022-03-11 2022-04-12 北京麟卓信息科技有限公司 Android application low-delay audio output method on Linux platform

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170171281A1 (en) * 2015-12-14 2017-06-15 Le Holdings (Beijing) Co., Ltd. Play method and apparatus and mobile terminal device for android platform
CN108052312B (en) * 2017-12-06 2021-04-27 晶晨半导体(上海)股份有限公司 Method for realizing multi-channel recording based on android system and audio system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104484152A (en) * 2014-12-31 2015-04-01 珠海全志科技股份有限公司 High sampling rate direct-connection audio output method and device based on Android
CN107566595A (en) * 2017-08-18 2018-01-09 广东欧珀移动通信有限公司 Method for controlling volume, device and the storage medium and mobile terminal of mobile terminal
CN114333933A (en) * 2022-03-11 2022-04-12 北京麟卓信息科技有限公司 Android application low-delay audio output method on Linux platform

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
基于Android系统的音频架构;王峻;《电声技术》;20121117(第11期);第1-4页 *
移动操作系统音频单元设计;王佩光等;《计算机时代》;20170215(第02期);第1-5页 *

Also Published As

Publication number Publication date
CN114968168A (en) 2022-08-30

Similar Documents

Publication Publication Date Title
US10558422B2 (en) Using a plurality of buffers to provide audio for synchronized playback to multiple audio devices having separate device clocks
US6405254B1 (en) System and method for protocol conversion using facilities and utilities
US20070050479A1 (en) Content receiving apparatus and content receiving method
EP1434127A2 (en) Template-based customization of a user interface for a messaging application program
CN102158553A (en) Method and device for playing multi-media files for remote desktop
CN102468989B (en) The method and system of network data
CN1525375A (en) Method to initiate server based collaboration on e-mail attachments
JP6582100B2 (en) Method and apparatus for providing voice service
KR101528367B1 (en) Sound control system and method as the same
CN114968168B (en) Independent control method for output volume of android application
US8639370B2 (en) Audio source system and method
US20080033978A1 (en) Program, data processing method, and system of same
CN101388846B (en) Method and apparatus for transferring data
US20120166585A1 (en) Apparatus and method for accelerating virtual desktop
CN1823355A (en) Flexible interface for controlling a motion platform
US8346218B2 (en) Avoiding redundant transmissions of data during multimedia mobile phone communications
CN111182334B (en) Data processing method, server, terminal, and storage medium
EP1401206A2 (en) Stream Data Processing Apparatus
WO2009016474A2 (en) System and method for efficiently providing content over a thin client network
JP2013084116A (en) Communication device, method of controlling communication device, and information processing system
KR100659460B1 (en) Background music service method and system
CN113035246A (en) Audio data synchronous processing method and device, computer equipment and storage medium
CN113873253B (en) Cloud application opening optimization method and device based on RDP
US20080126752A1 (en) Dual-processor communication
KR101520414B1 (en) Application remote control system, application remote control apparatus and method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant