Python Forum

Full Version: Python Idea Assist.: BerryIMU & Raspberry Pi 3 Audio Mapping
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greetings!

I am a Multimedia Student who is working on a audio/motion sensor project. I managed to make the project work in Processing 3, but now I need to use python code, which I've only just acquainted myself with. In short, the project is this: Mount a BerryIMUv2 motion sensor to a Raspberry Pi 3 (already soldered and running perfectly). Mount this on top of a pair of headphones for a user to wear. The idea is to have the roll and pitch directional data from the sensor linked to the amplification of the audio files in real time so a user can navigate between them. I need to use python code, and I have also located an overwhelming amount of audio libraries for python.

Sudo Code:
If RPi3 is booted up, then run the python program and turn on Green LED and play all four Audio Files simultaneously
else turn on Red LED if program fails to run.
If user rolls their head Left, amplify Audio File #1 and decrease amplification of Audio File #2 (X)
If user rolls their head Right, amplify Audio File #2 and decrease amplification of Audio File #1 (X)
If user pitches their head Forward, amplify Audio File #3 and decrease amplification of Audio File #4 (Y)
If user pitches their head Backward, amplify Audio File #4 and decrease amplification of Audio File #3 (Y)

Now, I've managed to make this work partially in P3, and I have posted my code below (Only two files running in the sketch). I am using a mapping function and the music library for Processing. However, I need this exact process replicated, but for python, in a Thonny pde.

My questions then, for all and those more familiar to Python which I'm starting to love, (1) what recommendations would you make for choosing an audio library AND (2) where can I find an equivalent mapping function for Python?

Thank you! Smile

Processing Code:
import ddf.minim.*;

float vol=0;
float vol2=0;

Minim minim;

AudioPlayer player;
AudioPlayer player2;

void setup()
{
  size(512, 200, P3D);
  noStroke();

  // we pass this to Minim so that it can load files from the data directory
  minim = new Minim(this);

  // loadFile will look in all the same places as loadImage does.
  // this means you can find files that are in the data folder and the 
  // sketch folder. you can also pass an absolute path, or a URL.
  player = minim.loadFile("MyRecordingV1_02.mp3");
  player.loop();
  player.setGain(vol);

  player2 = minim.loadFile("MyRecordingV2_02.mp3");
  player2.loop();
  player2.setGain(vol2);

}

void draw()
{
  player.setGain(vol);
  player2.setGain(vol2);
  
  background(0);
  
  vol=map(mouseX, 0, 512, -50, 30);
  float c = map(mouseX, 0, width, 0, 175);
  vol2=map(mouseX, 0, 512, 30, -50);
  float d = map(mouseX, 0, width, 40, 300);
  fill(255, c, 0);
  ellipse(width/2, height/2, d, d);
  
  
  println(vol);
}

/*void mousePressed() {
  vol+=10;
} */