- Edited
Hi! I am trying to connect two belas so that a recorded sound starts playing in one of them and then continuous in the other one. I would appreciate any kind of help
Hi! I am trying to connect two belas so that a recorded sound starts playing in one of them and then continuous in the other one. I would appreciate any kind of help
Do you mean the same audio file is pre-loaded on two belas, and playback starts on one, which then triggers the other to start playing after some amount of time?
somedev Yes, something like that. I want the two belas to communicate between each other so that an audio file .wav starts playing in the first one and at some point pass the information of where the sound stopped playing on it to the other bela so it continues in the other. Not necessarily the audio file being preloaded in the second bela, it can be loaded from the first bela. I was thinking of using UART communication or some other protocol.
Thank you. Now that I understand you intend to have serial communication between belas, I may say that I am interested in what the recommended approach to this is as well.
From a conversation with @Anaaa080 on a different channel, I gather the following:
It's unclear to me:
In the case of using two Belas, if the file has a small number of tracks (up to six tracks, really, depending on how many unused I/O channels are available), and assuming that spare inputs are available, the easiest way to combine two Belas would be to play back the audio from the first into the second; the first acts on the audio it is playing back from disk and the second one acts on the audio it receives from the inputs. One or more control voltages could also be sent, either via the analog I/O or via the digital I/Os. This would allow to achieve the tightest synchronization between the two boards. If the synchronization can be a bit looser, i.e.: if it's OK to be out of sync of a few ms, then sure you can use UART or whatever other non sample-accurate method to synchronise.
However, I would first look at running this all on a single Bela if at all possible. The OP says that frequencies 1 to 100Hz are all that's needed and I'll assume that 16 bit depth is not necessary. One could leverage some soft PWM channels to achieve decent performance in that frequency range, using only a passive RC filter on each PWM output. The example Extras/pru_pwm makes available 8 PWM outputs with a frequency of about 24kHz and about 8 and a half bits of precision. The easiest way to control this with decent timing accuracy from the audio code is to write a new PWM value for each audio procesing block. At the default block size of 16 samples per block, that means you'll be writing your signal with a sampling rate of 44100Hz/16 = 2756Hz. You would then apply a low pass filter at about 1kHz or lower to each of your signals and write them once per block using set_widths(). On the analog side, a 2k2 resistor in series and a 470nF capacitor in parallel gives you a cutoff frequency of 153 Hz which may be good enough for your application. This cutoff attenuates the frequency of the PWM wave by 42dB, but as that's already likely beyond the passband of your power amplifer and your actuator, that should be good enough.
giuliomoro I was thinking about what you proposed and I think I will try to control the two belas independently to make programming easier. I want to be able to control my bela in a way that I know which audio track is playing thanks to a time control knowing the sample rate.
giuliomoro Also, i don´t completely understand what you have proposed. You think it would be posible to have 12 outputs from the same bela used at the same time for my actuators?
Anaaa080 control the two belas independently to make programming easier
I am not sure it is indeed "easier" when using two Belas. Their clocks will drift apart, so even if two events are synchronised upon start, anything that plays for more than a handful of seconds will start drifting by some milliseconds, so phase alignment can't be guaranteed. If the playback is several minutes, you'll start building up hundreds of milliseconds of misalignment between the two boards if they are not pulled back together every so often. From a back of the envelope calculation, given that the crystal may have up to ±50 ppm tolerance, you may have two units that are 100 ppm apart. Over one minute, that gives you a maximum theoretical drift of 60 * 100ppm = 60 * 0.000100 = 0.006 s = 6 ms.
Again, depending on your requirements of phase or temporal alignment and the duration of the playbacks you are triggering, it may work for you, but if you are planning on planning long audio files, you would definitely need some more clever synchronisation mechanism.
Anaaa080 Also, i don´t completely understand what you have proposed. You think it would be posible to have 12 outputs from the same bela used at the same time for my actuators?
Yes. As long as the frequencies you send to the actuators are low enough, you can generate those via PWM instead of the audio or analog DAC.