Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Monday, January 28, 2013

#starling framework video tutorials

here are a nice set of video tutorials by +Hemanth Sharma to get you started with the starling framework:
http://youtu.be/RTvhZ8wbJaQ

if you don't use proprietary software like "flex builder", mind that you can set everything on the command line using the flex tools "mxmlc", "adl", "adb". i'm sure there are examples on how to do that online. flex is open source as is now maintained by the "apache software foundation".

--

Friday, March 18, 2011

#stripping down the windows sdk 3.5

here are some notes on how to strip down the size of the windows sdk 3.5 if you only need the set of compiler and libraries. this is a straight copy-past from a recent forum post...


[post]
you can strip down the 3.5 sdk as follows:


- get setup.exe from here:
link

(notice what the title says: Windows SDK for Windows Server 2008
_and_ .NET Framework 3.5)

- destination "somedrive:\sdk_tmp"

- install only the following components:
developer tools -> windows headers and libraries
developer tools -> compilers

- copy "program files\microsoft visual studio x.x" to "somedrive:\msvc"
- copy "somedrive:\sdk_tmp" to "somedrive:\sdk"
- goto "somedrive:\sdk" and delete everything but "lib" and "include"

- inspect the files "somedrive:\msvc\vc\bin\vcvars*.bat"

- set path to "somedrive:\msvc\vc\bin"
- set your environment variables "lib", "include", "windowssdkdir",
"vsinstalldir" etc..

- strip further libraries and compilers you don't need (e.g. for IA64).

- uninstall the 3.5 sdk


depending on what you have deleted and kept you will end up with a footprint of 100-400mb, which is a realistic size for a set of cross-compilers and libraries.

on low level debugging:
- find a older build of windbg (6.11.1 or something) (~20mb)
- include debug symbols with /Zi (or linker /debug) in your object code.
- follow trivial debug procedures...
reports in the category of addr2line should be available

or use alternative debuggers / methods...

[eop]

lubomir
--

Tuesday, February 15, 2011

#win32: automatic backup script for 7za

here is a small batch script for windows that will periodically create a zip backup of a certain folder with 7za.

on the top of the 'backup.cmd' it is possible to set:
- source path (folder where 'backup.cmd' is by default)
- target path
- update period (minutes)
- excluded files and sub-folders (7za option)
- other compressor options
(for more information about 7za options see: '7za -h')

just check the above settings and place the file in the project folder you wish to backup.
the result will be written at the 'target path' as 'foldername_date_timestamp.zip'.
it can be easily modified so that another compressor is used.

download link

Sunday, April 4, 2010

#send to cmd.exe

here is an useful trick. wonder if you can always right click a file under windows and open the file location in a command prompt?

on win xp. navigate to:
"[Drive]:\Documents and Settings\[Username]\Sendto"

on vista or 7 the folder should be at:
"[Drive]:\users\[Username]\AppData\Roaming\Microsoft\Windows\SendTo"

create a new file called "SendTo.cmd", place the following line of code inside it and save:

@cmd /a /k cd /d %~d1%~p1
what this commands does is:
echo off, open cmd.exe with ansi output, carry out a command and remain, change directory to the first input file's drive and path

now every time you right click a file or a folder and call "Send To -> SendTo.cmd" you will have a command prompt with its parent folder open.

for example:
right clicking + "sendto.cmd" any file or sub-folder in "c:\windows\system32\"
will open a command prompt showing:
"c:\windows\system32>"

lubomir

Thursday, February 25, 2010

#c++: function callbacks between classes and accessing non-static members from static methods

i was looking for a way to use a class in c++ as a processing container, which does callbacks to methods in another class. an example in digital signal processing can be given as: a tone generator which normally operates at sample rate fs=44100 Hz, but is oversampled to fs * 2 via an oversampling container.

now, of course the above can be inlined in a single method, which will be essentially faster, but leaves us with a composite method, instead of a case where both processes (tone generator and oversampler) are separated in classes and can be reused by other processes in a more object oriented class structure.

lets take a look at a case where the main processing method is in the parent class and the other processing method (a processing container) is in a sub class (or a class which is initiated inside the parent class).

here is an example:

// include a class from a header
#include "childclass.h";
// define parent class
class parentclass
{
  private:
    // child class instance
    childclass _childclass;
    // some variable
    float some_variable;
    
  public:
    // constructor
    parentclass()
    {
      // init stuff
      some_variable = 5.f;
    }
    
    // the main method
    virtual void processing_main_method(const float input)
    {
      // call a method from the child class and pass the input variable
      _childclass.some_method(input);
    }
}


how about callbacks i.e. passing a method which to be called from another method? in the c programming language to achieve that function pointers are used.here is a nice article that covers mostly everything on the subject of function pointers on callbacks:
http://www.newty.de/fpt/callback.html

but what if we decide to make a callback from the child class to a method in the parent class? the logical way to achieve that is to declare a method in the parent class as static. http://www.eelab.usyd.edu.au/ee_database/programming/c++/cplusplus-5.html:

...member of a class can be declared static; be it in the public or private part of the class definition. Such a data member is created and initialized only once; in contrast to non-static data members, which are created for each object of the class. A static data member is created when the program starts executing; but is nevertheless part of the class.

(note: info on static functions in the same article - section 5.2)

some code for our example:

// ==============
// program.cpp
// ==============
// include a class from a header
#include "childclass.h";
// define parent class
class parentclass
{
  private:
    // child class instance
    childclass _childclass;
    // some variable
    float some_variable;
    
  public:
    // constructor
    parentclass()
    {
      // init stuff
      some_variable = 5.f;
    }
    
    // ************************
    // the callback method
    // ************************
    static float processing_callback_method(const float input)
    {
      // do something
    }
    
    // the main method
    virtual void processing_main_method(const float input)
    {
      // call a method from the child class and pass the input variable
      // and also the local processing_callback_method
      _childclass.some_method(processing_callback_method, input);
    }
}

// ===============
// childclass.h
// ===============
// define child class
class childclass
{
  private:    
    float some_variable;
    
  public:
    // constructor
    childclass()
    {
      // init stuff
      some_variable = 5.f;
    }
    
    // ********************************************
    // the method that is called from parent
    // notice how the function pointer is passed
    // ********************************************
    virtual float some_method(float (*callback_function)(float), const float input)
    {
      // do something with input
      // ....
      
      // then do a callback
      return(*callback_function)(input);
    }
}


here is a quick diagram of the above:

.------------------------------------------.
|[*mainclass]                              |
|                                          |
|     processing_main_method               |
|           |                              |
|           |  processing_callback_method  |
|           V                  ^           |
|           |                  |           |
|  .--------|------------------|---.       |
|  |        |                  |   |       |
|  |        '--> some_method ->'   |       |
|  |[*subclass]                    |       |
|  '-------------------------------'       |
'------------------------------------------'


so far so good...
but now we face the issue that static methods cannot access non-static members. actually there is much sense in that if we think about it:

Besides static data, C++ allows the definition of static functions. Similar to the concept of static data, in which these variables are shared by all objects of the class, static functions apply to all objects of the class.

The static functions can therefore address only the static data of a class; non-static data are unavailable to these functions. If non-static data could be addressed, to which object would they belong? Similarly, static functions cannot call non-static functions of the class. All this is caused by the fact that static functions have no this pointer.


the way to solve this would be to pass an instance to the parent class to the subclass function (some_method) and then pass this instance back to the static callback function (processing_callback_method). an example (with void pointers):

// ==============
// program.cpp
// ==============
// include a class from a header
#include "childclass.h";
// define parent class
class parentclass
{
  private:
    // child class instance
    childclass _childclass;
    // some variable
    float some_variable;
    
  public:
    // constructor
    parentclass()
    {
      // init stuff
      some_variable = 5.f;
    }
    
    // *******************************
    // a non-static member function
    // *******************************
    virtual float non_static_method(const float input)
    {
      return input * 2.f;
    }
    
    // ************************
    // the callback method
    // ************************
    static float processing_callback_method(void* _this, const float input)
    {
      // cast the class
      childclass* _pthis = (childclass*) _this;
          
      // do something with a non-static member
      _pthis->some_variable = 1.f;
      
      // call a non-static member function
      return _pthis->non_static_method(input * 0.5f);
    }
    
    // the main method
    virtual void processing_main_method(const float input)
    {
      // call a method from the child class and pass the input variable
      // and also the local processing_callback_method
      _childclass.some_method(processing_callback_method, input);
    }
}

// ===============
// childclass.h
// ===============
// define child class
class childclass
{
  private:
    float some_variable;
    
  public:
    // constructor
    childclass()
    {
      // init stuff
      some_variable = 5.f;
    }
    
    // ********************************************
    // the method that is called from parent
    // notice how the function pointer is passed
    // but also an instance of the parent class
    // ********************************************
    virtual float some_method(void* _parent, float (*callback_function)(void*, float), const float input)
    {
      // do something with input
      // ....
      
      // then do a callback
      return (*callback_function)(_parent, input);
    }
}


so that is all.

please note that i have not tested any of the code from above and its just provided as a guideline.

lubomir

Thursday, March 5, 2009

#Designing an analog VU meter in DSP

Here are some notes on how to design a VU meter DSP fx.
I won't be getting much into the signal detection, but mostly into the visual of the plugin. If you wish to know more about it, please feel free to send me an email and I will be happy to respond to your questions.

Here is what we are going to use as an example. This is a very simple JesuSonic fx:



Setting some dimensions
We begin by setting the width and height for the visualization.
Its important to set the dimensions first, because they will determine the radius of the needle and the span of our scale.

We are going to make a rather large VU meter - 425x260px, with needle radius of 200px. You should be able to create an arch withing these dimensions using the needle radius.

Designing the VU meter scale
After the dimensions are set we can start creating our scale.
You can very easily design the scale, try to approximate other scales, or use ready equations.

In this example we are going to design our own scale by roughly approximating to an actual scale. There are a lot of photos of analog VU meter over the net. Different manufacturers have patented different scales. We will create our own (in a way).
Similar to this one for example:



We can use it as our base. In general its very difficult to make the approximation 100% accurate if you don't know the original function. Still there are ways to (try) to do so. For example LaGrange polynomials can help you with that. It may require a lot of points to be interpolated and the resulting function and the algorithm may became much more inefficient than a simple exp(). Also by using interpolation there might be some minor unavoidable and unwanted deviations between points.

First thing to do is to set some scale markings in dB:
-20, -10, -7, -5, -3, -2, -1, 0, +1, +2, +3

Here is how to convert amp signal in dB and then get the value of X (dB -> pixels on the X axis):



//code executed at bigger intervals - 1024 samples for example

//amp2dB
//take only abs(input) of input
//6/log(2) is our dB scale
in_db = log(abs(input))*6/log(2);

//then

//xl - is the value of X
//in_db - is the value in decibels
//use numbers 2.1 and 285 to tweak the equation
xl = floor(exp(log(1.055)*2.1*in_db)*285);


xl is the result we are looking for here, after converting amp into dB.
A very useful thing to do is to use some sort of a plotting program which can make calculations and draw some lines at the same time. I've used Adobe Flash which is quite fast to work with.


fig.1

The vertical lines on the left and right represent our width. Point O is the center the circle. Point A lies on the circle therefore OA = r. Point S0 represents a point from our scale using the above equations. To draw the actual lines from the scale, two additional large arches may be used (colored in blue). If we connect O with S0 an intersection will occur between the new cirlces and OS0. These are points D01, D02. So lines such as D01D02 will be visible on our scale. When we know all the coordinates of the points we can make an arrayand draw these 'markings' on plugin initialization.

Drawing the needle in realtime
After we have the result on the X axis we can start drawing the needle.
Of course if you wish to use a bitmap as the needle you should use a different method here (i.e. calculate angle of rotation).


fig.2

The math method used here to calculate point A's X,Y coordinates is by using proportional triangles and Pitagor theorem - as simple as it gets. Where: S0A / AO = P1A / AP2 etc. And since we know some of the lengths and coordinates of points we can get point A very easily.


//get y from x and radius - r
//Pitagor and proportional triangles used here
l=sqrt(sqr(r)+sqr(212-xlt));
h=((l-r)*r/l);
m=sqrt(sqr(l-r)-sqr(h));
ylt=35+h;
xlt < 212 ? xlt=xlt+m : xlt=xlt-m; // check if x is < of middle point 212


The results - xlt & ylt are the A's x,y coordinates and after we have them, we can draw a line between O and A in realtime.

Needle response
Updating the needle per sample is not advisable so I suggest that you use some sort of a countdown before make the above calculations. After some trial and error you will get an acceptable 'response' speed. You should know that the magnetic-electric system (inductor+constant magnet) of an analog vu-meter has response of 300ms. This is quite slow but of course you can tweak it.

Another characteristic of the needle response is the inertial fallback. This is due to the inductor exponential discharge. After executing the x,y calculation code you can add the fallback by simply subtracting pixels from X (original exp() scale) while multiplying the result by some factor for adding inertia (emulating the discharge).

Limiting x and y of A may also be a good thing since the given log scale in dB can go as low as -350db. Or you can just limit the input gain value to -25,+3.5 db

RMS window
Adding a RMS detector isn't very difficult to make in DSP either. Here is an example:


//***per sample
//cs - current sample counter
//300 - window in ms
//sum - peak values stored here
if (cs == (0.001*300*44100)) {
cs = 0;
sum = 0;
} else {
cs += 1;
//square the abs value of the input
sum += sqr(abs(input));
}
//***execute at bigger intervals - at sample block for example
//calculate value while converting into dB
//*100/100 is to output the values in the X.XX format
rms = floor(6/log(2)*log(sqrt(sum/cs))*100)/100;


So 'rms' would be our RMS value for a 300ms window.

Thats all...well mostly. If you have any question post a comment here or send me an email.

I leave that task of making the VU meter look good to you.

Lubomir

Wednesday, January 7, 2009

#MP3 player in blog - done easy

I've extended the 'hcon' JS lib to allow quick embedding of MP3 files.

The MP3 embed code is also stored here:
<script src='http://sites.google.com/site/neolit123/Home/hcon' type='text/javascript'/>
The above line should be embedded in you blog template.

How does it work:
<mp3 file="http://locationtomyfile.com/file.mp3" title="Song title goes in here"></mp3>
Demo:


The code is using 'innerHTML' once again so it may not work under IE.
If you wish to modify the JS (mp3 player URL, style etc) download it from here(rename to .js). More info about the player: http://www.1pixelout.net/.

Enjoy
Lubomir

Tuesday, January 6, 2009

#Show/Hide information in blog posts

This is probably the easiest way I've found so far to show/hide contents in posts. There are other solutions floating around but I think this one is the most user-friendly.

To enable the show/hide functionality open you blog-template (customize-layout-edit html) scroll down to the bottom and copy/paste the following code just above the end [/body] tag:

<script src='http://sites.google.com/site/neolit123/Home/hcon' type='text/javascript'/>
Save the template.
This enables the use of a simple [hcon] tag to hide/show contents. Here is an example:
<hcon open="[+]Open..." close="[-]Close...">Loooong text<hcon>More long text</hcon></hcon>
The 'open' and 'close' attributes are used to specify text names for the buttons. If no values are given [+]More... and [-]Less will be used by default. Also you can see that nesting is possible - as complex trees of [hcon] tags.

Here is a demo:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec lacus. Donec ultricies sem id nunc. Integer dignissim aliquam nisi. Phasellus varius. Suspendisse sit amet diam id libero pulvinar commodo. Vivamus a ante. Aenean non nisl. Morbi a turpis id sem gravida accumsan. Vestibulum sollicitudin, ligula sit amet consequat lacinia, neque ante condimentum neque, mollis bibendum quam lacus vel ipsum. Duis ac lectus a ante convallis commodo.
Praesent ac ligula. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Quisque lacus. Vivamus purus. Phasellus quam lectus, volutpat nec, tempor quis, facilisis nec, ligula. Nam fermentum eros eu enim. Maecenas est magna, bibendum eget, auctor vel, ultricies et, ligula. Maecenas id arcu et magna congue posuere. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse potenti. Phasellus interdum. Ut nisi augue, fermentum vel, tempor sed, accumsan vitae, augue. Duis eget tellus. Etiam vulputate aliquet massa. Suspendisse potenti. Curabitur interdum porttitor velit. Ut et arcu et est dapibus porta.

Some notes:
- You can download and modify the hcon file (rename to .js). Also upload it to a faster server.
- Its working with the latest FF, Opera. With IE there seems to be a problem with innerHtml(the bug is described here).
- Under the K-Meleon browser I've noticed that the "blockquote", "div", "h" tags break the [hcon]. Also the the nesting is not working correctly.
- It also supports the [mp3] tag now: Link


Lubomir

Sunday, January 4, 2009

#Reaper beatmatching tutorial

This is a small tutorial in PDF format about beatmatching and mixing tracks in Reaper.

The approach is simple and the results are quite good. I've tried mixing tracks offline with programs like Cooledit, Cubase, Ableton but this method is the fastest so far. You can have a draft CD mix up and running in about 30 minutes. The tutorial also includes some ideas about mixing with EQ & FX envelopes.



View PDF:
Reaper_Tutorial.pdf

Download 22mb (Example project files and mix are included):
Megaupload Link
Sendspace Link

There might be some typos, since I've wrote and compiled the tutorial quite fast.

Lubomir