Monthly Archives: January 2013

gstreamer

Here are some helpers for dealing with gstreamer

Sample gstreamer usage

# default audio src (does not work on mac mini with ubuntu)
gconfaudiosrc
# mac mini source from usb microphone
osssrc device=/dev/audio1
# run from file
filesrc location=current.raw blocksize=2048 ! audioparse rate=8000 channels=1 width=16
# save to file
! filesink location=filtered.raw
# play on speakers
! autoaudiosink
# audio format used
! audioconvert ! audioresample ! audio/x-raw-int rate=8000 channels=1 width=16
# active noice cancelling
! speexanc
# voice activation detector (part of pocketsphinx)
! vader name=vad auto-theshold=1
# voice recognition using pocketsphinx
! pocketsphinx name=asr lm=commands.lm dict=commands.dic configured=1

Sample gstreamer pipeline

PIPELINE="
osssrc device=/dev/audio1
! audioconvert
! audioresample
! audio/x-raw-int rate=8000 channels=1 width=16
! speexanc
! vader name=vad auto-theshold=1
! pocketsphinx name=asr lm=commands.lm dict=commands.dic configured=1
! fakesink
"

Splitting gstreamer pipeline into two parallel ones using tee

gst-launch audiotestsrc ! tee name=t ! queue ! speexanc silent=false ! autoaudiosink t. ! queue ! filesink location=file.raw

NEED TO SET leaky=1
http://www.oz9aec.net/index.php/gstreamer/410-x264enc-problem-in-gstreamer-video-switcher-solved

Today I learned how to fix it and make x264enc work in this pipeline, thanks to an email on the GStreamer-devel mailing list . In his email Senthil writes that “The queue will block the supplier when there is no more space in it. … Since x264enc may take more time to consume, setting leaky property (as suggested in the doc) on the queue before xvimagesink might help” – and indeed it does!

! tee name=t ! queue leaky=1 ! filesink location=log.raw t. ! queue leaky=1

makefile built in rules

To disable makefile built in rules call make with ‘-r’ or ‘–no-builtin-rules’

To disable makefile build in variables call make with ‘-R’ or ‘–no-builtin-variables’

To see all built in rules try ‘make -p -f /dev/null’

text to speech options on linux

espeak

eSpeak is a software speech synthesizer for English, and some other
languages.

eSpeak produces good quality English speech. It uses a different synthesis
method from other open source text to speech (TTS) engines, and sounds quite
different. It’s perhaps not as natural or “smooth”, but some find the
articulation clearer and easier to listen to for long periods.

It can run as a command line program to speak text from a file or from stdin.

* Includes different Voices, whose characteristics can be altered.
* Can produce speech output as a WAV file.
* Can translate text to phoneme codes, so it could be adapted as a front end
for another speech synthesis engine.
* Potential for other languages. More than 40 languages are included.
* Compact size. The program and its data total about 350 kbytes.
* Written in C++.

festival

Festival offers a full text to speech system with various APIs, as well an
environment for development and research of speech synthesis techniques. It
includes a Scheme-based command interpreter.

Besides research into speech synthesis, festival is useful as a stand-alone
speech synthesis program. It is capable of producing clearly understandable
speech from text.

flite

Flite is a small fast run-time speech synthesis engine. It is the
latest addition to the suite of free software synthesis tools
including University of Edinburgh’s Festival Speech Synthesis System
and Carnegie Mellon University’s FestVox project, tools, scripts and
documentation for building synthetic voices. However, flite itself
does not require either of these systems to run.

It currently only supports the English language.

linux find command

linux command find does wonders! It has a rich set of options to find any kinds of files and directories and execute commands on those files.

find dirname -name fname

More examples:

find . -name a.out -executable
find . -name *.o -delete
find . -name dirtofind -type d
find . -name filetofind -type f

To execute a command on every file you find:

find . -name *.hh -exec ls -l {} ;

And much more. See man find

pahole shows data structures from debug data in ELF binaries

pahole is a part of dwarves utilities package and can parse structure information from DWARF and CTF fields in your binary executables. Pahole is useful for highlighting data packing discrepancies and cache alignment in data structures. This can be very useful for data structures that are stored in RAM and are accessed by your main bottlenecks. It can particularly come in useful when switching to 64bit machines. It should be used in very very very late stage of optimization 😉

Installation

Ubuntu makes it very easy:

sudo apt-get install dwarves

Example

Let’s write a simple test file:

#include <stdint.h>

struct S {
  struct S*    a;
  struct S*    b;
  uint8_t      c;
  double       d;
  int32_t      e;
  int32_t      f;
  int32_t      g;
  uint16_t     h;
  uint16_t     i;
  float        j;
  int16_t      k;
  int8_t       l;
  double       m;
  int32_t      n;
  double       o;
  int32_t      p;
  double       q;
};

int main(int argc, char ** argv)
{
  struct S s;
  return 0;
}

and compile it with debug flags

g++ -g test.cc

This will produce an executable called a.out. Now we simply run pahole with the newly created executable as an argument.

pahole a.out

The output is fairly informative:

/tmp> pahole a.out
struct S {
	class S *                  a;                    /*     0     4 */
	class S *                  b;                    /*     4     4 */
	uint8_t                    c;                    /*     8     1 */

	/* XXX 3 bytes hole, try to pack */

	double                     d;                    /*    12     8 */
	int32_t                    e;                    /*    20     4 */
	int32_t                    f;                    /*    24     4 */
	int32_t                    g;                    /*    28     4 */
	uint16_t                   h;                    /*    32     2 */
	uint16_t                   i;                    /*    34     2 */
	float                      j;                    /*    36     4 */
	int16_t                    k;                    /*    40     2 */
	int8_t                     l;                    /*    42     1 */

	/* XXX 1 byte hole, try to pack */

	double                     m;                    /*    44     8 */
	int32_t                    n;                    /*    52     4 */
	double                     o;                    /*    56     8 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	int32_t                    p;                    /*    64     4 */
	double                     q;                    /*    68     8 */

	/* size: 76, cachelines: 2 */
	/* sum members: 72, holes: 2, sum holes: 4 */
	/* last cacheline: 12 bytes */
};	/* definitions: 1 */