Go Down

Topic: How to play audio while doing other processing (Read 447 times) previous topic - next topic

mackerel

Does anyone have a good suggestion on this?  I need to play samples of 1-2 seconds duration but also receive and process data from the ADC at the same time.  I think it should be technically possible but have not seen a clear route.  I am not tied to any particular processor at the moment.  I have been thinking of using the Arduino mkr zero and ArduinoSound WavePlayback for this, but am open to all suggestions!

Thanks!

Geek Emeritus

the YX-5300 module plays sound from an on board TF card. you send a command, it plays and stops on its own without further interaction with the Arduino. just a serial trigger and move on to the next thing
All PMs will be deleted unopened due to arrogant argumentative pot stirring Malfoys.
 If you have not read "How to use this forum - please read", in particular: "7. If you are posting code or error messages, use "code" tags":  expect rude responses

DVDdoug

I don't know exactly how to do it and I've never used the Zero but it might be possible depending on how much "processing" you're doing.

Conceptually....   You just need an interrupt timer to read the ADC and write the DAC at the desired sample rate.   If the ADC & DAC sample rates are the same you can use the same interrupt.

Then of course, your processing has to be fast-enough to keep-up with the sample rate.    And, you're probably going to use the same interrupt timing.

Grumpy_Mike

#3
Mar 27, 2019, 08:53 am Last Edit: Mar 27, 2019, 09:12 am by Grumpy_Mike
You have to play back the sound asynchronously. Most sound libraries worth there salt will offer this option.

I did this with the following project http://youtu.be/pL0pMAPkkVw
The waveform was set playing asynchronously and then the code monitored the audio through a peak detector circuit and changed the mouth part of the face so that as the sound got louder the mouth got bigger. I was using the Adafruit wav shield circuit to produce the sound so samples were fetched on a timed interrupt routine.

mackerel

Thanks all - I'm keen to just use one arduino rather than trigger to a second.  An asynch option from a sound library is definitely what they need - I haven't yet found one of these?  Can you point me to what you used?
Thanks!

Grumpy_Mike

Quote
An asynch option from a sound library is definitely what they need - I haven't yet found one of these?
https://github.com/TMRh20/TMRpcm

From the heading:-
Quote
Arduino library for asynchronous playback of PCM/WAV files direct from SD card.

mackerel

Thanks Mike - I'm not sure this will be good enough for me as I need a fair amount of compute power left over - I think a 32bit ARM based arduino will be needed - I don't think the 328 series has very much CPU power?

Grumpy_Mike

Yes but you can implement the same thing as that library does on any processor and you will have more cycles in between what it has to do.

mackerel

Well that would be great - but in the wiki it only says 328 boards supported?  Will it definitely run on a zero?

Grumpy_Mike

No that is not what I said. Please read my last post again.

mackerel

Ah -so you are saying I could write the equivalent function targeting a zero?  Not that the code in the link would run on a zero?  Doesn't sound like that's getting me closer then  :(

Grumpy_Mike

Quote
Doesn't sound like that's getting me closer then  :(
Why is that then? Is it your lack of programming skills?

mackerel


Go Up