marvin2k
marvin2k

Reputation: 1653

Howto pipe raw PCM-Data from /dev/ttyUSB0 to soundcard?

I'm working currently on a small microhpone, connected to PC via an FPGA. The FPGA spits a raw datastream via UART/USB into my computer. I'm able to record, play and analyze the data.

But I can't play the "live" audiostream directly.

What works is saving the datastream in PCM raw-format with a custom made C-program, and piping the content of the file into aplay. But that adds a 10sec lag into the datastream... Not so nice for demoing or testing.

tail -f snd.raw | aplay -t raw -f S16_LE -r 9000

Does someone have another idea, how get the audiostream faster into my ears? Why does

cat /dev/ttyUSB0 | aplay

not work? (nothing happens)

Thanks so far
marvin

Upvotes: 3

Views: 2894

Answers (2)

user7624508
user7624508

Reputation:

That would seem to be the domain of the alsaloop program. However, this program requires two ALSA devices to work with and you can see from its options that it goes to considerable effort in order to match the data flow of the devices, something that you would not necessarily want to do yourself.

This Stackoverflow topic talks about how to create a virtual userspace device available to ALSA: maybe that is a route worth pursuing.

Upvotes: 1

AShelly
AShelly

Reputation: 35540

You need an api that lets you stream audiobuffers directly to the soundcard. I haven't done it on Linux, but I've used FMOD for this purpose. You might find another API in this question. SDL seems popular.

The general idea is that you set up a streaming buffer, then your c program stuffs the incoming bytes into an array. The size is chosen to balance lag with jitter in the incoming stream. When the array is full, you pass it to the API, and start filling another one while the first plays.

Upvotes: 1

Related Questions