{"id":3133,"date":"2022-07-30T05:42:50","date_gmt":"2022-07-30T12:42:50","guid":{"rendered":"https:\/\/www.donluc.com\/?p=3133"},"modified":"2022-07-30T05:42:50","modified_gmt":"2022-07-30T12:42:50","slug":"project-22-synthesizer-volume-sound-mk07","status":"publish","type":"post","link":"https:\/\/www.donluc.com\/?p=3133","title":{"rendered":"Project #22: Synthesizer &#8211; Volume Sound &#8211; Mk07"},"content":{"rendered":"<div style=\"width: 720px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-3133-1\" width=\"720\" height=\"480\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04W.mp4?_=1\" \/><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04W.mp4\">https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04W.mp4<\/a><\/video><\/div>\n<p>&#8212;&#8212;<\/p>\n<p>DonLucElectronics #DonLuc #Synthesizer #UltrasonicSynth #Mozzi #Arduino #ArduinoProMini #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04a.png\" alt=\"Volume Sound\" width=\"720\" height=\"409\" class=\"alignnone size-full wp-image-3135\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04a.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04a-300x170.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04b.png\" alt=\"Volume Sound\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3136\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04b.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04b-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><a href=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04c.png\" alt=\"Volume Sound\" width=\"720\" height=\"480\" class=\"alignnone size-full wp-image-3137\" srcset=\"https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04c.png 720w, https:\/\/www.donluc.com\/wp-content\/uploads\/2022\/07\/DL2207Mk04c-300x200.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/a><\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>Volume Sound<\/strong><\/p>\n<p>Volume the degree of loudness or the intensity of a sound. The volume of a sound is how loud or quiet the sound is. Sounds are vibrations that travel through the air. Volume, or loudness, is related to the strength, intensity, pressure, or power of the sound. Amplified vibrations result in louder sounds. There are a few ways of varying the volume.<\/p>\n<p>I am using the Mozzi audio library to implement a simple synthesizer and using a potentiometer to control the amplitude of a sinewave with Mozzi sonification library. To convey the volume level. Volume it to an 8 bit range for efficient calculations.<\/p>\n<p><strong>DL2207Mk04<\/strong><\/p>\n<p>1 x Arduino Pro Mini 328 &#8211; 5V\/16MHz<br \/>\n2 x HC-SR04 Ultrasonic Sensor<br \/>\n3 x 1M Ohm Potentiometer<br \/>\n3 x Knob<br \/>\n1 x Audio Jack 3.5mm<br \/>\n1 x SparkFun Audio Jack Breakout<br \/>\n1 x SparkFun USB Mini-B Breakout<br \/>\n1 x SPDT Slide Switch<br \/>\n1 x JST Jumper 2 Wire Connector<br \/>\n1 x JST Jumper 3 Wire Connector<br \/>\n1 x Insignia Speakers<br \/>\n1 x SparkFun Solderable Breadboard &#8211; Large<br \/>\n1 x SparkFun FTDI Basic Breakout &#8211; 5V<br \/>\n1 x SparkFun Cerberus USB Cable<\/p>\n<p><strong>Arduino Pro Mini 328 &#8211; 5V\/16MHz<\/strong><\/p>\n<p>Ech &#8211; Digital 13<br \/>\nTri &#8211; Digital 12<br \/>\nEcR &#8211; Digital 11<br \/>\nTrR &#8211; Digital 10<br \/>\nSPK &#8211; Digital 9<br \/>\nCAP &#8211; Analog A0<br \/>\nCAH &#8211; Analog A1<br \/>\nCAV &#8211; Analog A2<br \/>\nVIN &#8211; +5V<br \/>\nGND &#8211; GND<\/p>\n<p>&#8212;&#8212;<\/p>\n<p><strong>DL2207Mk04p.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/* ***** Don Luc Electronics \u00a9 *****\r\nSoftware Version Information\r\nProject #22: Synthesizer - Volume - Mk07\r\n22-07\r\nDL2207Mk04p.ino\r\n1 x Arduino Pro Mini 328 - 5V\/16MHz\r\n2 x HC-SR04 Ultrasonic Sensor\r\n3 x 1M Ohm Potentiometer\r\n3 x Knob\r\n1 x Audio Jack 3.5mm\r\n1 x SparkFun Audio Jack Breakout\r\n1 x SparkFun USB Mini-B Breakout\r\n1 x SPDT Slide Switch\r\n1 x JST Jumper 2 Wire Connector\r\n1 x JST Jumper 3 Wire Connector\r\n1 x Insignia Speakers\r\n1 x SparkFun Solderable Breadboard - Large\r\n1 x SparkFun FTDI Basic Breakout - 5V\r\n1 x SparkFun Cerberus USB Cable\r\n*\/\r\n\r\n\/\/ Include the Library Code\r\n\/\/ Mozzi\r\n#include &lt;MozziGuts.h&gt;\r\n\/\/ Oscillator\r\n#include &lt;Oscil.h&gt;\r\n\/\/ Table for Oscils to play\r\n#include &lt;tables\/cos2048_int8.h&gt;\r\n\/\/ Smoothing Control\r\n#include &lt;Smooth.h&gt;\r\n\/\/ Maps unpredictable inputs to a range\r\n#include &lt;AutoMap.h&gt;\r\n\r\n\/\/ Desired carrier frequency max and min, for AutoMap\r\nconst int MIN_CARRIER_FREQ = 22;\r\nconst int MAX_CARRIER_FREQ = 440;\r\n\r\n\/\/ Desired intensity max and min, for AutoMap, note they&#039;re inverted for reverse dynamics\r\nconst int MIN_INTENSITY = 700;\r\nconst int MAX_INTENSITY = 10;\r\n\r\n\/\/ Desired mod speed max and min, for AutoMap, note they&#039;re inverted for reverse dynamics\r\nconst int MIN_MOD_SPEED = 10000;\r\nconst int MAX_MOD_SPEED = 1;\r\n\r\n\/\/ Maps unpredictable inputs to a range\r\nAutoMap kMapCarrierFreq(0,1023,MIN_CARRIER_FREQ,MAX_CARRIER_FREQ);\r\nAutoMap kMapIntensity(0,1023,MIN_INTENSITY,MAX_INTENSITY);\r\nAutoMap kMapModSpeed(0,1023,MIN_MOD_SPEED,MAX_MOD_SPEED);\r\n\r\n\/\/ Set the input for the knob to analog pin 0\r\nconst int KNOB_PIN = A0;\r\n\/\/ Set the analog input for fm_intensity\r\nint LDR1_PIN;\r\n\/\/ Set the analog input for mod rate\r\nint LDR2_PIN;\r\n\r\n\/\/ Table for Oscils to play\r\nOscil&lt;COS2048_NUM_CELLS, AUDIO_RATE&gt; aCarrier(COS2048_DATA);\r\nOscil&lt;COS2048_NUM_CELLS, AUDIO_RATE&gt; aModulator(COS2048_DATA);\r\nOscil&lt;COS2048_NUM_CELLS, CONTROL_RATE&gt; kIntensityMod(COS2048_DATA);\r\n\r\n\/\/ Harmonics (Brightness)\r\nint iModRatio = A1;\r\nint mod_ratio;\r\n\/\/ Carries control info from updateControl to updateAudio\r\nlong fm_intensity;\r\n\r\n\/\/ Smoothing for intensity to remove clicks on transitions\r\nfloat smoothness = 0.95f;\r\nSmooth &lt;long&gt; aSmoothIntensity(smoothness);\r\n\r\n\/\/ Trigger pin 12 to pitch distance sensor\r\nconst int iTrigPitch = 12;\r\n\/\/ Echo Receive pin 13 to pitch distance sensor\r\nconst int iEchoPitch = 13;\r\n\/\/ Define the useable range of the pitch sensor\r\nconst int pitchLowThreshold = 45;\r\nconst int pitchHighThreshold = 2;    \r\n\/\/ Stores the distance measured by the distance sensor\r\nfloat distance = 0;\r\n\/\/ Trigger pin 10 to rate distance sensor\r\nconst int iTrigRate = 10;\r\n\/\/ Echo Receive pin 13 to pitch distance sensor\r\nconst int iEchoRate = 11;\r\n\/\/ Define the useable range of the pitch sensor\r\nconst int rateLowThreshold = 45;\r\nconst int rateHighThreshold = 2;    \r\n\/\/ Stores the distance measured by the distance sensor\r\nfloat rate = 0;\r\n\r\n\/\/ Volume\r\n\/\/ Set the input for the knob to analog pin 2\r\nconst int iVolKnob = A2;\r\n\/\/ To convey the Volume level from updateControl() to updateAudio()\r\nbyte bVolume;\r\n\r\n\/\/ Mini Speaker\r\nint SPK = 9;\r\n\r\n\/\/ Software Version Information\r\nString sver = &quot;22-07&quot;;\r\n\r\nvoid loop() {\r\n\r\n  \/\/ Audio Hook\r\n  audioHook();\r\n  \r\n}\r\n<\/pre>\n<p><strong>getHC-SR04.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ HC-SR04 Ultrasonic Sensor\r\n\/\/ Setup HC-SR04\r\nvoid setupHCSR04() {\r\n\r\n  \/\/ The trigger iTrig Pitch will output pulses of electricity\r\n  pinMode(iTrigPitch, OUTPUT);\r\n  \/\/ The echo iEcho will measure the duration of pulses coming back from the distance sensor\r\n  pinMode(iEchoPitch, INPUT);\r\n\r\n  \/\/ The trigger iTrig Rate will output pulses of electricity\r\n  pinMode(iTrigRate, OUTPUT);\r\n  \/\/ The echo iEcho will measure the duration of pulses coming back from the distance sensor\r\n  pinMode(iEchoRate, INPUT);\r\n  \r\n}\r\n\/\/ Distance\r\nfloat isDistance() {\r\n  \r\n  \/\/ Variable to store the time it takes for a ping to bounce off an object\r\n  float echoTime;\r\n  \/\/ Variable to store the distance calculated from the echo time\r\n  float calculatedDistance;\r\n\r\n  \/\/ Send out an ultrasonic pulse that&#039;s 10ms long\r\n  digitalWrite(iTrigPitch, HIGH);\r\n  delayMicroseconds(10);\r\n  digitalWrite(iTrigPitch, LOW);\r\n\r\n  \/\/ Use the pulseIn command to see how long it takes for the\r\n  \/\/ pulse to bounce back to the sensor\r\n  echoTime = pulseIn(iEchoPitch, HIGH);\r\n\r\n  \/\/ Calculate the distance of the object that reflected the pulse\r\n  \/\/ (half the bounce time multiplied by the speed of sound)\r\n  calculatedDistance = echoTime * 0.034 \/ 2;\r\n\r\n  \/\/ Send back the distance that was calculated\r\n  return calculatedDistance;\r\n  \r\n}\r\n\/\/ Rate\r\nfloat isRate() {\r\n  \r\n  \/\/ Variable to store the time it takes for a ping to bounce off an object\r\n  float echoTime;\r\n  \/\/ Variable to store the distance calculated from the echo time\r\n  float calculatedDistance;\r\n\r\n  \/\/ Send out an ultrasonic pulse that&#039;s 10ms long\r\n  digitalWrite(iTrigRate, HIGH);\r\n  delayMicroseconds(10);\r\n  digitalWrite(iTrigRate, LOW);\r\n\r\n  \/\/ Use the pulseIn command to see how long it takes for the\r\n  \/\/ pulse to bounce back to the sensor\r\n  echoTime = pulseIn(iEchoRate, HIGH);\r\n\r\n  \/\/ Calculate the distance of the object that reflected the pulse\r\n  \/\/ (half the bounce time multiplied by the speed of sound)\r\n  \/\/ cm = 58.0\r\n  calculatedDistance = echoTime * 0.034 \/ 2;\r\n\r\n  \/\/ Send back the distance that was calculated\r\n  return calculatedDistance;\r\n  \r\n}\r\n<\/pre>\n<p><strong>getMozzi.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Mozzi\r\n\/\/ Update Control\r\nvoid updateControl(){\r\n\r\n  \/\/ Variable to store the distance measured by the sensor\r\n  distance = isDistance();\r\n  \/\/ Low Threshold\r\n  if ( distance &gt;= pitchLowThreshold) {\r\n\r\n    \/\/ pitchLowThreshold\r\n    distance = pitchLowThreshold;\r\n    \r\n  }\r\n  \/\/ High Threshold\r\n  if ( distance &lt; pitchHighThreshold){\r\n    \r\n    \/\/ pitchHighThreshold\r\n    distance = pitchHighThreshold;\r\n    \r\n  }\r\n\r\n  \/\/ Variable to store the distance measured by the sensor\r\n  rate = isRate();\r\n  \/\/ Low Threshold\r\n  if ( rate &gt;= rateLowThreshold) {\r\n\r\n    \/\/ rateLowThreshold\r\n    rate = rateLowThreshold;\r\n    \r\n  }\r\n  \/\/ High Threshold\r\n  if ( rate &lt; rateHighThreshold){\r\n    \r\n    \/\/ rateHighThreshold\r\n    rate = rateHighThreshold;\r\n    \r\n  }\r\n\r\n  \/\/ Map\r\n  distance = map(distance, 45, 2, 0, 1023);\r\n  rate = map(rate, 45, 2, 0, 1023);\r\n  \r\n  \/\/ Read the knob\r\n  \/\/ Value is 0-1023\r\n  int knob_value = mozziAnalogRead(KNOB_PIN);\r\n\r\n  \/\/ Read the mod_ratio\r\n  \/\/ Value is 0-1023\r\n  mod_ratio = mozziAnalogRead(iModRatio);\r\n\r\n  \/\/ Map\r\n  mod_ratio = map(mod_ratio, 0, 1023, 2, 15);\r\n\r\n  \/\/ Map the knob to carrier frequency\r\n  int carrier_freq = kMapCarrierFreq(knob_value);\r\n\r\n  \/\/ Calculate the modulation frequency to stay in ratio\r\n  int mod_freq = carrier_freq * mod_ratio;\r\n\r\n  \/\/ Set the FM oscillator frequencies\r\n  aCarrier.setFreq(carrier_freq);\r\n  aModulator.setFreq(mod_freq);\r\n\r\n  \/\/ Read the light dependent resistor on the width\r\n  LDR1_PIN = distance;\r\n  int LDR1_value = LDR1_PIN;\r\n\r\n  int LDR1_calibrated = kMapIntensity(LDR1_value);\r\n\r\n  \/\/ Calculate the fm_intensity\r\n  \/\/ Shift back to range after 8 bit multiply\r\n  fm_intensity = ((long)LDR1_calibrated * (kIntensityMod.next()+128))&gt;&gt;8;\r\n  \r\n  \/\/ Read the light dependent resistor on the speed\r\n  LDR2_PIN = rate;\r\n  int LDR2_value= LDR2_PIN;\r\n\r\n  \/\/ Use a float here for low frequencies\r\n  float mod_speed = (float)kMapModSpeed(LDR2_value)\/1000;\r\n\r\n  kIntensityMod.setFreq(mod_speed);\r\n\r\n  \/\/ Read the variable resistor for volume\r\n  \/\/ Value is 0-1023\r\n  int iVolValue = mozziAnalogRead(iVolKnob); \r\n  \/\/ map it to an 8 bit range for efficient calculations in updateAudio\r\n  bVolume = map(iVolValue, 0, 1023, 155, 1);\r\n  \r\n}\r\n\/\/ Update Audio\r\nint updateAudio()\r\n{\r\n\r\n  \/\/ Update Audio\r\n  long modulation = aSmoothIntensity.next(fm_intensity) * aModulator.next() * bVolume;\r\n  return aCarrier.phMod(modulation);\r\n\r\n}\r\n<\/pre>\n<p><strong>setup.ino<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"arduino\" data-enlighter-title=\"\">\r\n\/\/ Setup\r\nvoid setup() {\r\n\r\n  \/\/ Setup HC-SR04\r\n  setupHCSR04();\r\n\r\n  \/\/ Delay\r\n  delay( 200 );\r\n\r\n  \/\/ Mozzi Start\r\n  startMozzi();\r\n\r\n}\r\n<\/pre>\n<p>&#8212;&#8212;<\/p>\n<p><strong>People can contact us:<\/strong> https:\/\/www.donluc.com\/?page_id=1927<\/p>\n<p><strong>Technology Experience<\/strong><\/p>\n<ul>\n<li>Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc&#8230;)<\/li>\n<li>IoT<\/li>\n<li>Robotics<\/li>\n<li>Camera and Video Capture Receiver Stationary, Wheel\/Tank and Underwater Vehicle<\/li>\n<li>Unmanned Vehicles Terrestrial and Marine<\/li>\n<li>Research &#038; Development (R &#038; D)<\/li>\n<\/ul>\n<p><strong>Instructor and E-Mentor<\/strong><\/p>\n<ul>\n<li>IoT<\/li>\n<li>PIC Microcontrollers<\/li>\n<li>Arduino<\/li>\n<li>Raspberry Pi<\/li>\n<li>Espressif<\/li>\n<li>Robotics<\/li>\n<\/ul>\n<p><strong>Follow Us<\/strong><\/p>\n<p><strong>J. Luc Paquin \u2013 Curriculum Vitae &#8211; 2022 English &#038; Espa\u00f1ol<\/strong><br \/>\nhttps:\/\/www.jlpconsultants.com\/luc\/<\/p>\n<p><strong>Web:<\/strong> https:\/\/www.donluc.com\/<br \/>\n<strong>Web:<\/strong> https:\/\/www.jlpconsultants.com\/<br \/>\n<strong>Facebook:<\/strong> https:\/\/www.facebook.com\/neosteam.labs.9\/<br \/>\n<strong>YouTube:<\/strong> https:\/\/www.youtube.com\/channel\/UC5eRjrGn1CqkkGfZy0jxEdA<br \/>\n<strong>Twitter:<\/strong> https:\/\/twitter.com\/labs_steam<br \/>\n<strong>Pinterest:<\/strong> https:\/\/www.pinterest.com\/NeoSteamLabs\/<br \/>\n<strong>Instagram:<\/strong> https:\/\/www.instagram.com\/neosteamlabs\/<\/p>\n<p><strong>Don Luc<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212; DonLucElectronics #DonLuc #Synthesizer #UltrasonicSynth #Mozzi #Arduino #ArduinoProMini #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; &#8212;&#8212; Volume Sound Volume the degree of loudness or the intensity of a sound. The volume of a sound is how loud or quiet the sound is. Sounds are vibrations that travel through the air. Volume, or loudness, &#8230; <a title=\"Project #22: Synthesizer &#8211; Volume Sound &#8211; Mk07\" class=\"read-more\" href=\"https:\/\/www.donluc.com\/?p=3133\" aria-label=\"Read more about Project #22: Synthesizer &#8211; Volume Sound &#8211; Mk07\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[205,50,49,38,59,5,7,58,10,43,51],"tags":[6,102,4,19,85,24,25,9,27,109,8,127,33,34,226],"class_list":["post-3133","post","type-post","status-publish","format-standard","hentry","category-synthesizer","category-arduino","category-consultant","category-digitalelectronics","category-fritzing","category-microcontrollers","category-musical-instruments","category-arduino-programming","category-projects","category-sparkfun","category-synth","tag-arduino","tag-components","tag-consultant","tag-electronics","tag-fritzing","tag-microcontroller","tag-musical-instruments-2","tag-programming","tag-projects-2","tag-sparkfun","tag-synth","tag-synthesizer","tag-technology","tag-video-blog","tag-volume-sound"],"_links":{"self":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3133"}],"version-history":[{"count":1,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3133\/revisions"}],"predecessor-version":[{"id":3138,"href":"https:\/\/www.donluc.com\/index.php?rest_route=\/wp\/v2\/posts\/3133\/revisions\/3138"}],"wp:attachment":[{"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.donluc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}