Solving problems in software :)

I bought a S/PDIF-analog converter in DealExtreme. It works well, but outputs an annoying buzz when no signal is present. Some say it is a defect, some say it is by design, the converter expects a continuous optical signal.

Unfortunately, Mac turns off the optical link when there's no sound for 10 seconds or so. The obvious kludgey solution is to play continously a silence audio stream.

The program below uses CoreAudio to do so. It eats 6% CPU, but nothing is perfect :)

#!/usr/bin/env python

import thread
import coreaudio # http://wiki.python.org/moin/MacPython/CoreAudio
import time

class Ctrl(object):
def callback(self):
# called in another thread context!
return self.silence

def __init__(self):
audio_id, sampling_rate, chunksize = coreaudio.initAudio()
self.silence = [0.0 for i in range(0, chunksize)]
coreaudio.installAudioCallback(audio_id, self)

def stop(self):

# Have to initialize the threading mechanisms in order for PyGIL_Ensure to work
thread.start_new_thread(lambda: None, ())

ctrl = Ctrl()
except KeyboardInterrupt:

This is actually a nice example of how to use CoreAudio in Python, and it was based in a project of mine, PaiMorse. The start_new_thread is there only to make the interpreter thread-aware, because CoreAudio creates threads unbeknownst to Python.