Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 17 of 17

Thread: The sound of a motor humming on a teensy 3.2

  1. #1

    The sound of a motor humming on a teensy 3.2

    Dear members of the forum,
    I just received my Teensy 3.2 with the audio shield. I soldered everything, and then did the first tests with the Arduino IDE samples. What a joy to see that everything works the first time. I already used Teensy and had some setbacks with the SPI while I started in microelectronics. But it was before.
    Here is my question: I registered the engine of my car with my phone. There are several files: the startup when I put the contact. An acceleration and several stable sounds at different speeds.
    I would like to create a program that mimics the sound of an engine. I want to limit the number of files to use. Except when I turn on and I turn off the engine, I want to use the same sound file.
    For this I am willing to use digital filters, but my knowledge in this area is very limited. Could you point me?

    Here's what I noticed, accelerating the engine runs faster and pulls the treble.
    Optional: the engine hums sometimes, a little as if at low frequencies it iscillate slightly.

    Best regards,
    Sylvain.

    P.S. If my project materializes, would it be possible to make it appear on the blog? With photos and videos to support.

  2. #2
    While doing research, I realized that an engine was not only a sound but a set of distinct sounds as clutches, valves ... and for the V8, it emits a very special explosion sound. Would you know where I can find this type of sound? It will be easier for me to assemble them with the Teensy. If you also had paper documentation on the topic could you communicate them to me?

  3. #3
    Ok Beware the dog I understand the way it mean, lot of sound.wav or Sd??

    I ve put the wav file into my sd card, if I change the format into *.mp3, do I have the same results? then i may ask if those libs are similare?

  4. #4
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,759
    Using MP3s is probably not a good idea trying to mix a lot of samples together. Wav files have no compression so they are easier to unpack and stream from the SD card and the total amount of audio here is pretty small. In fact for this you may find converting some of your engine effects to raw and storing them in your program gets the lowest latency with trying to mix the various bits and bobs together. Have not seen a really good solution to what you are trying to do, since ideally you would be tampering with the replay rate and that is not something supported out of the box on Teensy Audio library. So you would be trying to extract the various effects and then firing them off at your engine RPM + mixing in the background mechanical noises on longer loops. You may find using a desktop sound engine may make this sort of thing easier to get your head around and make sure your samples actually mix the way you want.

    I have used supercollider https://supercollider.github.io/ but it is massivly overkill for what you want and has a vertiginous learning curve. I was actually looking at a similar task and worked from https://en.wikibooks.org/wiki/Design...rCollider/Cars to synthetically make an gunfire effect, fully building all the elements. Which was fun but the end result was not actually that good so if lining clips up does what you want it will get you there a lot faster than the synth way.

  5. #5
    Hello,
    I can't find the function that accelerates the playback speed of a WAV sound. Could someone help me please ?

  6. #6
    I am in the process to emulate engine sounds by modelling the mechanics of the metal and the environment. This most probably will nothing a small micro processor can synthesize in real time, but i cann give you some hints:

    - use a dirac impulse shaped with eqs to model the explosions
    - superimpose several explosions to shape the real explosion's waves
    - add reflections caused by the small room in an engine's parts using a 3D model and reflection zones
    - starting from any reflection zone (wall of an engine's part) progress the waves taking the sound speed in metal into account
    - add reflections and the end points of all joints, cranks and enclosure parts
    - then it comes to damping and EQ-ing to model the losses in the materials and the air.

  7. #7
    Hello
    Thanks for your reply, nevertheless I am a little lost by the techniques you use. In the first step you talk about Dirac and equations which I have no idea of their content.
    The second step is okay, I could create a random way to start the sound with defined statistical characteristic, it takes a little work but it is possible.
    Then, I'm not sure I understood, the engine being in a reduced space you talk about reflections, then I propose to use the reverberation to have a more realistic rendering?
    Fourth point: I have done pretty well by breaking down a short extract of engine sound with three filters, pass low, pass band, and pass high, and superimposing them. So I happen to have a sound rather good.
    Fifth point, I do not know, I could understand better with readings.

    I would like to try tomorrow to play with the sample rate of a sample in order to vary the speed of the engine. I do not think it will work but I have no other leads at the moment. If you could help me, I tell you what I have to realize:
    For now, simulate a single gear with a potentiometer for the throttle. A teensy, a speaker.

  8. #8
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,759
    What Audioengineer is doing is similar to the supercollider link above, producing a burst of noise, filtering it to match an explosive pulse and then adding reverb and mechanical effects.

    To achieve a gunfire effect in the teensyaudio system I have used a white noise generator low pass filtered and with the gain sharply ramped up and down to produce the base burst, then added reverb. To this I added a pair of https://www.pjrc.com/teensy/gui/?inf...ynthSimpleDrum sythdrum triggers adjusted for a 'ting' sound for the mechanical motion effects. I played around with other effects on the result but generally just made the sound 'flatter'.

    So if you want a not very pretty but infinitly adjustable 'bang bang bang' engine noise ASAP my thought would be to grab the white noise source, work out your virtual RPM and write some code to ramp the noise generator amplitude in bursts coming at your virtual RPM.

    If you have time you then put a bandpass filter in front to get things more engine like, and with more time change the filter values across X different presets where X is your cylinder number. Sticking some other mechanical noises from strings or drums in there will add some colour and a modulated low rumble would round it out.

    The difficulty with this approach is that I do not think a teensy has the capability to produce a truly realistic engine effect from this mechanism since it needs tuned echos as described by audioengineer that if done from first principles would need more processing than a Teensy has.

    What this may give you is good enough soon enough.

  9. #9
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,759
    Dusted off some assorted code fragments and and evening's work got this
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioSynthNoiseWhite     noise1;         //xy=127,377
    AudioSynthToneSweep      tonesweep1;     //xy=170,246
    AudioSynthKarplusStrong  string1;        //xy=182,205
    AudioSynthKarplusStrong  string2;        //xy=192,286
    AudioSynthSimpleDrum     drum1;          //xy=196,173
    AudioFilterBiquad        biquad1;        //xy=297,407
    AudioMixer4              mixer1;         //xy=470,258
    AudioMixer4              mixer2;         //xy=567,373
    AudioOutputI2S           i2s1;           //xy=780,354
    AudioOutputAnalog        dac1;           //xy=819,179
    AudioConnection          patchCord1(noise1, 0, mixer2, 1);
    AudioConnection          patchCord2(noise1, biquad1);
    AudioConnection          patchCord3(tonesweep1, 0, mixer1, 2);
    AudioConnection          patchCord4(string1, 0, mixer1, 1);
    AudioConnection          patchCord5(string2, 0, mixer1, 3);
    AudioConnection          patchCord6(drum1, 0, mixer1, 0);
    AudioConnection          patchCord7(biquad1, 0, mixer2, 2);
    AudioConnection          patchCord8(mixer1, 0, mixer2, 0);
    AudioConnection          patchCord9(mixer2, dac1);
    AudioConnection          patchCord10(mixer2, 0, i2s1, 0);
    AudioConnection          patchCord11(mixer2, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=504,604
    // GUItool: end automatically generated code
    
    // GUItool: end automatically generated code
    
    uint32_t cylinder=0;
    uint32_t stage=0;
    uint32_t cylinderfreq[]= {60,63,58,64,59,60,58,61,62};
    elapsedMillis sinceBang;
    elapsedMillis sinceStatus;
    byte bangStage =0;
    uint32_t bangPeriodMilliseconds = 500;
    void setup() {
      // put your setup code here, to run once:
    
      Serial.begin(115200);
    
      // audio library init
      AudioMemory(15);
    
     
    
      AudioNoInterrupts();
    
      drum1.frequency(60);
      drum1.length(1500);
      drum1.secondMix(0.0);
      drum1.pitchMod(0.55);
      mixer2.gain(1,0);
     //  mixer2.gain(1,0);
      biquad1.setLowpass(0,400,0.8);
      
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.6);
    
      AudioInterrupts();
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
      //these numbers would be better being adjusted as RPM increases
      if (bangStage==1) if (sinceBang>50){noise1.amplitude(0.1); bangStage=2; }
      if (bangStage==2) if (sinceBang>100){noise1.amplitude(0.5); bangStage=3; }
      if (bangStage==3) if (sinceBang>50){noise1.amplitude(0.000); bangStage=0; }
     
      if(sinceBang>bangPeriodMilliseconds)    
      {
        sinceBang=0;
        bangStage=1;
        cylinder++;
        if (cylinder>7) cylinder=0;
        drum1.frequency(cylinderfreq[cylinder]);
          drum1.length(bangPeriodMilliseconds);
        drum1.noteOn();
        noise1.amplitude(0.05);
        stage++;
    
        //add your own RPM process here
        if (stage>100) stage=0;
        if (stage<50)bangPeriodMilliseconds=300-stage*4;
        else bangPeriodMilliseconds=300-(100-stage)*4;
        //End of cut for RPM code
    
     
      }
      if (sinceStatus>5000){
        Serial.print("Diagnostics: ");
        Serial.print(AudioProcessorUsageMax());
        Serial.print(" ");
        Serial.println(AudioMemoryUsageMax());
        AudioProcessorUsageMaxReset();
      }
    }
    Should be outputting both to audio shield headset and the teensy DAC. Several things wrong with it, including several unused instruments and realism close to zero but does function. I think next step is to double up the drums, possibly to one per cylinder so they have more time between beats and simplify pitch shifting them.

  10. #10
    Okay, I can see more clearly. I'm doing tests today. I'll send you a code tonight.
    And thanks to you GreemlinWrangler for your code, i'll try it now

  11. #11
    That's pretty good, freverbs add some realistic to the sound, i keep trying with différents parameters. when the code is okay i'll publish it

  12. #12
    Hello
    Here's the GremlinWrangler program test. I changed some settings and I find the result very good. Now, to improve this code, I will add a more explosive "bang", simulating the explosion of gasoline in the engine, I would like to filter the sound of the engine again to get a more metallic rendering.
    If you have some other tricks, please send them to me


    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    
    
    // GUItool: begin automatically generated code
    AudioSynthNoiseWhite     noise1;         //xy=127,377
    AudioSynthSimpleDrum     drum1;          //xy=196,173
    AudioFilterBiquad        biquad1;        //xy=297,407
    AudioMixer4              mixer1;         //xy=470,258
    AudioMixer4              mixer2;         //xy=567,373
    AudioOutputI2S           i2s1;           //xy=780,354
    AudioEffectFreeverb      freeverb1;
    AudioConnection          patchCord1(noise1, 0, mixer2, 1);
    AudioConnection          patchCord2(noise1, biquad1);
    AudioConnection          patchCord6(freeverb1, 0, mixer1, 0);
    AudioConnection          patchCord7(biquad1, 0, mixer2, 2);
    AudioConnection          patchCord8(mixer1, 0, mixer2, 0);
    AudioConnection          patchCord9(drum1,freeverb1 );
    AudioConnection          patchCord10(mixer2, 0, i2s1, 0);
    AudioConnection          patchCord11(mixer2, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=504,604
    // GUItool: end automatically generated code
    
    // GUItool: end automatically generated code
    
    uint32_t cylinder=0;
    uint32_t cylinderfreq[]= {60,63,58,80,59,60,50,61,62};
    elapsedMillis sinceBang;
    elapsedMillis sinceStatus;
    byte bangStage =0;
    uint32_t bangPeriodMilliseconds = 500;
    void setup() {
      // put your setup code here, to run once:
    
      Serial.begin(115200);
    
      // audio library init
      AudioMemory(15);
    
     
    
      AudioNoInterrupts();
    
      drum1.frequency(60);
      drum1.length(1500);
      drum1.secondMix(0.0);
      drum1.pitchMod(0.55);
      mixer2.gain(1,0);
      biquad1.setLowpass(0,1200,0.8);
      
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.6);
    
      AudioInterrupts();
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
          freeverb1.roomsize(0.4);
          freeverb1.damping(4);
          
      //these numbers would be better being adjusted as RPM increases
      if (bangStage==1) if (sinceBang>50){noise1.amplitude(0.08); bangStage=2; }
      if (bangStage==2) if (sinceBang>100){noise1.amplitude(0.5); bangStage=3; }
      if (bangStage==3) if (sinceBang>50){noise1.amplitude(0.000); bangStage=0; }
     
      if(sinceBang>bangPeriodMilliseconds)    
      {
        sinceBang=0;
        bangStage=1;
        cylinder++;
        if (cylinder>7) cylinder=0;
        drum1.frequency(cylinderfreq[cylinder]+20);
          drum1.length(bangPeriodMilliseconds);
        drum1.noteOn();
        noise1.amplitude(0.05);
       
    
        //add your own RPM process here
      
        bangPeriodMilliseconds=70;
       // 
     
      }
      if (sinceStatus>5000){
        Serial.print("Diagnostics: ");
        Serial.print(AudioProcessorUsageMax());
        Serial.print(" ");
        Serial.println(AudioMemoryUsageMax());
        AudioProcessorUsageMaxReset();
      }
    }
    Thank you for your help

  13. #13
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,759
    Well one thing to look at is my code has an error at
    if (bangStage==3) if (sinceBang>50){noise1.amplitude(0.000); bangStage=0; }

    That would probably work better if it was

    if (bangStage==3) if (sinceBang>150){noise1.amplitude(0.000); bangStage=0; }
    Otherwise it fires oce cycle after sinceBang==100

  14. #14
    I found accidentally a method to simulate the sound of the engine start-up.

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    int R=0;
    long t0=0;
    // GUItool: begin automatically generated code
    AudioSynthNoiseWhite     noise2;         //xy=352,1067
    AudioSynthWaveform waveform;   //xy=353,1136
    AudioFilterBiquad        biquad2;        //xy=633,1052
    AudioEffectMultiply      multiply1;      //xy=869,1093
    AudioEffectFreeverb      freeverb1;
    AudioEffectDigitalCombine combine1;
    AudioOutputI2S           i2s2;           //xy=1076,1097
    AudioConnection          patchCord1(noise2, biquad2);
    AudioConnection          patchCord2(waveform, 0, multiply1, 1);
    AudioConnection          patchCord3(biquad2, 0, multiply1, 0);
    AudioConnection          patchCord4(multiply1, 0, freeverb1, 0);
    AudioConnection          patchCord5(freeverb1, 0, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=880,644
    // GUItool: end automatically generated code
    
    
    
    void setup() {
         Serial.begin(115200);
         // audio library init
         AudioMemory(15);
         AudioNoInterrupts();
         biquad2.setBandpass(0,1000,0.8);
         waveform.frequency(10);
         sgtl5000_1.enable();
         sgtl5000_1.volume(0.6);
         waveform.amplitude(1);
         AudioInterrupts();
         long t0=millis();
    }
    
    void loop() {
         if (millis()<t0+2500){
              freeverb1.roomsize(0.01);
              freeverb1.damping(10);
              noise2.amplitude(1);
              waveform.begin(WAVEFORM_PULSE);waveform.offset(-1);  waveform.pulseWidth(0.90);
       }
    
    else {noise2.amplitude(0);}
    
    }

  15. #15
    The following point is still a mystery for me:
    starting from any reflection zone (wall of an engine's part) progress the waves taking the sound speed in metal into account
    I understand the sentence but not how to achieve it, could explain me this further?

  16. #16
    maybe strings tool???

  17. #17
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,759
    Materials have different speed of sound values so a true engine model would be spreading the impulse noise spectrum from each cylinder fire similar to these things
    https://en.wikipedia.org/wiki/Surfac...ic_wave_sensor
    In teensy Audio terms this would be a chain of delay units with a narrow filter on each join in the chain and then the filter outputs mixed together. This would allow some parts of the spectrum to arrive sooner than others. This would be very processor intensive and might make sense in a simulated instrument but not seeing any particular parts of an engine note that would benefit from it.

    I suspect what we need now is something that simulates the whistle/whoosh noise from the exhaust air, which I think starts as a sine fm object but at the moment unclear on how to modulate that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •