📜 ⬆️ ⬇️

Improving sound quality on Android tablets with Intel Atom processors using the Dolby Digital API

Developers do not often think about high-quality sound on tablets, but in vain! Tablets are full-featured mobile entertainment systems, and when users understand this, sound is crucial for delivering entertainment content.
Android * devices account for more than half of the tablet market, so Google’s operating system is becoming the preferred platform not only for portable mobile entertainment devices, but also for entertainment in general. The Android platform produces a huge variety of devices, and not all of them are able to provide good entertainment features.
Let's see how you can improve the sound quality in Android-applications on tablets with built-in Dolby Digital Plus equipment.

With regard to high-quality sound, there are three main factors to consider.

We chose a Samsung Galaxy Tab * 3 10.1 tablet with an Intel Atom processor. In terms of speed, it is not inferior or exceeds all other devices, so performance is definitely not a problem. The high clock frequency and the use of a dual-core processor ensure flawless sound reproduction even when multitasking.
In addition, the Intel Atom SoCs used in Android devices are optimized for power consumption, so they run on battery power for a very long time, which is especially true for the Galaxy Tab 3.

The final factor is sound quality; Dolby Digital Plus * embedded audio equipment is responsible for this. Dolby hardware resources provide several important components, among which we note the following: Volume Maximizer - increase the volume of the sound without distortion; Audio Optimizer - a significant improvement in sound clarity using proprietary Dolby sound processing algorithms.
Also note that since the Dolby solution is hardware, it does not cause additional load on the CPU. When used, it practically does not consume the computing resources of the system.
The concept of “sound quality” as such is largely subjective, especially with regard to already recorded content, but the Dolby Digital Plus codec used here contains a whole set of technologies that are worth considering in more detail.

Dolby Digital Plus Audio Codec Technology


The Dolby Digital Plus sound codec includes a number of sound processing technologies that affect the audio content that is played on a mobile device. The ultimate goal of the codec is to improve the subjective sound quality. It should be noted several technologies related to music playback.
')
Volume leveler

Volume Leveler continuously tracks the reproduced sound with the help of a “psychoacoustic model of loudness perception” (in Dolby terminology), which determines how loud the sound will seem to a person. This value is used to dynamically adjust the volume to ensure that the subjective volume is the same from the point of view of the listener. At the same time, another technology is used, the Auditory Scene Analysis; her goal is to avoid incorrect adjustment of the sound, as a result of which the sounds and melody moments intentionally made silent can be amplified.
Dolby experts say that Volume Leveler can independently adjust both audio channels and even individual frequency ranges to avoid the “pumping” and “vibration” effects when processing sound.

Volume maximizer

One of the important advantages of the Dolby Digital Plus codec is the Volume Maximizing module, which provides quite a loud sound from the small speakers that mobile devices are usually equipped with. After processing the sound in Volume Leveler, the Maximizer module increases the amplitude of the sound by a sufficiently significant amount, up to 12 dB.
To avoid over-amplifying the signal, which can cut off the frequency range, Volume Maximizer uses a “pre-emptive limiter”. The limiter combines signal amplification with multi-band compression to increase the volume of the sound without distortion.

Audio optimizer

The frequency range of the speakers, which are equipped with mobile devices, is often far from ideal. In other words, for different frequencies, the sound level can be quite different. Because of this, listening to music can sound unnatural or muffled. Audio Optimizer technology applies a set of filters to bypass the possible imperfections of the speakers. These filters are individually selected for each device model. The ultimate goal is to produce a natural, balanced sound with the same level of reproduction of all frequencies, which for most devices in practice means an increase in the level of low and high frequencies.

Audio regulator

The final stage of processing music that interests us as listeners is the Audio Regulator. If you increase the volume of the output sound on mobile devices, distortion may occur. This effect can be caused by the amplifiers themselves, speaker overloading, resonance, or a “banging” on smartphones and tablets. This behavior is individual for each device, it may vary for different frequencies.
Regulator applies multi-band compression taking into account the individual characteristics of each specific device. Both Audio Regulator and Audio Optimizer are calibrated according to the unique features of each type of device.
In addition, restrictions are applied to preserve the timbre of the sound during compression.
Finally, the Regulator is volume dependent. You can use distortion control to a lesser extent or turn it off at low volume.

Why is sound important on mobile devices?


Tablets and smartphones are increasingly becoming the preferred devices for viewing and consuming entertainment content. Good sound quality influences the overall perception of entertainment materials quite strongly. Recently, Parks Associates conducted a study (commissioned by Dolby) to assess the importance of high-quality sound. This study showed that in most cases, smartphone owners attach some importance to sound quality when choosing a smartphone or tablet.

However, after listening to an audio demonstration from a device with improved playback, many users recognized that sound quality is important for their mobile devices.
After a simple demonstration of Dolby Digital sound processing technology, you will most likely agree with this.

Using the Dolby Audio API in Android Applications

Dolby technology makes it very easy to improve sound quality on Android devices equipped with a Dolby Digital Plus hardware module. The Dolby Developer portal contains a free API to support Dolby sound processing in traditional Java * applications, as well as on some third-party platforms, including Xamarin, Unity 3D *, and Cordova *.
Dolby Digital solution works at the hardware level, so it improves the sound quality regardless of how the sound is loaded and reproduced in the source code.
To enable Dolby Digital audio processing, follow these steps.
  1. Download and install the Dolby Digital API in a mobile application at developer.dolby.com .
  2. Get an instance of the DolbyAudioProcessing object. It's very simple: just call GetDolbyAudioProcessing () from the Dolby API.
  3. Create a Dolby Listener Object. Usually the object of the Dolby listener is the current Activity to simplify the implementation, but it can be a separate class.

The Java snippet is shown below.
import com.dolby.dap.DolbyAudioProcessing; import com.dolby.dap.OnDolbyAudioProcessingEventListener; import com.dolby.dap.DolbyAudioProcessing.PROFILE; public <strong>class</strong> MainActivity extends Activity implements OnDolbyAudioProcessingEventListener { DolbyAudioProcessing mDolbyAudioProcessing; ... @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... mDolbyAudioProcessing = DolbyAudioProcessing.getDolbyAudioProcessing(this, DolbyAudioProcessing.PROFILE.GAME, this); if (mDolbyAudioProcessing == null){ Toast.makeText(this, "Dolby isn't available on this device", Toast.LENGTH_SHORT).show(); finish(); return; } } ... } 

Example Description


I had the opportunity to create an application for streaming audio to help independent musicians attract attention and showcase their music. It was important to have a device suitable for the demonstration of both music and applications. Therefore, for reasons of performance, battery life and sound quality, a Galaxy Tab 3 10.1 tablet (86-bit) was chosen for this project.
The music content is streamed from SoundCloud and is played using the MediaPlayer object, which is part of the Android API.

To use the code on other platforms (WPF, Windows * Store, etc.), I used a third-party development tool, Xamarin Android, which allows you to write your own Android applications on .NET C #. However, since Xamarin uses Android’s own Java APIs, the development steps are generally the same as when writing Java applications.

Dolby API example

As for the Android Activity, which is responsible for playing melodies, I decided to make it a Dolby Digital API listener. This means that it is responsible for listening and responding to the Dolby Digital API using the methods defined in IOnDolbyAudioProcessingEventListener . I also implemented the IOnCompletionListener interface of the MediaPlayer object in the Activity, making it a single playback point. This approach works well, but you can separate these interfaces into separate classes, if required by your application architecture.

My class signature looks like this:
 public class Activity1 : Activity, MediaPlayer.IOnCompletionListener, IOnDolbyAudioProcessingEventListener. 

I keep instances of both MediaPlayer objects available as class-level variables. Note that the DoblyAudioProcessing object should be made static and you should not keep more than one instance of this object in the application. If you need access to the DolbyAudioProcessing object from an Activity, you must provide access to it using a singleton class or some type of global link.

To initialize Dolby sound processing, I created the helper InitAudio () method to safely get a reference to the DolbyAudioProcessing object. Since compatibility with other devices is still necessary, this method is unsuitable for devices that are not equipped with the Dolby codec.
When requesting a processing object, I also set the Dolby Digital processing mode. In this case, I chose the music mode, designed to improve the clarity of sound, balance and perceived volume. Sound enhancements are noticeable when using the device’s built-in speakers, headphones, or line-out to external audio equipment.
 void InitAudio() { if (mDolbyAudioProcessing != null) return; mDolbyAudioProcessing = DolbyAudioProcessing.GetDolbyAudioProcessing(this, DolbyAudioProcessing.PROFILE.Music, this); if (mDolbyAudioProcessing == null) { Toast.MakeText(this, "Dolby Audio Processing load failed", ToastLength.Short).Show(); return; } } } 

Finally, I check and save the Dolby processing state when the action starts, and restore the state when our application is running in the background or closing. Dolby Digital equipment affects all the sound that plays on a device, so this is a very important step, and it is easily done using onResume () and onPause () lifecycle management methods.

SoundCloud API

The SoundCloud API allows you to create applications that use all the functionality of the SoundCloud website. HTTP requests are sent to a set of endpoint URLs to request information and perform actions.
Working with the SoundCloud API is well documented, but since this API itself is quite complex, it may be difficult at first to figure it out. You should first read the REST documentation .
The easiest way to get started is to use the Java API shell available on the GitHub portal ; nonetheless, I will describe the SoundCloud deployment process manually.
You need to create a SoundCloud client ID that is a unique identifier for your application. This should be done when interacting with other REST APIs to access publicly available content.

Playing SoundCloud content

Consider the process of accessing a particular artist in SoundCloud, downloading album information, reading individual tunes and playing. To do this, we will interact with the RESTful SoundCloud service and decode the returned JSON data.

Step 1. Create Customer ID
As mentioned above, this identifier is free, you can create it here .
It will look something like this: 7de8bc189e5ba2ab12fa4223951fabb8 .

Step 2. Find the artist ID
You need to find the user ID of the artist whose music you want to play. You can do this directly on the SoundCloud website or using the SoundCloud API. Since we are only learning the API, I’ll show you a quick way to find the ID manually. Open any artist page directly on the SoundCloud website, click Share, and then Embed. In the Code & Preview window, you will see an iFrame tag. Inside it, you'll see a link that looks something like this: https% 3A // api.soundcloud.com / users / 547647 . The number is the performer id we need.

Step 3. Create a request for uploading albums
Now we will create the first request to the SoundCloud API. We start with the API address, and then we collect the full URL using the artist ID from step 2 and our own customer ID from step 1.
 string request = "http://api.soundcloud.com/" + "users/" + artistID + "/playlists.json?client_id=" + clientID; 


Step 4. Submit a request
Now just send the request. My application is written in C #, so the code looks like this:
 public async Task<string> GetUserPlaylists () { HttpClient client = new HttpClient (); var request = "http://api.soundcloud.com/" + "users/" + artistID + "/playlists.json?client_id=" + clientID; HttpResponseMessage response = await client.GetAsync (request); return await response.Content.ReadAsStringAsync (); } 

A brief note. This code can work on any modern .NET platform that includes Microsoft HttpClient, including WPF, Windows Store, or Silverlight *.

Step 5. Deserialize the object.
Here you can use your favorite JSON library. When I write .NET code, I use the Newtonsoft Json library.
 _setLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AlbumData>>(response); 

The response variable is the result of using the GetUserPlaylists () method in the previous step. We will get a list of AlbumData objects (defined below).

Step 6: Create a Ringtone URL
Most likely, you would prefer to present a set of albums to users so that they select the desired one in the ListView; I will not describe in detail the creation of the user interface.
Below is the code of the AlbumData data transfer object. Note that below it contains a list of TrackData objects representing individual melodies.
Fortunately, the data used to populate the TrackData object contains the URL to play.

Step 7. Play the melody
Finally, playing audio from a remote URL using HTTP streaming on the Android platform looks like this:
 String url = myTrack.StreamURL; MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.SetAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.SetDataSource(url); mediaPlayer.Prepare(); mediaPlayer.Start(); 

Where myTrack is a specific instance of TrackData tunes that I need to play.

SoundCloud data transfer objects

At this point, I want to show the AlbumData and TrackData objects. The SoundCloud API is very easy to use if you do not want to write a significant amount of code for JSON analysis, but we will use data transfer objects (DTO) to store the analyzed JSON data.
To view the albums and play melodies, we need two DTO objects: one will represent the album data, and the second - separate melodies. I have included two of my DTO objects below in C # code. They are given completely, you can use them in your projects.
If you need to work with the SoundCloud API at a deeper level, you may need to create additional DTO objects.
Code
 AlbumData.cs using Newtonsoft.Json; using System.Collections.Generic; namespace SoundCloud.Json { public class AlbumData { [JsonProperty("id")] public string Id { get; internal set; } [JsonProperty("created_at")] public string CreatedAt { get; internal set; } [JsonProperty("user_id")] public string UserId { get; internal set; } [JsonProperty("user")] public UserData User { get; internal set; } [JsonProperty("title")] public string Title { get; internal set; } [JsonProperty("permalink")] public string Permalink { get; internal set; } [JsonProperty("permalink_url")] public string PermalinkUrl { get; internal set; } [JsonProperty("uri")] public string Uri { get; internal set; } [JsonProperty("sharing")] public string Sharing { get; internal set; } [JsonProperty("embeddable_by")] public string EmbeddableBy { get; internal set; } [JsonProperty("purchase_url")] public string PurchaseUrl { get; internal set; } [JsonProperty("artwork_url")] public string ArtworkUrl { get; internal set; } [JsonProperty("description")] public string Description { get; internal set; } [JsonProperty("label")] public UserData Label { get; internal set; } [JsonProperty("duration")] public int Duration { get; internal set; } [JsonProperty("genre")] public string Genre { get; internal set; } [JsonProperty("tag_list")] public string TagList { get; internal set; } [JsonProperty("label_id")] public string LabelId { get; internal set; } [JsonProperty("label_name")] public string LabelName { get; internal set; } [JsonProperty("streamable")] public bool Streamable { get; internal set; } [JsonProperty("downloadable")] public bool Downloadable { get; internal set; } [JsonProperty("tracks")] public List<TrackData> Tracks { get; internal set; } } } TrackData.cs using System; using Newtonsoft.Json; namespace SoundCloud.Json { [JsonObject] public class TrackData { [JsonProperty("id")] public long Id { get; internal set; } [JsonProperty("created_at")] public DateTime CreatedAt { get; internal set; } [JsonProperty("user_id")] public long UserId { get; internal set; } [JsonProperty("duration")] public long Duration { get; internal set; } [JsonProperty("commentable")] public bool Commentable { get; internal set; } [JsonProperty("state")] public string State { get; internal set; } [JsonProperty("sharing")] public string Sharing { get; internal set; } [JsonProperty("tag_list")] public string TagList { get; internal set; } [JsonProperty("permalink")] public string Permalink { get; internal set; } [JsonProperty("description")] public string Description { get; internal set; } [JsonProperty("streamable")] public bool Streamable { get; internal set; } [JsonProperty("downloadable")] public bool Downloadable { get; internal set; } [JsonProperty("genre")] public string Genre { get; internal set; } [JsonProperty("release")] public string Release { get; internal set; } [JsonProperty("purchase_url")] public string PurchaseUrl { get; internal set; } [JsonProperty("label_id")] public string LabelId { get; internal set; } [JsonProperty("label_name")] public string LabelName { get; internal set; } [JsonProperty("isrc")] public string ISRC { get; internal set; } [JsonProperty("video_url")] public string VideoUrl { get; internal set; } [JsonProperty("track_type")] public string TrackType { get; internal set; } [JsonProperty("key_signature")] public string KeySignature { get; internal set; } [JsonProperty("bpm")] public long? BPM { get; internal set; } [JsonProperty("title")] public string Title { get; internal set; } [JsonProperty("release_year")] public string ReleaseYear { get; internal set; } [JsonProperty("release_month")] public string ReleaseMonth { get; internal set; } [JsonProperty("Release_day")] public string ReleaseDay { get; internal set; } [JsonProperty("original_format")] public string OriginalFormat { get; internal set; } [JsonProperty("license")] public string License { get; internal set; } [JsonProperty("uri")] public string Uri { get; internal set; } [JsonProperty("permalink_url")] public string PermalinkUrl { get; internal set; } [JsonProperty("artwork_url")] public string ArtworkUrl { get; internal set; } [JsonProperty("waveform_url")] public string WaveformUrl { get; internal set; } [JsonProperty("user")] public UserItemData User { get; internal set; } [JsonProperty("stream_url")] public string StreamUrl { get; internal set; } [JsonProperty("download_url")] public string DownloadUrl { get; internal set; } [JsonProperty("playback_count")] public long PlaybackCount { get; internal set; } [JsonProperty("download_count")] public long DownloadCount { get; internal set; } [JsonProperty("favoritings_count")] public long FavoritingsCount { get; internal set; } [JsonProperty("comment_count")] public long CommentCount { get; internal set; } [JsonProperty("attachments_uri")] public string AttachmentsUri { get; internal set; } } } 


Conclusion and conclusions


Soundcloud

The information above provides a good foundation for getting started with SoundCloud. If you require a deeper implementation, such as sending or managing content, you will need to create additional data transfer objects and ensure that the data in your application is synchronous with SoundCloud. If you are developing a program in Java, it makes sense to look into the Android Sharing Kit .

Dolby Digital and SoundCloud

In audio streaming services, there is a common problem with the uneven sound level of different files. This will not affect the provision of content by the service, but it’s very good if the Dolby Digital API normalizes the volume. The difference in levels becomes especially noticeable when switching between tunes of different artists.

Android MediaPlayer

The MediaPlayer object in the Android API is convenient for playing local or streaming audio content, but it cannot be considered a universal solution: it does not always work. When creating applications for Android, you should always test on as many devices as possible, and this is especially important when it comes to the MediaPlayer object. You should not hope that it will “just work” on all devices, even if everything was perfect during testing. This is especially true for less powerful devices. Try using the alpha and beta functions of the Google Play store, or use a testing service that allows you to run your application on a wide variety of phones and tablets.

Performance

As mentioned above, be careful with the MediaPlayer, as it may not work properly on low-powered devices. In addition, be sure to optimize other parts of your application so that the sound is played without interruptions. Always run the code waiting for the web service, separate from the user interface, and use techniques such as cell reuse and View Holder in list controls to reduce memory usage and improve performance. Useful tips on optimization, see the documentation Smooth scrolling ListView .

Devices

The Samsung Galaxy Tab 3 10.1 tablet turned out to be an excellent demonstration device, and I really liked the audio enhancement achieved by hardware processing the streaming content with the Dolby Digital codec. This codec is not available on all devices, but it still makes sense to integrate the Dolby Digital API into your Android applications. This solution can be implemented very quickly, while it significantly improves the clarity of the output sound.

Next steps

The Samsung Galaxy Tab 3 10.1 tablet is still very competitive, but the mobile device market is growing rapidly. Soon tablets with new quad-core Intel Atom processors will appear on the market. Dell Venue * 8 7000 will become a class-leading device after its release in Q4 2014. In addition, Dolby Digital Plus equipment is fairly widespread. Lenovo, a major manufacturer of mobile devices, produces several tablets equipped with the Dolby codec. I recently switched to the Lenovo S8-50f as the main device for development on the Android platform. This device is equipped with a quad SoC Intel Atom Z3745 x86 architecture, 2 GB of RAM and, of course, the Dolby Digital Plus codec.

Related Links


Source: https://habr.com/ru/post/255011/


All Articles