Go Down

Topic: Theremin--how to make stepped ranges for audioplay? (Read 155 times) previous topic - next topic

pollyy

Hi there folks maybe someone could give me some direction.

I am working on a sound installation and this is my second time using Arduino so please forgive my ignorance. But as many of my maker friends have advised, making the project you want to do is the best way to learn.  :D

Project Description: an antenna in the center of a room (possibly mounted on a sculpture, later) that acts as a theremin (without volume control) in the sense that the oscillator gives a frequency input, which can later be turned into a digital output in the form of audio. Here is the base code I used. When a person walks into the room and gets closer to the antenna, depending on the frequency that is received, different audio recordings will play in relation to the body in space. I know this will not be exactly how the antenna works, since other "hot" objects like phones/laptops can also translate into changes in frequency, but I'm ok with that.

I've built the theremin as per the instructions and now I have a few questions of how to proceed. For better audio quality and more processing possibilities I decided to output the serial monitor values received from my Arduino antenna into Raspberry Pi. I imagine that I will have to translate these frequency values into some kind of stepped range, i.e. value range from 60293-63059 will play 1st recording, person moves closer and value range changes, 2nd or 3rd recording will play.

I'm new to coding as well so perhaps someone can give me a hint on how to proceed, and also what other problems I might run into hardware or software-wise.

Also: how can I expand the distance of the range of the antenna? Is it simply a matter of having a larger antenna?  :smiley-red: Sorry if these are super newbie questions!

Many thanks!


Johan_Ha

So your Arduino reads the antenna and you get numeral data out of it? What are the recordings you mention? mp3 files? A complete tune that starts and plays through when its triggered by a certain frequency? Or will it stop and switch to another tune in the middle of playback?

I've created a "Theremin" with two light resistors. To get nice sound of it, I translated the hand gesture values to midi data, which I sent to my synth. Instead of just any note in a half step scale, it played a pentatonic scale. The number data I got from the analog input from the LDR I mapped to something 20 to 35. Then I multiplied by 12 and divided by 5 to get a pentatonic scale around middle C.
____________________
- One day my stepper motor driver works like a charm. No task is too big for it and I can do anything with it. Next day it refuses to work and even the tiniest motor blows its fuse. What's wrong with it?
- It's bipolar.

pollyy

So your Arduino reads the antenna and you get numeral data out of it? What are the recordings you mention? mp3 files? A complete tune that starts and plays through when its triggered by a certain frequency? Or will it stop and switch to another tune in the middle of playback?
Yes, it shows up as numeric data constantly running through serial monitor. The recordings will be mp3 files, but not single notes or tunes as you put it--rather recordings and a collage of sounds I've put together. I'm not really interested in making the theremin work as a typical instrument (I already have one for that purpose!).

And yes, to clarify I'd like different recordings to play when triggered by different frequencies. I'm just wondering how to begin to separate the total range values received by the antenna in order to assign one range to one recording, another range to the next etc. So one recording should stop abruptly in the middle of where it's playing once the frequency received by the antenna gets into a new range of values, and the next assigned recording will start playing. Also, it would be interesting if somehow you could 'pause' where these recordings are stopped, and if the frequency range is triggered again then the recording will start from where it left off.

If you have any advice on how I can begin to write the code or what syntax I can start with that would be great! Thanks!

wvmarle

Easiest would be to have an mp3 shield or so - upload your mp3 files to it, and the Arduino can tell the mp3 shield which one to play.

Then for your sound range, that can be done in two ways. If you have an analog range of 0-1023 (from the 10-bit ADC), and you have say 10 sound snippets, simply do:
Code: [Select]
String songList[10] = {"song1", "song2", ..., "song10"};
uint8_t songToPlay = map(thereminSignal, 0, 1023, 1, 10);
playSong(songList[songToPlay]);

If not linear, you'll have to use a series of if/else statements:
Code: [Select]
if (thereminSignal >= 0 && thereminSignal < 100)
  playSong(songList[0];
else if (thereminSignal >= 100 && thereminSignal < 150)
  playSong(songList[1]);
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.

Johan_Ha

You don't want to stop one playback and start another as soon as the frequency changes from one band to another - and back again. Your signal from the antenna/sensor/whatever might oscillate at two values right at the range border.

When one mp3 is playing and it's attached to a frequency band defined by say hi_freq and lo_freq and you poll the thereminSignal to check whether your mp3 should still be playing, you do...
Code: [Select]

    if (thereminSignal < lo_freq - threshold || thereminSignal > hi_freq + threshold)
    {
        // switch to another mp3 and another frequency band

So if you playback your first mp3 and the border is at 120, your theremin signal must raise to say 125, before your second mp3 starts playing. Then again, when the signal goes down, it has to go below 115, before the first mp3 takes over again.
____________________
- One day my stepper motor driver works like a charm. No task is too big for it and I can do anything with it. Next day it refuses to work and even the tiniest motor blows its fuse. What's wrong with it?
- It's bipolar.

wvmarle

Another way to achieve this, would be to check the values and change sounds only every now and then, like every 1-3 seconds.
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.

Go Up