As part of my next crazy project on the Pi I'm trying to generate time of day linear timecode in order to jam a real timecode generator.
I have written a Python function which runs in the background as a daemon thread. It gets the time from time.time, converts it to local hours, minutes, seconds and frames, then turns those into a string of 0 and 255 ascii characters, complete with phase correction bit and end of packet marker. This is a total of 10 bytes of 8 bits each, with each bit represented by 4 audio samples, 25 times per second, total 8000 samples per second. This string is then sent to the /dev/dsp device through ossaudiodev.
It almost works, and is probably good enough for most purposes. But there are two things I'm not happy about. First is that there are occasional stutters. When I first start the thread it hesitates a couple of times. It then stutters every few seconds. The second issue is that there is about a one second delay from sending the packet to the audio being output. If I flush the buffer after sending each packet, there is a pause of about a second after each packet.
It's obviously going to be a bit tight trying to regularly output 320 samples in 1/25th of a second at 8000 samples per second, so I'm prepared to compromise and shorten the last bit of the end of packet marker, leaving just 319 samples. But the Pi seems determined to buffer its audio driver. Anyone know how to send an audio stream without buffering? Or to shorten the buffer to 319 bytes?