Welcome to my musings on whatever topic catches my eye, plus stories, recipes, handyman tips, welding, photography, and what have you. Oh, and analog/digital hardware design, and software. Please comment on the blog post so everyone who visits can see your comments.

Category: Educational (Page 14 of 27)

Educational topics and useful things to know.

Simplest Way to Play Raw PCM Audio on Ubuntu: libao

There are a zillion ways for a Linux programmer to play audio through the sound card.  This is the problem.  There are many layers to the audio system, many ways to go, and most of them are very complex because multimedia is very complex.

But what if you have the simplest of all cases where you have a buffer in memory containing raw PCM samples, ready to play, and you just want to pump the data out to the sound card and play it at a certain sample rate?  In many cases you’re looking at hundreds of lines of code, writing your own plugin, etc.

After two days of asking questions, Googling, and reading, I finally found what I was looking for.  Libao is part of the standard Ubuntu distribution and it does the job without writing tons of code.

I found a couple of examples but both had problems compiling cleanly.  After using Synaptic to install the libao development files the following will compile cleanly on Ubuntu 10.04 using the gcc command shown in the comments below:

 /*  
  *  
  * ao_example.c  
  *  
  *   Written by Stan Seibert - July 2001  
  *   Modified slightly by Phil Landmeier - February 2011  
  *  
  * Legal Terms:  
  *  
  *   This source file is released into the public domain. It is  
  *   distributed without any warranty; without even the implied  
  *   warranty * of merchantability or fitness for a particular  
  *   purpose.  
  *  
  * Function:  
  *  
  *   This program opens the default driver and plays a 440 Hz tone for  
  *   one second.  
  *  
  * Compilation command line (for Linux systems):  
  *  
  *   gcc -lao -ldl -lm -o ao_example ao_example.c  
  *  
  */  
 #include <stdio.h>  
 #include <string.h>  
 #include <ao/ao.h>  
 #include <math.h>  
 #define BUF_SIZE 4096  
 int main(int argc, char **argv)  
 {  
     ao_device *device;  
     ao_sample_format format;  
     int default_driver;  
     char *buffer;  
     int buf_size;  
     int sample;  
     float freq = 440.0;  
     int i;  
     /* -- Initialize -- */  
     fprintf(stderr, "libao example programn");  
     ao_initialize();  
     /* -- Setup for default driver -- */  
     default_driver = ao_default_driver_id();  
     memset(&format, 0, sizeof(format));  
     format.bits = 16;  
     format.channels = 2;  
     format.rate = 44100;  
     format.byte_format = AO_FMT_LITTLE;  
     /* -- Open driver -- */  
     device = ao_open_live(default_driver, &format, NULL /* no options */);  
     if (device == NULL) {  
         fprintf(stderr, "Error opening device.n");  
         return 1;  
     }  
     /* -- Play some stuff -- */  
     buf_size = format.bits/8 * format.channels * format.rate;  
     buffer = calloc(buf_size,  
             sizeof(char));  
     for (i = 0; i < format.rate; i++) {  
         sample = (int)(0.75 * 32768.0 *  
             sin(2 * M_PI * freq * ((float) i/format.rate)));  
         /* Put the same stuff in left and right channel */  
         buffer[4*i] = buffer[4*i+2] = sample & 0xff;  
         buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff;  
     }  
     ao_play(device, buffer, buf_size);  
     /* -- Close and shutdown -- */  
     ao_close(device);  
     ao_shutdown();  
  return (0);  
 }  

High Light Bulb Changer


So you have a light bulb in a high ceiling fixture and no ladder.  What to do?  Make your own light bulb changer.

Materials needed:

Broom stick with standard Acme threads
An empty 2 liter plastic soda bottle
An old cotton t-shirt
Small amount of tape (electrical, duct, masking, whatever)
Sharp knife

Steps:

1.) Cut the bottle approximately as shown in the photo.  Be careful because this kind of plastic is tough.  Both the knife and the plastic can cut you.  You don’t need or want a smooth clean edge on the plastic.  A ragged edge is fine.  (see below)

Top portion of bottle attached to broomstick.

2.) Screw the broomstick into the mouth of the bottle until it’s snug, then apply a wrap or two of tape as shown in the photo to make sure it stays in place.

3.) Take the old t-shirt and fold it once so there are four layers of material and carefully fit it into the bottle.  What I do is fold the t-shirt then lay it over a light bulb and use the bulb to gently press the shirt into the bottle.  Once the shirt is in place, you can replace bulbs all day long without readjusting the shirt.

Old T-Shirt Inserted

4.) Now you’re ready to go.  Gently press the tool up over the existing bulb and twist the broom stick counterclockwise to unscrew it.  Put the new bulb into the tool and install it.

BE GENTLE!  This device grips the bulb and gives a lot of leverage so it’s very easy to twist the bulb right off and break it.  Fingertip pressure is all you need to hold the broom stick.

The way it works is the sharp edge of the bottle tends to grab the t-shirt material so the shirt doesn’t slip.  When you twist, the cotton t-shirt material takes about a 1/8th turn wrap on the bulb and grips it.  The harder you twist, the tighter it grips.  A heavy cotton t-shirt works best and a dirty t-shirt grips better than a clean t-shirt.

How it looks when ready to use.

This device works equally well on incandescent bulbs and spiral CFLs (compact fluorescents).  For very small bulbs, fold the t-shirt twice before inserting it.  For other shapes like long skinny CFLs you might try the same methods but with differently shaped bottles.

Cook Over Wood More Efficiently


A huge number of people in the world use wood fuel for cooking. Cooking over wood is very common here in Guatemala. Wood fires generally produce a lot of pollution and smoke, and result in deforestation in some areas.

But wood is not such a bad fuel if we burned it more efficiently. The problem is that methods for burning wood are terribly inefficient. Most wood fueled cooking setups waste over 90 percent of the heat produced. The heat just goes off into the atmosphere and not into the item being heated. We also burn wood at a lower than optimum temperature, which results in wasted fuel, incomplete burning, and production of smoke.

If we could raise the efficiency of the burning process and at the same time focus the heat produced into the cooking pot or other item being heated instead of wasting it, we could theoretically get the same cooking done faster, using a lot less wood, and producing a lot less pollution.

Devices that burn wood more efficiently and that you can cook on are not that difficult to construct if you know how to build things from sheet metal and weld it together. And you’ll end up with a fairly large, heavy, non-portable device. But most people in poor countries do not have the ability to build such things and cannot afford to buy a large, heavy, and thus expensive device.

In order to make an efficient wood burning device that is small and portable you have to use forced air. Well that’s out of the question in poor countries, isn’t it? But what if the device generated its own electricity to power a fan for the forced air. Way too complicated and unreliable, right?

Perhaps not. Check out the BioLite. It’s a pretty neat idea.

« Older posts Newer posts »

© 2025 Shuttersparks

Theme by Anders NorenUp ↑

Find me on Mastodon