Showing posts with label way. Show all posts
Showing posts with label way. Show all posts
Friday, May 26, 2017
A geek way to wish Happy Birthday!
There is nothing more awesome than doing regular things in a geeky way. Few days back I was wondering what would be the geekiest way to wish someone happy birthday. It should be geeky alright, but should also have regular things like cake + candles + birthday song + wishing happy birthday.
Now mixing all this with my very little knowledge in signal processing, I wrote a python code which does this:

Fork me on github



Enjoy!
Now mixing all this with my very little knowledge in signal processing, I wrote a python code which does this:

Fork me on github
How it works?
So, here we have a virtual cake whos shade has an equalizer effect corresponding to the "happy birthday" song that is played in the background. Here, the cake has candles with flames fluttering randomly. Also, we have a fancy display of happy birthday message.
Lets see how each of it is done one by one.
Equalizer effect
The key here is to consider a sample size of frames in the audio corresponding to the part which is playing currently and display the normalized amplitudes inside the cake. First lets take a look at the amplitudes in the sound wave (stereo):
Channel L:

Channel R:

As we can see even though the audio has two channels, both are nearly the same. Hence for further calculations we will discard one of the channels. If this was not the case, we should have taken the average of both the channels. If the audio file you have taken is already mono, you dont have to worry about anything.
As there is no negative amplitude in the equalizer effect, we will make all values positive:

Now that we have the required data, we can iterate over the frames and display the amplitudes in the cake to give equalizer effect. In the current example, I am considering 1500 frames per iteration. No matter how many frames you consider in a given iteration, the total time taken to complete the iteration should be same as the time required to play the song. Hence we add a sleep after every iteration. The net sleep time+processing time should be equal to songs play time.
We cant display all the 1500 frames at a given time. Hence we take samples in that 1500 frames and averages of each sample is found. The averages are then normalized between the maximum and minimum amplitudes that can occur in the entire song. These normalized averages are then represented as a sequence of 8s (longer the sequence implies higher the amplitude).
Walah! you have the equalizer effect.
There is a serious problem here. The time required for processing, printing on terminal and waking up from sleep are not determinable. For instance printing on xterm happens very fast whereas the mac terminal or gnome-terminal can be very slow. Hence we need to add a manual correction to the sleep time in order to stay in phase with the song which is being played.
Fluttering candle flames
If you observe the video, the candle flames can have three states:
<space> <dot> <space>
<space> <space> <dot>
<dot> <space> <space>
So basically we just have to randomly switch between these three states to get the fluttering candle flame effect.
Happy birthday text
I have used figlet to print the message. You can also display with different fonts and sizes.
Python Code
Enjoy!
Saturday, May 20, 2017
A better way to power car audio in home
Usually, car audio systems like CD player or cassette player have good audio amplifiers, with four channels (front L/R and rear L/R) of enough power for in home use. The radio tuner is also of high quality, with automatic best frequency selection and RDS information. Not all car audio systems have audio auxiliary inputs, although with a little tweaking, you can add audio line level inputs to a cassette player so you can use it as audio amplifier with any audio source.
There are plenty of how-to's about this subject online. Yet I couldn't find one that handles the memory loss problem. Car audios are designed to be continuously powered by the battery. Therefore, most don't have a permanent storage memory for settings. Upon disconnecting the power, the device loses all audio settings and stored radio stations.
This article will deal with the memory loss problem. Unless you will never unplug the DC adapter from the mains, you will need something similar to what follows if you want to use a car audio device in home. Let's start with the basics.

Tuesday, April 11, 2017
A better way to define Java error codes
"Use enums instead of int constants" - This is one of the recommendations in the book "Effective Java". So whats wrong with int constants? Consider these error codes:
Here are some limitations if you are using the int constants in your code.
public static final int INVALID_REQUEST = 0;
public static final int MISSING_PARAMETER = 1;
public static final int MISSING_HEADER = 2;
Here are some limitations if you are using the int constants in your code.
- There is no type safety since compiler will not complain if you pass the INVALID_REQUEST to a method which expects a different a error code, say MISSING_HEADER.
- There is no namespace for int constants so there may be name clashes.
- No way to translate constants to printable strings which is meaningful for a user.
The alternative is to use the "enum" type as shown below:
public enum MyExceptionCodes {
INVALID_REQUEST(0, "The request is invalid"),
MISSING_PARAMETER(1, "Required query parameter is missing"),
MISSING_HEADER(2, "Required header is missing");
private final int id;
private final String msg;
MyExceptionCodes(int id, String msg) {
this.id = id;
this.msg = msg;
}
public int getId() {
return this.id;
}
public String getMsg() {
return this.msg;
}
}
Now you can use above enum, MyExceptionCodes, in your exception handling code.
public class MyException extends Exception {
private int errorCode;
private String errorMsg;
public MyException(MyExceptionCodes code) {
this.errorMsg = code.getMsg();
this.errorCode = code.getId();
}
public int getErrorCode() {
return errorCode;
}
public String getErrorMsg() {
return errorMsg;
}
}
Here is an example which shows how to use the error codes we just defined. public class Test {
public static void throwE() throws MyException {
throw new MyException(MyExceptionCodes.MISSING_HEADER);
}
public static void main(String[] args ) {
try {
throwE();
} catch (MyException e) {
e.printStackTrace();
System.out.println(e.getErrorMsg());
}
}
}
By using an enum type instead of int constants, you get compile time safety, name space protection, and easy conversion to a string representation. In addition, you can add rich methods to enhance your error codes. How about returning a link to an html page with the exception?
Search
Blog Archive
-
2021
(1060)
-
December
(48)
- Download Legend Of The Seeker O2tvseries
- Free Download Java Programming Pdf
- Download Doraemon New Episodes Mp4
- Free Download Preset Manager Sony Vegas
- Download Mp3 Catur Arum
- Download Film Comedy Terbaik
- Sql Accounting Download New Version
- Download Video Instagram Y2mate
- Star Wars Language Font Download
- Wallpapers Download In 3d
- Download Google Images App
- Resident Evil 2 2nd Run Lion Statue
- Download Miui 10 Via Updater
- Free Download Psd Viewer Software
- Google Earth Pro Gold Edition 2013 Free Download
- Download Cheat Zombie Age 2 Mod Apk
- Download Buku Google Play Gratis
- Download Lagu Bagaikan Langit Dan Bumi Cover Gitar...
- Download Snap Music
- Download Google Earth Live Apk
- Download Lagu Diantara Bintang Cover
- Download Filmora Windows 7 32 Bit
- Filmorago Apk Download Uptodown
- Download Vlc Player Offline Installer Free
- Dj Yankee Lean On Me Video Download
- Citra Emulator Download For Pc Windows 7
- Download Warship Battle Mod Apk Unlimited Gold New...
- Download Aplikasi Edit Nama Terbaru
- Download Emulator Coc Untuk Pc
- Download Lagu Bulan Bintang D'ubud Band Mp3
- Game Virtual Families 2 Mod Apk
- Redmi Note 8 Pro Stock Camera Apk
- Download Naruto Ultimate Ninja Storm 3 Apk Android
- Download Idm Crack Pc
- Download Warcraft 3 And Frozen Throne Full Version
- Download Mp4 Asmara Cover By Ines
- Download Idm Terbaru Tanpa Serial Number
- Google Play Store App Download For Sony Ericsson X...
- Download Image Google Earth Engine
- Download Google Font Lobster
- How To Download Google Drive Files On Mac
- Youtube Download Google Home App
- Jio Tv Channel Download Karo
- Download Lagu Leona Lewis You Dont Care
- Google Chrome Windows Xp Download Gratis
- Free Download Psd Card Business
- Apps To Download Video Songs For Android
- Huawei Camera Apk Download
- November (104)
- October (95)
- September (82)
- August (102)
- July (95)
- June (91)
- May (98)
- April (86)
- March (85)
- February (73)
- January (101)
-
December
(48)