Python Forum
Python Idea Assist.: BerryIMU & Raspberry Pi 3 Audio Mapping
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Idea Assist.: BerryIMU & Raspberry Pi 3 Audio Mapping
#1
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;
} */
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error python audio codiac 3 4,170 Mar-30-2023, 03:12 PM
Last Post: deanhystad
  Mapping a value to an interval JazonKuer 12 2,008 Mar-17-2023, 07:59 PM
Last Post: Gribouillis
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,266 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,816 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  python audio analysis kiyoshi7 3 1,778 Feb-22-2022, 06:09 PM
Last Post: Axel_Erfurt
  Coding for Python and Raspberry pi beast 3 47,390 Sep-21-2021, 09:56 PM
Last Post: beast
  Mapping a range ebolisa 5 3,520 Jun-12-2021, 11:17 PM
Last Post: ebolisa
  python 3 raspberry pi 4 dual control motor programming problem yome 0 1,987 Mar-21-2021, 05:17 PM
Last Post: yome
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 3,998 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  Embedded python fails to compile on Raspberry Pi tryfon 2 3,489 Dec-22-2020, 02:06 PM
Last Post: tryfon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020