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