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.

Author: Phil (Page 20 of 51)

Hello. I'm a retired electronic hardware, software & mechanical engineer. My hobby is making metal art. My interests range across writing, economics, politics, history, photography, fountain pens, languages, ham radio, and music. I've been writing software since 1968.

The Paradox of Tolerance: If a society is tolerant without limit, its ability to be tolerant is eventually seized or destroyed by the intolerant. --Karl Popper

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);  
 }  

Major Flickr Accident

Photo sharing service Flickr accidentally deleted a user’s photos.  Five years and 4,000 photos are gone and there’s no recovery, no backups.  Read about it here:

http://techcrunch.com/2011/02/02/flickr-accidentally-wipes-out-account-five-years-and-4000-photos-down-the-drain/

If just the thought of this gives you a wave of nausea, there are solutions to the problem such as this one:

http://www.backupify.com

How about your Gmail account?  Google Docs?  I have 1,500 spreadsheets and 300 important documents plus miscellaneous stuff stored on Google Docs and can’t afford to lose them.  What about all your posts on Facebook?  A service like Backupify can give you a level of safety and control you don’t have now.

Install Fails, Files Out of Date

The other day I was trying to install the software for a digital oscilloscope and ran into a problem.  The software is written in Visual Basic.  The installer said that “certain files are out of date” and offered to update the files before rebooting the system.  If you answer no, the installer quits.  If you answer yes, the system reboots and when you run the installer again it repeats the “files out of date” message.  There’s no way to get past this, but I have found a workaround.  The problem occurs with both the Microsoft and Nullsoft installers, and it happens on Windows 2000 and XP.

How To Fix It

Your installable program will consist of at least a setup program, a CAB file, and a file called SETUP.LST.  SETUP.LST is structured like an INI file so you can open it with a text editor like Notepad.  Don’t use a word processor.  If you open SETUP.LST you’ll see the file organized into sections that look something like this:

[Bootstrap]
SetupTitle=Install
SetupText=Copying Files, please stand by.
CabFile=app.CAB
Spawn=Setup1.exe
Uninstal=st6unst.exe
TmpDir=msftqws.pdw
Cabs=1

[Bootstrap Files]
File1=@VB6STKIT.DLL,$(WinSysPathSysFile),,,7/15/00 12:00:00 AM,101888,6.0.84.50
File2=@COMCAT.DLL,$(WinSysPathSysFile),$(DLLSelfRegister),,5/31/98 12:00:00 AM,22288,4.71.1460.1
File3=@asycfilt.dll,$(WinSysPathSysFile),,,3/5/10 7:37:40 AM,65536,5.1.2600.5949
File4=@olepro32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,4/14/08 6:42:04 AM,84992,5.1.2600.5512
File5=@oleaut32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,4/14/08 6:42:04 AM,551936,5.1.2600.5512
File6=@stdole2.tlb,$(WinSysPathSysFile),$(TLBRegister),,4/13/08 10:12:08 PM,16896,5.1.2600.5512
File7=@msvbvm60.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,4/14/08 6:42:02 AM,1384479,6.0.98.2

The problem is in the [Bootstrap Files] section.  Several of the files in that section are unnecessary.  If you comment them out (by putting a semicolon at the start of the line) your install will proceed without any problems.  You may have to experiment with how many files to comment out but in general you should keep the first two or three files in the list and comment out the rest.  The configuration that worked for me is below.  Your SETUP.LST file will probably be slightly different.

[Bootstrap Files]
File1=@VB6STKIT.DLL,$(WinSysPathSysFile),,,7/15/00 12:00:00 AM,101888,6.0.84.50
File2=@COMCAT.DLL,$(WinSysPathSysFile),$(DLLSelfRegister),,5/31/98 12:00:00 AM,22288,4.71.1460.1
;File3=@asycfilt.dll,$(WinSysPathSysFile),,,3/5/10 7:37:40 AM,65536,5.1.2600.5949
;File4=@olepro32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,4/14/08 6:42:04 AM,84992,5.1.2600.5512
;File5=@oleaut32.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,4/14/08 6:42:04 AM,551936,5.1.2600.5512
;File6=@stdole2.tlb,$(WinSysPathSysFile),$(TLBRegister),,4/13/08 10:12:08 PM,16896,5.1.2600.5512
;File7=@msvbvm60.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,4/14/08 6:42:02 AM,1384479,6.0.98.2

Good luck!
« Older posts Newer posts »

© 2025 Shuttersparks

Theme by Anders NorenUp ↑

Find me on Mastodon