Shop OBEX P1 Docs P2 Docs Learn Events
Reading servo data from a wav file and audio — Parallax Forums

Reading servo data from a wav file and audio

Looking for some help on a project. I wanted to use an Arduino but I do not think it would be able to do all the things at once. So I bought a Propeller activity board.
I want to Read interleaved data on a SD card, I guess it could be interleaved or a 32 bit word spited into Servo data and wav data, or stereo with the right channel sent to the DAC for the audio and the left channel processed and sent to the servos.

Has this already been done? I have looked but I have not found and code that will do what I want. I have used the propeller a long time ago but that was with spin code and Objs. I would like to do it in the simple IDE, because I know a little bit programming in C++. But if there is something already in spin I would use that.
Thanks for any help.


  • You can get reasonable audio at 22kHz but this is far faster than the 20ms refresh timing of standard servos., so you file would become larger than needed to accommodate both features. It also takes a lot of code to play audio from a Propeller (I know, because I helped create two WAV players for EFX-TEK).

    I would suggest you use a low-cost audio player that the Propeller can control with a serial command, and then read your servo data from the SD on the PAB. The file driver that most use on the P1, FSRW, can only open one file at a time.

    A really good friend of mine, Peter (who works for Disney Imagineering) has amazing things with servo animatronics -- he used to, anyway, before his life go very busy.

    Peter plays audio from his PC while that PC streams position data to the servos (he hand-coded his own animation system). He even wrote a little editor to create servo position in sync with the audio. It turns out animating speech is not difficult: he opens the mouth at the beginning of each syllable, allows it to close at some speed (he experimented). Sometimes the next syllable starts before the mouth is full closed, and this process results in very natural "speech" from a skeleton.

  • Wuerfel_21Wuerfel_21 Posts: 4,448
    edited 2023-03-04 21:30

    @JonnyMac said:
    It also takes a lot of code to play audio from a Propeller (I know, because I helped create two WAV players for EFX-TEK).

    Not sure what you're on about, a very basic raw audio player is less than 150 LoC. Though I guess you are right in that the FAT library eats some good chunk of the memory.

    You really just need to copy data into the counter registers at uniform intervals. That's all there is to audio playback. Embedding data into the stream at some point(s) is trivial.

    Infact, I've literally done this sort of embed-control-data-in-audio thing, except instead of controlling a servo, I'm controlling the screen scaling factor in this silly game I wrote (note how everything bobs to the beat of the music?)

    In that particular application, the control data isn't separated from the audio stream at all, it simply uses the first byte of each 256 byte block (LSB of the left sample). This introduces some (basically inaudible) distortion to the music, but it was simple to implement. I could have just as well made it skip those bytes entirely, not sure what I was thinking.

    The sound code used in that is somewhere in here, but be warned that it is very optimized, obtuse and hard to use and you probably don't want it:

    You can probably get away with some pretty basic code. Create a buffer (ideally twice the size of an SD sector...). Use two cogs. One reads from the buffer into its DAC registers with appropriate timing and the other refills the buffer. Really simple.

  • Thanks for your replys. I am now thinking of using an STM blue pill, the AVR running at 16 Mhz can play wav files from an SD card. So I think an STM running at 75 Mhz should be able to play both the wav file and also control the servos? If I can get this to work I could have as many audio channel as I want all synced to a start trigger.

Sign In or Register to comment.