Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How to get max performance on iOS devices (Read 4392 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to get max performance on iOS devices

Hi, I am implementing the libopusenc on my iOS project. The script is working fine and the audio created is very good. The implementation was easy and done in objc with a front end in Swift.

I was able to reduce a 137mb file to  2.4mb which is great. But I am having serious problems with the time needed to process it. It needed 48 seconds which is a lot. I would rather get a bigger files with less compression over a super compressed one and max CPU usage for a short time.

 My default settings are:

Sample rate: 48000hz (cannot change it, required by another part of the project).
Bitrate: 16kb/s (probably the lowest possible to have something with quality).
complexity varies based on the device, on this device (iPhone 6) I ran the script the value is 2.
Signal: OPUS_SIGNAL_VOICE
Application: OPUS_APPLICATION_VOIP
Channels: 1

If you know what I can do to speed up the compression, I will be glad to hear you guys.
Thanks.

Re: How to get max performance on iOS devices

Reply #1
How many times real-time is that? 

In any case, make sure all ARM optimizations are enabled, as those will have a large impact.

Re: How to get max performance on iOS devices

Reply #2
I don't think it sounds too slow, but I don't know exactly how powerful your device is.  Despite what you might read, Opus is one of the more complex codecs around and it isn't one of the fastest either to encode or decode.  FPU speed and optimisation is probably the critical thing to look at.  You might not be able to do much though, ARM builds of libopus include specific optimisations already, so unless they weren't enabled in your build you might already be as fast as you can easily go.

Re: How to get max performance on iOS devices

Reply #3
Hi, @saratoga and @lithopsian thank you for the answer.

@saratoga I have no idea, how I can check this?
@lithopsian I get it, I think opus is compressing the audio too much and using a lot of CPU time for this, I understand that using a higher complexity will result into a higher quality, but it doesn't change the final audio size. The file is 57 times smaller, something around 15-20 times could be very good. The IO write speed are high, the problem is to process the audio.

I am compiling libopus from the source code, I am using the build 1.3. Do you know what I can do to enable the ARM optimizations?

I am using the script provided by this project to build the static library (.a):

Project: https://github.com/chrisballinger/Opus-iOS
Build script: https://github.com/chrisballinger/Opus-iOS/blob/master/build-libopus.sh

This script also creates the .framework which I don't use in my project.

Thank you.

Re: How to get max performance on iOS devices

Reply #4
I think when you run that script it should hopefully print what optimizations it is using.  You want all of the ARM ones.

Re: How to get max performance on iOS devices

Reply #5
I think when you run that script it should hopefully print what optimizations it is using.  You want all of the ARM ones.
They should all be on by default, but worth checking.  There should also be some assembler in there to help do things that ARMs aren't good at.  I suspect it would be really slow without that.

Re: How to get max performance on iOS devices

Reply #6
I don't think there is a big difference in speed between creating a high-bitrate file and a low-bitrate version.  The audio is the same, the analysis is largely the same.  This is not compression and it is no harder to create a smaller audio track than a large one, easier in many ways.  You could certainly try a higher bitrate and see if it is any faster - the file will be bigger of course.  I suspect it will actually be slower.

The complexity is a separate setting unrelated to the bitrate or file size.  It is a measure of how much computation the library is prepared to do to find the most efficient encoding.  By default, it is set to 10 which is the most complex, and obviously takes the most CPU.  Setting this to a lower number should result in faster encoding, but the resulting audio file may be of lower quality.  If you're prepared to trade off file size, you can always increase the bitrate to compensate for any loss of quality caused by running the encode at low complexity.  Most people are aiming for the highest quality at a given file size and are prepared to wait for the encoder, hence it runs as slowly as possible by default.

 

Re: How to get max performance on iOS devices

Reply #7
Ok.. The math gives me that the file is 21 minutes long, and you say it takes 48 seconds to do so. That's something around 26 times realtime.

( 2.4MiB / 16kbits/s = 1258 seconds = 20.9 minutes)
(  Another way to calculate it would be that a 128kbps mp3 was roughly 1 minute per megabyte, and 16kbps is 8 times smaller. 2.4*8 = 19 minutes)

I don't consider that slow for an ARM and Opus.

And knowing the length, we can say something also about the original file, it is around 900kbps (too many roundings to be correct)