Wednesday, May 31, 2017

How does AMR Bandwidth efficient mode looks like?

 In the payload, no specific mode is requested (CMR=15), the speech frame is not damaged at the IP origin (Q=1), and the coding mode is AMR 7.4 kbps (FT=4).  The encoded speech bits, d(0) to d(147), are arranged in descending sensitivity order according to [2].  Finally, two padding bits (P) are added to the end as padding to make the payload octet aligned.




references:
https://tools.ietf.org/html/rfc4867

Friday, May 26, 2017

How to install tomcat on Mac ?

This can be installed easily through the home-brew. 

$brew install tomcat 

this will take care of the downloading, installation and configuration of Tomcat and manage its dependancies as well. 

Brew keeps packages (known as kegs) in the Cellar, where one can check the config and data files. it is located at 

$ls /usr/local/cellar 

The tomcat installation can be verified using the home-brew’s service utility 

$brew services list 

To run the tomcat server, just execute the catalina command 

$ls /usr/local/Cellar/tomcat 
$ /usr/local/Cellar/tomcat /8.5.3/bin/catalina run 

after running the page can be visited at http://localhost:8080

references

Calling a method on constant C++

Why does the error below happen? 

member function 'SetMethodX’ not viable: 'this' argument has type 'const webrtc::ClassY’, but function is not marked const
In my case, the ClassY was constant and using that it was trying to call SetMethodX which was defined to be not constant.

To be able to call a function on a const object, you need to promise the compiler that the function will not modify the object. To do that, you mark the function with the keyword const after its argument list. For example, to make getDimension a const member function, you would change it to:

const ULL getDimension() const { return dimension; }
(Note that the const in the return type will have absolutely no effect, so you should get rid of it)

references:

C++ what is a non static member function?

it is a function without const or friend specifier and that is declared in a member specification. 
Below gives some good overview of various types of member functions 

class S 
{
int mf1(); //non static member function declaration 
void mf2() volatile, mf3() &&; //can be cv-qualified and reference-qualified
        int mf4() const {return data;} //can be defined inline
virtual void()  mf5() final; //can be virtual can use virtual/final 
        S() : data(12) {} // constructors are member functions as well. 
        int data;
};

int S::mf1() {return 6;} //if not defined inline, it has to be defined at namespace. 

references:

Wednesday, May 24, 2017

How to access Google Team drives from Desktop offline

This can be done basically using the google team drive. the new version has EAP Early access program which will allow one utilise the new features such as Team drive.


references:
https://gsuite.google.com/campaigns/index__drive-fs-eap.html

Differences between VoIP and VoLTE

They both essentially uses the same mechanism. Voice packets are encoded to data and sent as data packets over IP network. However, they both differs in the way that the data is carried and the network infrastructure used for carrying it. 

The differences between two include 

1. Using 3G or 4G network 
2. QoS component 
3. Radio Frequency or SR-VCC (Single Radio Voice Continuity) IMS requirement
4. HD Voice requirements

VoLTE packets have 3 times more voice and data carrying capacity using 4G network. VoLTE also has built in QoS components. 

4G boasts about having 100 megabits per second speed. VoIP can use either 3G or 4G while VoLTE can only use 4G. 

one of the main difference is in the QoS. VoLTE uses IMS network and separate radio frequency to help maintain the quality of the VoLTE transmission. something like an expressway! 

When the user leave an LTE coverage area, SR-VCC functions by connecting to the LTE and legacy network at the same time . The radio frequency uses the IMS framework to make this happen. 

Since VoLTE uses fewer resources and has simpler compacting ability for the data packets, networks and handsets, these items consume use less energy with VoLTE. This provides greater battery life for each. VoLTE calls take less time to connect than a 3G call. 

VoLTE calls take less time to connect than a 3G call.

references:

Monday, May 22, 2017

C++ vTable and vPtr

What is a virtual table?

Virtual Table is a lookup table of function pointers used to dynamically bind the virtual functions to objects at run time. It is not intended to be used directly by the program, and as such there is no standardised way to access it.

Every class that uses virtual functions (or is derived from a class that uses virtual functions) is given it's own virtual table as a secret data member. This table is set up by the compiler at compile time. A virtual table contains one entry as a function pointer for each virtual function that can be called by objects of the class. It stores NULL pointer to pure virtual functions in ABC. Virtual Table is created even for classes that have virtual base classes. In this case, the vTable has pointer to the shared instance of the base class along with the pointers to the class's virtual functions if any.

What is a vptr?

This vtable pointer or _vptr, is a hidden pointer added by the compiler to the base class and this pointer is pointing to the virtual table of that particular class. This _vptr is inherited to all the derived classes. Each object of a class with virtual functions transparently stores this _vptr. Call to a virtual function by an object is resolved by following this hidden _vptr.

references
https://www.quora.com/What-are-vTable-and-VPTR-in-C++

What is vTable and vPtr in C++


Tuesday, May 16, 2017

iOS Swift Make a CustomView using Xib file - Swift learning

These are the steps to making a custom UIView that is designable within Xcode:

1. Create a View .xib file (e.g.: CustomView.xib)
2. Design the user interface in Xcode
3. Set up Auto Layout constraints
4. Create a Swift code file (CustomView.swift)
5. Set .xib file’s “File’s Owner” custom class to CustomView (it must match the class name)
6. Implement both CustomView initializers: init(coder:) and init(frame:)
7. Load the UIView from the .xib file using the NSBundle and UINib classes
8. Add the view as a subview and property for the class (future modifications)
9. Add autoresizing masks for the view to match the size of the CustomView itself
10. Make the view’s frame leverage the design time size of the embedded CustomView’s bounds

The extremely important thing to remember is step 5

5. Set .xib file’s “File’s Owner” custom class to CustomView (it must match the class name)

After clicking on File's owner, before giving the class name as CustomView, do not touch anywhere else than the textfield. If touch anywhere in the View, it is going to set the class name to the UIView that is in the Xib file and the loading of the view will get into recursive loop.

references:


Monday, May 15, 2017

Capture and playback AMR packets - wireshark

This is an extremely useful tool found came in handy while integration AMR codec into a system.
To give a basic usage of this, Application sends the encoded frames to the other end and in the middle, AMR frames can be captured and played back. Below is the basic steps as its s described in the git page.

Filter packets of interest (e.g. by 'rtp')
Telephony -> RTP -> Stream analysis
Save -> Forward/Reverse stream audio, Save as type (*.raw)
Guess information about AMR format: AMR vs AMR-WB, octet-align vs bandwidth efficient, number of channels (e.g. from SIP signalization, RTP layer) and provide them to amr.py.

python amr.py -a -n 1 -v -w wb_amr_3.raw

the above command decodes the stream from the wireshark row file and output as wav file. If the file is playing correctly, then done!

amr.py -a -n 1 -v wb_amr_3.raw

references:
https://github.com/suma12/amr

What is EFR in AMR?

Enhanced Full Rate or EFR or GSM-EFR or GSM 06.60 is a speech coding standard that was developed in order to improve the quite poor quality of GSM-Full Rate (FR) codec. Working at 12.2 kbit/s the EFR provides wirelike quality in any noise free and background noise conditions. The EFR 12.2 kbit/s speech coding standard is compatible with the highest AMR mode (both are ACELP). Although the Enhanced Full Rate helps to improve call quality, this codec has higher computational complexity, which in a mobile device can potentially result in an increase in energy consumption as high as 5%[citation needed] compared to 'old' FR codec.

The sampling rate is 8000 sample/s leading to a bit rate for the encoded bit stream of 12.2 kbit/s. The coding scheme is the so-called Algebraic Code Excited Linear Prediction Coder (ACELP). The encoder is fed with data consisting of samples with a resolution of 13 bits left justified in a 16-bit word. The three least significant bits are set to 0. The decoder outputs data in the same format.[2]

The Enhanced Full Rate (GSM 06.60) technical specification describes the detailed mapping between input blocks of 160 speech samples in 13-bit uniform PCM format to encoded blocks of 244 bits and from encoded blocks of 244 bits to output blocks of 160 reconstructed speech samples. It also specifies the conversion between A-law or μ-law (PCS 1900) 8-bit PCM and 13-bit uniform PCM. This part of specification also describes the codec down to the bit level, thus enabling the verification of compliance to the part to a high degree of confidence by use of a set of digital test sequences. These test sequences are described in GSM 06.54 and are available on disks.

references
https://en.wikipedia.org/wiki/Enhanced_full_rate

Wednesday, May 10, 2017

Git how to commit a file that is added into commit?

If this is your last commit and you want to completely delete the file from your local and the remote repository, you can:
remove the file git rm
commit with amend flag: git commit --amend.


references

Tuesday, May 9, 2017

What is Conda ?

Conda is a package manager application that quickly installs, runs, and updates packages and their dependencies. The conda command is the primary interface for managing installations of various packages. It can query and search the package index and current installation, create new environments, and install and update packages into existing conda environments. See our Using conda section for more information.

Conda is also an environment manager application. A conda environment is a directory that contains a specific collection of conda packages that you have installed. For example, you may have one environment with NumPy 1.7 and its dependencies, and another environment with NumPy 1.6 for legacy testing. If you change one environment, your other environments are not affected. You can easily activate or deactivate (switch between) these environments. You can also share your environment with someone by giving them a copy of your environment.yaml file.

SEE ALSO: Managing environments.

A conda package is a compressed tarball file that contains system-level libraries, Python or other modules, executable programs, or other components. Conda keeps track of the dependencies between packages and platforms.

Conda packages are downloaded from remote channels, which are simply URLs to directories containing conda packages. The conda command searches a default set of channels, and packages are automatically downloaded and updated from http://repo.continuum.io/pkgs/.

SEE ALSO: Managing packages.

Users may modify what remote channels are automatically searched, for example, if they wish to maintain a private or internal channel (see Configuration for details).

The conda build command creates new packages that can be optionally uploaded to a repository such as PyPi, GitHub, or Anaconda.org.



references:
https://conda.io/docs/intro.html

Monday, May 8, 2017

Android how to simulate Service being killed



http://stackoverflow.com/questions/11365301/how-to-simulate-android-killing-my-process

Friday, May 5, 2017

Wireshark - How to decrypt SSL streams

The SSL dissector is fully functional and even supports advanced features such as decryption of SSL if the encryption key can be provided and Wireshark is compiled against GnuTLS (rather than OpenSSL or bsafe). This works for RSA private keys.

If Wireshark is compiled with SSL decryption support there will be a new option in the preferences for SSL. If the key entry option is absent then verify if your Wireshark is linked against the required GnuTLS library. This can be done with  wireshark -v . The output should include GnuTLS and GCrypt. If you see without GnuTLS, without Gcrypt, then you will need reconfigure with --with-gnutls, recompile and reinstall.

To configure a RSA private key, go to the SSL dissector preference in the Protocols tree. Then press the RSA keys list button. A new dialog windows appears showing you the currently configured RSA private keys. Press the New button to configure a new RSA private key. In the new window you have to configure the following fields:

The RSA key file can either be a PEM format private key or a PKCS#12 keystore. If the file is a PKCS#12 keystore (typically a file with a .pfx or .p12 extension), the password for the keystore must be specified in the Password field.

Starting with Wireshark 2.0, the RSA key file is automatically matched against the public key as found in the Certificate handshake message. Before Wireshark 2.0, it relied on the user to enter a valid Address and Port value. Note that only RSA key exchanges can be decrypted using this RSA private key, Diffie-Hellman key exchanges cannot be decrypted using a RSA key file! (See "SSLKEYLOGFILE" if you have such a capture.)

The fileformat needed is 'PEM'. Note that it is common practice on webservers to combine the public key (or certificate) and the private key in a single PEM file.

references:
https://ask.wireshark.org/questions/34393/how-to-decrypt-ssl-traffic-using-wireshark

Wednesday, May 3, 2017

WAV Storage format

The data bits for each sample should be left-justified and padded with 0s. For example, consider the case of a 10-bit sample (as samples must be multiples of 8, we need to represent it as 16 bits). The 10 bits should be left-justified so that they become bits 6 to 15 inclusive, and bits 0 to 5 should be set to zero.



As an example, here is a 10-bit sample with a value of 0100001111 left-justified as a 16-bit word.



Given the fact that the WAVE format uses Intel's little endian byte order, the LSB is stored first, as shown here:

The analogy is for mono audio, meaning that you have just one "channel." When you deal with stereo audio, 3D audio, and so forth, you are in effect dealing with multiple channels, meaning you have multiple samples describing the audio in any given moment in time. For example, for stereo audio, at any given point in time you need to know what the audio signal was for the left channel as well as the right channel. So, you will have to read and write two samples at a time.


Say you sample at 44 KHz for stereo audio; then effectively, you will have 44 K * 2 samples. If you are using 16 bits per sample, then given the duration of audio, you can calculate the total size of the wave file as:

Size in bytes = sampling rate * number of channels * (bits per sample / 8) * duration in seconds

Number of samples per second = sampling rate * number of channels

When you are dealing with such multi-channel sounds, single sample points from each channel are interleaved. Instead of storing all of the sample points for the left channel first, and then storing all of the sample points for the right channel next, you "interleave" the two channels' samples together. You would store the first sample of the left channel. Then, you would store the first sample of the right channel, and so on.

references:
http://www.codeguru.com/cpp/g-m/multimedia/audio/article.php/c8935/PCM-Audio-and-Wave-Files.htm

What is PCM ?


In the digital domain, PCM (Pulse Code Modulation) is the most straightforward mechanism to store audio. The analog audio is sampled in accordance with the Nyquest theorem and the individual samples are stored sequentially in binary format. The wave file is the most common format for storing PCM data.

Interchange Format Files (IFF)
It is a "Meta" file format developed by a company named Electronic Arts. The full name of this format is ElectronicArts Interchange File Format 1985 (EA IFF 85). IFF lays down a top-level protocol on what the structure of IFF compliant files should look like. It targets issues such as versioning, compatibility, portability, and so forth. It helps specify standardized file formats that aren't tied to a particular product. The wave file format is based on the generic IFF format.

The WAVE File Format supports a variety of bit resolutions, sample rates, and channels of audio.

The WAVE file format is based on Microsoft's version of the Electronic Arts Interchange File Format method for storing data. In keeping with the dictums of IFF, data in a Wave file is stored in many different "chunks." So, if a vendor wants to store additional information in a Wave file, he just adds info to new chunks instead of trying to tweak the base file format or come up with his own proprietary file format.


There are three chunks that are required to be present in a valid wave file:

'RIFF', 'WAVE' chunk
"fmt" chunk
'data' chunk

All other chunks are optional. The Riff wave chunk is the identifier chunk that tells us that this is a wave file. The "fmt" chunk contains important parameters describing the waveform, such as its sample rate, bits per sample, and so forth. The Data chunk contains the actual waveform data.

An application that uses a WAVE file must be able to read the three required chunks although it can ignore the optional chunks. But, all applications that perform a copy operation on wave files should copy all of the chunks in the WAVE.

The Riff chunk is always the first chunk. The fmt chunk should be present before the data chunk. Apart from this, there are no restrictions upon the order of the chunks within a WAVE file.

While interpreting WAVE files, the unit of measurement used is a "sample." Literally, it is what it says. A sample represents data captured during a single sampling cycle. So, if you are sampling at 44 KHz, you will have 44 K samples. Each sample could be represented as 8 bits, 16 bits, 24 bits, or 32 bits. (There is no restriction on how many bits you use for a sample except that it has to be a multiple of 8.) To some extent, the more the number of bits in a sample, the better the quality of the audio.

One detail to note is that 8-bit samples are represented as "unsigned" values whereas 16-bit and higher are represented by "signed" values.

references:
http://www.codeguru.com/cpp/g-m/multimedia/audio/article.php/c8935/PCM-Audio-and-Wave-Files.htm

Tuesday, May 2, 2017

WebRTC Basics of FineAudioBuffer

FineAudioBuffer takes an AudioDeviceBuffer (ADB) which deals with audio data corresponding to 10ms of data. It then allows for this data to be pulled in a finer or coarser granularity. I.e. interacting with this class instead of directly with the AudioDeviceBuffer one can ask for any number of audio data samples. This class also ensures that audio data can be delivered to the ADB in 10ms chunks when the size of the provided audio buffers differs from 10ms. As an example: calling DeliverRecordedData() with 5ms buffers will deliver accumulated 10ms worth of data to the ADB every second call.

Constructor is like below.

FineAudioBuffer(AudioDeviceBuffer* device_buffer,
                  size_t desired_frame_size_bytes,
                  int sample_rate);

device_buffer => Is the buffer that provides 10 ms of audio data.
desired_frame_size_bytes => is the number of bytes of audio data GetPlayoutData() should return on success. It is also the required each recorded buffer used in DeliverRecordedData calls
sample_rate => is the sample rate of audio data. This is needed because |device_buffer| delivers 10ms of data. Given the sample rate the number of samples can be calculated.

The two main function in this class are the ones below

1. void FineAudioBuffer::GetPlayoutData(int8_t* buffer)
This method asks webrtc for data in 10 milliseconds

2. void FineAudioBuffer::DeliverRecordedData(const int8_t* buffer,
                                          size_t size_in_bytes,
                                          int playout_delay_ms,
                                          int record_delay_ms)
Deliver the recorded data in in 10ms samples to the observer. Consume samples from buffer in chunks of 10ms until there is not enough data left. The number of remaining bytes in the cache is given by the new size of the buffer.

references:
https://chromium.googlesource.com/external/webrtc/+/master/webrtc/modules/audio_device/fine_audio_buffer.cc

Monday, May 1, 2017

Assertions in C - Pre, Post, Invariants.

In C, assertions are implemented with the standard assert macro. The argument to assert must be true when the macro is executed, otherwise the program aborts and prints an error message. For example, the assertion

    assert( size <= LIMIT );
will abort the program and print an error message like this:

    Assertion violation: file tripe.c, line 34: size <= LIMIT
if size is greater than LIMIT.

There are 3 types of assertions

1. Preconditions : Specify conditions at the start of a function.
2. Postconditions : Specify conditions at the end of a function.
3. Invariants : Specify conditions over a defined region of a program.

An assertion violation indicates a bug in the program. Thus, assertions are an effective means of improving the reliability of programs-in other words, they are a systematic debugging tool.

Preconditions

Preconditions specify the input conditions to a function. Here is an example of a function with preconditions:

int
magic( int size, char *format )
{
    int maximum;

    assert( size <= LIMIT );
    assert( format != NULL );
    ...
These pre-conditions have two consequences:

magic is only required to perform its task if the pre- conditions are satisfied. Thus, as the writer of magic, you are not required to make magic do anything sensible if size or format are not as stated in the assertions.
The caller is certain of the conditions under which magic will perform its task correctly. Thus, if your code is calling magic, you must ensure that the size or format arguments to the call are as specified by the assertions.


Postconditions

Postconditions specify the output conditions of a function. They are used much less frequently than preconditions, partly because implementing them in C can be a little awkward. Here is an example of a postcondition in magic:

    ...
    assert( result <= LIMIT );
    return result;
}
The postcondition also has two consequences:

magic guarantees that the stated condition will hold when it completes execution. As the writer of magic, you must make certain that your code never produces a value of result that is greater than LIMIT.
The caller is certain of the task that magic will perform (provided its preconditions are satisfied). If your program is calling magic, then you know that the result returned by magic can be no greater than LIMIT.
Compare this with the apple-picker analogy. Another part of your contract states that you will not bruise the apples. It is therefore your responsibility to ensure that you do not (and if you do, you have failed.) Your employer is thus relieved of the need to check that the apples are not bruised before shipping them.

Assert Writing preconditions

The simplest and most effective use of assertions is as preconditions-that is, to specify and check input conditions to functions. Two very common uses are to assert that:

Pointers are not NULL.
Indexes and size values are non-negative and less than a known limit.
Each assertion must be listed in the Asserts section of the function description comment in the corresponding header file. For example, the comment describing magic will include:

 *  Asserts:
 *      'size' is no greater then LIMIT.
 *      'format' is not NULL.
 *      The function result is no greater than LIMIT.
 */
If there are no assertions, write ``Nothing'':

 *  Asserts:
 *      Nothing
 */

Assertion violations

If a precondition is violated during program testing and debugging, then there is a bug in the code that called the function containing the precondition. The bug must be found and fixed.

If a postcondition is violated during program testing and debugging, then there is a bug in the function containing the precondition. The bug must be found and fixed.


Turning assertions off

By default, ANSI C compilers generate code to check assertions at run-time. Assertion-checking can be turned off by defining the NDEBUG flag to your compiler, either by inserting

    #define NDEBUG
in a header file such as stdhdr.h, or by calling your compiler with the -dNDEBUG option:

    cc -dNDEBUG ...
This should be done only you are confident that your program is operating correctly, and only if program run-time is a pressing concern.

If you face any error like this while compiling the code, make sure you have #include included.


error: implicit declaration of function 'assert' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

references:
http://ptolemy.eecs.berkeley.edu/~johnr/tutorials/assertions.html

How to convert WAV to PCM format?

Wav files are often just raw PCM data with some RIFF and Wav header  information, depending on whether or not you know exactly whats in there will determine the method you use, stereo pcm data in cd quality sound is interleaved 16 bits per channel left first, often with wav files you can discard the first 44 bytes of the header and write the rest of the pcm data to your card to play or convert, but wav files can contain almost any kind of sound data, mu-law, pcm, adpcm, even mp3 wrapped in a wave file header. Another portable library is libao if you only want to open the file
for playing, very easy to use. but libsndfile does pretty much the same thing, also openal will give you a threaded write to your sound  device if you making a game of some kind.

references:
http://computer-programming-forum.com/47-c-language/7c98914c3e47bd5b.htm