h1

Networking on Linux

2010-04-10

Here’s something worth mentioning. In Arch Linux, there are a couple of places to enable/disable IP forwarding. In order to make sure forwarding is enabled,

/etc/sysctl.conf

net.ipv4.ip_forward = 1.

Also make sure:

/etc/conf.d/iptables

IP_FORWARD=1.

Naturally this all relates to making sure the file

/proc/sys/net/ipv4/ip_forward

has a one instead of a zero in it.

h1

Morphing waveforms

2010-01-22

Ever since graduation, I’ve had more time to focus on projects that are of personal interest. My C++ music project has become a favorite, as I’ve recently been reunited with my old band.

My first task was to make use of the 88 individually sampled 10-second clips of my upright piano. I used sox to convert them from AIFF to WAV since libsndfile prefers WAV, and proceeded to provide the necessary filters to give it a more realistic feel. Dabbling in IIR filter design isn’t a specialty of mine, but I was able to import some C code and refactor it into a C++ class. Looking over the code really highlighted the semantic differences between the two languages, and allowed me to see where efficiency and readability can be at odds. With the primary low-pass filter class in place, I decided to make a few subclasses to hold precomputed filter coefficients for filter sweeps.

I’m now at the point where I want to sample other instruments such as a Hammond organ. I obtained a sample of a Hammond playing a few notes in the low octave range which were highly periodic, and very suitable for my form of wave-table synthesis which involves storing a single period of the waveform in 96,000 samples in memory and then varying the iteration speed to achieve different pitches. My first instinct was to take a period of the lowest possible note (C0) and stretch it to fit 96,000 samples. This produced harmonically distorted results due to the poor zero-crossing within the sample. Refining my method, I decided to take a higher note (A0) having integer frequency (55 or 110 Hz). Using Cool Edit Pro 2.0 (my editor of choice), I applied the stretch function to the waveform, but ended up with slightly more samples than I needed (96016), so instead I doubled the wave several times using the “adjust / convert sample type” functions until the samples numbered about 55,000. At this point, I told CEP to treat the wave as though the number of samples was equal to the sample rate, and then to convert it up to a rate of exactly 96,000. Problem solved, no distortion, sounds great at varying pitches!

I still need to implement LFOs (simple right?) and high-pass filters. I’ve also recently implemented sub-sine on the low keys as my bass instrument, but it needs tweaking to get the Shepherd-tone effect that I’m seeking.

h1

Time allocation

2009-10-07

Here’s how I spent my day:

3pm-5pm
Tutoring introductory algebra. Subtract that from both sides. No not divide, subtract. Ok, now divide both sides… y = mx + b is slope-intercept form.

5pm-9pm
Installing a 32-bit chroot on Arch Linux in order to compile and use nsis on a 64-bit platform. Shell scripts and aliases are your friends. Linux32 seems to provide a transparent way to make it work.

9pm-12:30am
Troubleshooting software installation on Vista. Spent the first 2-3 hours trying various manifest and packaging options and instructing the user to uninstall and install various versions of the Visual C++ 2005 Redistributable file from Microsoft. The only thing that fixed it was using Visual C++ 2008 SP1 in VirtualBox on my MacBook to compile the software, and point to the newer Redistributable. Seriously Microsoft, it shouldn’t be this complicated.

h1

Sweet home West Virginia

2009-10-03

Having been entrusted with yet another infrastructure deployment project, I purchased a SuperMicro barebones system from Newegg along with a Xeon X3220 processor, 8 GB of RAM, and two WD 320 GB SATA-II hard disks. Installing Arch Linux was (as always) a walk in the park, but care had to be taken to set up the RAID properly. The latest version of Arch allows the admin to set up the array, and then write the output of mdadm to mdadm.conf, and doesn’t require kernel parameters– mdadm.conf is loaded immediately during initrd so that no kernel parameters are needed to reload the array.

I was very pleased when the server came online in WV without needing operator assistance. I attribute this to carefully configuring the rc.conf to have the correct IP settings and making sure iptables allowed only SSH access into the machine. Arch Linux isn’t difficult to configure in regard to TCP/IP settings, but it does require some know-how. It isn’t obvious from looking at rc.conf that the gateway settings need to be provided in terms that the route command can directly understand. I referred to my previous work to make sure I had it down cold.

Now that it’s online, I’m spending time tuning and tweaking the system for optimal performance. I realized that some of the code I had written before was very suboptimal, mainly because every page referred to a gigantic >1000 line monstrosity of a PHP class that contained everything needed for the entire management site. I decided to peel layers away from it piece by piece, and I’ve now ended up with several smaller files that are dynamically loaded when they are needed. The common functions live in their own file, and each database table gets its own file to handle validation and presentation. The average load time has dropped significantly as a result.

h1

Pattern Recognition is schooling me in math all over again

2009-09-27

Discriminant functions:

g(x) = x⃗ᵗ W⃗ᵢ x⃗ + w⃗ᵢx⃗ + wᵢ₀

the first is the product of a 1×2 row vector, 2×2 matrix, and 2×1 column vector. This should return a scalar. Leaving x⃗ as an independent variable (e.g. x⃗ = {{x₁},{x₂}}), yields a quadratic equation such as Ax₁² + Bx₂² + (C+D)x₁x₂. The second part gives Ex₁ + Fx₂, and the last part is just a scalar with no variable coefficient attached.

I’ve been using Numpy within Python with Matplotlib and a bit of Scipy in order to do my homework for this class. In creating my functions to take data and crunch it, I’m being very general with the dimensionality of the data set. I have a function that can take in the W⃗ matrix and the w⃗ vector, and produce as its output a list of coefficients of the resulting quadratic, using the size of the list and the order of its elements to encode the independent variables x₁² x₂² x₁x₂ x₁ x₂ and so on.

h1

Windows 7 + memory upgrade

2009-08-25

Didn’t change a thing. Same issues.

Here’s another link about the problems people are having.

But I’m not complaining about the performance increase in Windows XP Pro 32-bit. Using the /3GB switch in boot.ini enables XP to allocate up to 3 GB of memory to an application, instead of its default behavior of splitting the entire RAM between system and applications 50/50. Since my motherboard doesn’t support running memory at 1066 MHz, I’ve been forced to leave my clock settings alone. It seems as though I can tweak my timings to 4-4-4-12 if I increase the voltage to at least 2.0V, but I’d rather have stability at 1.8V running with 5-5-5-15 timings. With a new motherboard, I could take advantage of syncing the memory to the processor at 1066 MHz, but I’ll probably hold off and spend money on a whole new setup since this one performs decently.

One thing I hate is blue screens of death… I’ve gotten a few in the process of tweaking my settings… all of them a stop 0x50 error: PAGE_FAULT_IN_NONPAGED_AREA. I’ve also upgraded my BIOS and made sure my chipset drivers are up-to-date.

h1

Nyquist

2009-08-21

I’ve spent the last 90 minutes reading a bunch of DSP geeks arguing about whether 192 kHz audio is worthwhile at
dsprelated.com. Here are a few references for context:
Nyquist-Shannon sampling theorem, pulse-code modulation.

Many argue that since most humans can’t perceive sounds greater than 20-22 kHz, it doesn’t make sense to encode at a higher rate than twice that; CD audio is defined as 44.1 kHz. While Nyquist states that twice the audible threshold is sufficient to encode audio, he is careful to note that it is sufficient assuming ideal components for reproduction of said audio. Bandlimiting must be ideal during the ADC process to avoid aliasing, and the DAC’s output must use ideal sinc functions and impulses to avoid interpolation error. Increasing the sample rate mitigates the error caused by unideal conversion processes.

There’s certainly a reason that many prefer the sound of vinyl compared to that of a CD, and the term most people use to describe the difference is “warmth”. Because of the way a CD’s audio is encoded, frequencies in the mid range (200-800 Hz) can end up sounding muddy. While a CD is producing a piecewise staircase pattern (one with smoothed step corners under circumstances involving high-end DACs), the information stored on vinyl is a continuous analog curve. To put it in simple terms, the more samples there are, the closer to analog a digital recording becomes – visualize it as the steps being less steep and closer together; more intermediate steps.

The middle frequencies get muddied up because it takes a series of numbers to represent any one frequency, and at any given time in a piece of music, many frequencies must be reproduced simultaneously. Picturing a histogram provides a clear example of what is going on: there are only so many bins that can be defined in the result of a Fourier transform. If a frequency ends up being a non-integer-divisible numerator over the sample rate, the frequency will end up falling into multiple bins of adjacent integer frequencies – quantization error I believe it’s called. By increasing the sample rate, more frequency bins are available, allowing for finer frequency resolution and cleaner reproduction of music, especially music that involves non-equal-temperament tunings.

Another fine example of reduced audio quality is that of the result of MP3 compression. Some may argue that an analysis of the frequency response is identical to that of uncompressed audio, but IMHO it’s not a very good argument. One only has to crunch audio down to a lower bitrate to understand the horrors of MP3 compression and what it does to the signal. That weird tinny sound in the upper frequency range is the result, and can be avoided by destroying (bandlimiting) data in the higher frequency range for better results, but clearly MP3 compression is lossy so any further discussion to the contrary is absurd. MP3 compression “gets rid” of “things we normally can’t hear” by reducing the frequency resolution through Fourier transformation and further quantization.

Ultimately I think it boils down to what people enjoy. Personally I think there’s room for more research in sampling. Not that Nyquist was wrong, but just that most people take for granted the part about things needing to be “ideal”. Multi-channel audio is certainly better than monophonic or stereophonic audio, and I think it’d be nice to see an audio format that stores multiple frequency ranges in different channels – like the subwoofer channel on a DVD… let’s have four channels for four ranges of frequencies: lo-lomid-midhi-hi, and two sets of those to make stereo, or maybe just channel one for the lowest frequencies since directionality is less perceptible at those rates, for a total of seven channels. Or even crazier, what if we separated the channels by odd/even frequencies?

One last thought about the issue of higher resolution: Digitized audio is the sum of periodic functions. Not too long ago I set about to improve my sub-frequency sinewave samples for use in music production. When generating sinewaves at low frequencies in equal temperament, I ran into the issue of period variance. Each sample had to be trimmed differently because the zero-crossings varied. Like a continued fraction or irrational number, some frequencies simply cannot be represented by a finite series of digits.

Some argued that it’s all about the money and taking money from naive consumers, and I think that’s an unfair remark. Yes, the record industry is in fact out to make a profit, and I disagree heavily with some of the legal tactics they’ve undertaken to achieve that goal, but offering higher-resolution sampled audio data isn’t dishonest in the least. For now, analog ultimately wins the quality battle, and one can only hope that more research will be undertaken by those who care equally about empirical quality and listener satisfaction.