Go Down

Topic: Haptic Feedback with Arduino Uno using Audio (Read 299 times) previous topic - next topic

NewbieFury

Hello everyone,

I'm new in here, respects and loves to all members first. I just started doing a project using an Arduino Uno, which is basically taking the audio from pc and generating vibrations from the current sounds direction to the vest. For example when you are gaming, if someone shoots you from back left, your back left vibration motor on the vest simply vibrates so that there will be another dimension for the VR. Just by itself, connecting an audio signal is a little complicated work (as I read from this forum) how can I achieve something which is taking audio signal and detecting the direction of it. Will be very appricated if someone can help me.

Thanks

Coding Badly


wvmarle

how can I achieve something which is taking audio signal and detecting the direction of it.
Wouldn't know how, but quite sure it's not a job for an Arduino. You'll more need something like an RPi, plus a bunch of directional microphones (the number depending on in how many dimensions you want to detect the sound source), plus some powerful sound analyses software to filter the sound you're interested in from the background and then determine where it comes from.

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Grumpy_Mike

Quote
For example when you are gaming, if someone shoots you from back left, your back left vibration motor on the vest simply vibrates so that there will be another dimension for the VR.
How does the sound come from a direction? If it is a stereo audio source it is your brain that makes it think of the direction, not the actual sound itself.

NewbieFury

How does the sound come from a direction? If it is a stereo audio source it is your brain that makes it think of the direction, not the actual sound itself.
Most games actually are using 5.1 or 7.1 surround audio. So there are directions in audio.

NewbieFury

Wouldn't know how, but quite sure it's not a job for an Arduino. You'll more need something like an RPi, plus a bunch of directional microphones (the number depending on in how many dimensions you want to detect the sound source), plus some powerful sound analyses software to filter the sound you're interested in from the background and then determine where it comes from.


I think I don't need microphones. There's a product in the market called 'KOR-FX', which is basically the same thing that I want to do. And I guess there are no mics on it. An audio card probably. I was thinking that if I have an audio card which has more than 4 outputs (for surround sound) I can connect 4 of them (front left, front right, back left, back right) to Arduino as analog inputs, then according to the volume of them I can write an algoryhtm.

wvmarle

If you just want volume, you have to use some kind of envelope filter,.

Note that the Arduino's ADC has a sampling rate of just under 10 ksps, and that is for all channels (there's just one ADC), so four inputs give you just 2.5 ksps sampling rate. That's enough for envelope detection, far too low for actual digitisation.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

NewbieFury

If you just want volume, you have to use some kind of envelope filter,.

Note that the Arduino's ADC has a sampling rate of just under 10 ksps, and that is for all channels (there's just one ADC), so four inputs give you just 2.5 ksps sampling rate. That's enough for envelope detection, far too low for actual digitisation.
So are you saying that it can be done ? I mean I still have no idea how to create "direction effect" on sound to Arduino. I just thought that sound card idea, it has no solid background. Maybe you guys know/think another way to do it. It's very crucial to me.
Thanks again everyone who contributes

wvmarle

You can filter an audio signal to create an envelope signal. That gives you the volume of a channel. This is done in hardware, and pretty easy.

A harder part is measuring it of all four channels; where by nature of the ADC readings of the channels are taken at a 110µs interval. That may or may not be a problem for your sound.

Then you have to filter the sounds you want to react upon (of course the volume will be changing all the time). This is the very hard part, also as you can't store much data in the little memory of an Arduino, and possibly why you should really be looking at something more powerful like an RPi. Well, maybe a Teensy can do as well, also has quite some horsepower and memory available.

When you have processed the sound and determined the direction it comes from and which motor to operate, that part again is simple.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Grumpy_Mike

#9
Jul 30, 2019, 03:43 pm Last Edit: Jul 30, 2019, 03:44 pm by Grumpy_Mike
You have several problems in making this work. Identifying a shot sound from all the other sorts of sound is going to be a big problem. Like running noise, heavy breathing and the game music. Then if you use microphones then there is also the problems of external noises like a door slam being picked up.

My advice would be to connect the Arduino directly to the 5 speaker outputs of a 5.1 surround system. That removes any interference from room noise. It also might make things simpler in ignoring unwanted noise from the game. For example if you are getting sound from all five speakers then it might be that this is the game music, where as just one making a sound might indicate a simple shot.

Another trouble in using just two microphones is the 180o ambiguity you get with the maths.

One way round this might be to use The Matrix board:- https://www.hackster.io/matrix-labs/direction-of-arrival-for-matrix-voice-creator-using-odas-b7a15b

NewbieFury

  Hello everyone, I've finally decided to do it only for stereo (left and right). So I have a question for you programmer guys. Again, I am on starter level on programming Arduino. Can anyone help me with the codes? I basically describe what I need and what I have.

  So I have 2 audio signals as analog input (1 for right audio 1 for left and assume  that its enveloped and between 0-5 V). And I have 2 vibration motors as output.
  What I need is, when the signals are below X hz (depending on whether its right or left), the vibration motors operate. (X is the threshold value of bass frequencies, and I'm gonna check and find it later on.)

Thank you for your attention guys, waiting for your feedbacks!

PieterP

The easiest thing would be a digital low-pass filter. But implementation might be tricky.
You'll need a decent analog anti-aliasing filter as well, because the Arduino is slow.

Since you only want an estimate of the bass frequencies, a couple of EMAs might be enough, with a peak detector on the output.
Here's a fast EMA implementation:
https://tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Digital-filters/Exponential%20Moving%20Average/C++Implementation.html
It's just a couple of load and store instructions, one 16-bit addition, one 8-bit addition, one 16-bit subtraction, and K shifts. (If you're using 10 ADC bits and K < 7.)

uint_t must be at least ADC bits - K bits wide.
Here's a formula for the cut-off frequency: https://tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Digital-filters/Exponential%20Moving%20Average/Exponential-Moving-Average.html#cutoff-frequency   (α = 2-K)
But you have to know the sample frequency, and you have to take it with a grain of salt, because the roll-off is pretty bad.

Don't use the analogRead function, because it's very slow. Instead, start a new conversion before filtering, so the measurement happens during the calculation and you don't waste time.
If your anti-aliasing filter is bad, you might want to change the ADC prescaler and use only 8 ADC bits. The ATmega328P's datasheet has all the necessary details. That only helps if your filtering and processing can keep up, of course.

Pieter

wvmarle

I am on starter level on programming Arduino.
Then you'd better go and find some starter level programming tasks, as this definitely is in the advanced part. Help with the code is a tall order: you can try and put your hardware together, make sure it works, then send it off to someone who can do the programming. That's not going to be cheap, for this kind of jobs.

#11 describes quite nicely what you're up against. I hope you have at least sufficient understanding of sound analyses to understand what is written there...

Don't use the analogRead function, because it's very slow. Instead, start a new conversion before filtering, so the measurement happens during the calculation and you don't waste time.
Maybe even better: ADC in free running mode, with interrupt upon completion of a conversion. If speeding up the conversion from the default of just under 10 kHz make sure your calculations are fast enough to keep up, so finished before the next value comes in! After all an Arduino runs at just 16 MHz. Particularly if doing this on two channels, so twice the work for peak detection + direction calculation.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

NewbieFury

Hello everyone,

 Can I basically implement a first order low pass filter algorythm after enveloping the audio signal with a simple circuit (two 100k ohm resistors and one 10uF capacitor). So with these, I'll have enveloped signal to lowpass filter, and then if the signal is below the threshold, simply run the motors. Is there some one give me the codes or lead me to some one who can write it ? I have now very limited amount of time. I've gathered all the stuff needed for it. I just need the freakin' codes... I really do.

Thanks again for your feedback guys.

Grumpy_Mike

#14
Aug 19, 2019, 09:32 am Last Edit: Aug 19, 2019, 09:34 am by Grumpy_Mike
Quote
Can I basically implement a first order low pass filter algorythm after enveloping the audio signal with a simple circuit (two 100k ohm resistors and one 10uF capacitor)
Yes, but you only need one resistor. But the envelope detector is in itself a low pass filter and you can change the cut off frequency by changing the values of the resistor and capacitor.

If you want someone to write code for you then post in the gigs and collaboration section and say how much you are willing to pay.

But from what you have said previously you can't use an envelope detector if you want to be able to measure frequency.

Go Up