Adding Audio Output Circuit
Hi,
I am looking for advice on the possibility to add a stereo audio output circuit to my Cyton. My goal is to play music once the brain has reached a certain frequency band. Will one of the unused pins be able to support such a circuit? According to the PIC32 datasheet, the component does have audio interface features. And I read a few posts about people using some of the aux channels as mic inputs, now I just want to check about adding outputs to the board.
Any advice will be appreciated. Thanks!
Comments
Generally it's not a great idea to add digital or analog outputs from an EEG device. Because the EEG signal is very weak, only a few tens of microvolts. Whereas digital or analog output signals are much much stronger in amplitude (voltage). So your output has the potential to feedback into the EEG input, via inductive or capacitive coupling.
Audio output from all modern computers (even single boards like Raspberry or Arduino) is very easy to do, and there is no coupling possible.
William
Thanks for replying, William.
I understand what you are saying. Thanks for the heads-up! Will it be possible then to alter the Arduino code of the Cyton by adding a parallel system where an ESP32 MCU is controlling the audio? The code will then be for instance:
if (channel data == wanted frequency band) {
ESP32 will activate the audio circuit and play the music
}
Hope that makes sense?
Elke
The signal processing operations, such as band powers, FFT, etc., are best done on the laptop which has better processing power to do the computation intensive operations. You can use the Brainflow library in the language of your choice.
https://brainflow.org/
https://brainflow.readthedocs.io/en/stable/Examples.html
Brainflow does not run on microcontrollers.
Thanks! I will have a look at those links but do you think it would be possible to incorporate the ESP32 to do the audio circuit part of my project? By that, I am meant to run the Cyton board and the ESP32 MCU from the same script?
Please read some of the Brainflow documentation. The Cyton firmware (PIC32) is not intended to do onboard signal processing (such as FFT, filtering, band powers, etc.), that should be done on the laptop instead. Then since the laptop already has audio output capability, it makes little sense to connect the ESP32 as you suggest for audio.
Hope this makes sense.
Yes, I understand that the processing part should be on the laptop.
I want the music to play wirelessly from my laptop to my earphones and that is why I want to make a subcircuit for the audio. If the EEG is in the desired frequency band then a 'trigger' will be sent to the ESP32 wirelessly indicating it should start streaming the music from (for example) an SD card. My idea is to use an audio breakout board with an SD card slot that is connected between my earphones and ESP32.
Hope this gives you a bit of a clearer picture of what I am trying to achieve? Sorry, I should have been clearer on what I was trying to achieve in my first post. Apologies if this post doesn't fall into the criteria of this discussion board. I was not sure if my question falls under this discussion board or the Build-it-yourself one.
The easiest and most straightforward way for audio to stream wirelessly from the laptop doing the signal processing, to your headphones, is via a set of Bluetooth headphones. Even single board computers such as Raspberry can do this.
I'm just trying to point out the 'easiest' way, involving fewest components and circuits.
Regards, William
Thanks! I was thinking about using an ESP32 wroom32 module to do the Bluetooth signaling for the audio. I want to use stereo audio for my earphones and play two different sounds from each earphone, but I think that can be easily set with a stereo audio breakout board.
Thanks for the advice! You helped save me from wasting time on something that might not work as efficiently as I wanted.
Kind regards,
Elke
As I understand this thread, I think it's best to connect the Cyton to a Laptop or Raspberry Pi, write software to achieve the result, and use standard wired or bluetooth headphones. Using a Raspberry Pi is slightly more complicated than a Laptop due to the type of processor and the steps required to run BrainFlow (software used to connect to board).
Hope this helps,
RW
Thanks for the advice RW!
The reason I am skeptical about using Bluetooth earphones (obviously it will be most ideal) is that I need two different sounds playing into each ear. That is why I am thinking of instead of using off-the-rack Bluetooth earphones, I will try and create Bluetooth earphones. Hence why I am talking about using the ESP32 to store the music internally and receiving the trigger signal from the laptop to start playing the music.
Hope this makes sense of why I am wanting to use the ESP32. I already have a spare module that is another reason why I am thinking of using it.
Regards,
Elke
re: are Bluetooth headphones stereo?
Yes, almost all the output only devices are stereo. On the other hand Bluetooth 'headsets' or combination mic + headphones / buds, are a different story. The issue is that it takes special wireless technology to simultaneously support two way audio: output to the ears and input from the mic. Some devices do support this simultaneity. Especially gamer equipment. See answers on this link,
https://superuser.com/questions/930251/possible-to-use-bluetooth-headset-in-stereo-mode-with-mic
If you only require sound output, then almost any Bluetooth headphone will be fine.
Thanks for the quick reply.
Yes, I do not want to use a mic in my project. So will it then be possible to write in the same code script the audio for the Bluetooth earphones and the processing of the EEG data of Brainflow? My knowledge is more C++ and Arduino coding and I see that Brainflow does supply C++ code.
Yes, that is easily done. It is also possible to use 'threads' in most programming languages, that allow parallel processing of multiple control loops.
https://www.google.com/search?q=threads+in+c+vs+c++
That is great! Thanks for the link and all the advice!
I will see what I can do. Threads will be possible to use without Linus right? I have windows, but I just want to double-check that it will be fine?
Kind regards
Elke
There is a left and right channel for all modern earphones/headphones. You would play two different samples/sounds/songs and then pan them to either the left or right channel. This is done in software.
Another way is to create sounds and then edit using a simple tool called "Audacity" to pan the sounds themselves beforehand. Then, when you play them back they will already be panned.
Yes, the threads library (called 'pthreads()' for C and C++) exists on all operating systems: Windows, Mac, Linux. Semantics should be very similar on all platforms, but check your OS documentation. Some OS's may have a wrapper over top of pthreads that they prefer you to use.
Also, as Richard points out, you may not need to use any parallel threads at all. I just mentioned pthreads, because many real-time interactive programs use multiple threads. For example a separate thread for managing the GUI, and another thread for driving a simulation / animation.
If you are using a 'C' like language with Windows, Windows has really excellent support for C#, the C variant that they invented and is usually the best C for Windows.
William
https://brainflow.readthedocs.io/en/stable/Examples.html#c
Thanks for all your comments! I already created my audio with Audacity and it worked well for what I was trying to achieve for my audio.
I will go through the link you posted William. What software program would you suggest working with when writing the script? Would Visual Studios be fine to work with or is there something better for Windows?
Elke
The free Visual Studio supports many languages including C#, C++, etc.
https://visualstudio.microsoft.com/free-developer-offers/
Thanks! I have already started with the brainflow installation on Visual Studio. I just installed the brainflow nuget package.
Would this threading be possible with python and micropython?
https://www.google.com/search?q=threading+in+python
Thanks for the link!
I am currently looking for a way to work with brainflow in python and then communicate with my ESP32 in Arduino. I saw that you can control an Arduino with python by using PySerial. Is this something you have worked with in the past? The ESP32 can be controlled by Micropython, but I am just checking for an alternative in case the threading does not work.