make few sound with a motor dc

Hello,

I want make few sounds with a motor DC…
ESP8266 + driver H-Bridge with pins :
InA : boolean
InB : boolean
and Pwm 0 - 100% : 0 - 255

void motorAv()
  {     digitalWrite(inaPin, HIGH);                              
        digitalWrite(inbPin, LOW);      }
 
void motorAr()
  {        digitalWrite(inaPin, LOW);                              
           digitalWrite(inbPin, HIGH);         }  
 
void motorStop()              
       {   digitalWrite(inaPin, LOW);                              
           digitalWrite(inbPin, LOW);      }      
 
 
void playSound(uint16_t freq, uint16_t duration_msec, uint8_t amplitude)
{  uint32_t n,k,period_usec,duration_usec;
   period_usec = 1000000L / freq;
   duration_usec = 1000 * (uint32_t) duration_msec;
   k = duration_usec / period_usec;
   pwm= amplitude;                              // pwm max driver motor = 100%
   for (n = 0; n < k; n++)
     {  motorAv();
        delayMicroseconds(period_usec/2);
        motorAr();
        delayMicroseconds(period_usec/2); }
   motorStop;                                    }
       
 
 uint16_t freq = 1000;     // max 65535
  uint16_t duration_msec = 400;
  uint8_t amplitude=255;
  for (int i =15000; i < 19000; i = i +100)
    {  delay(100);
       playSound(i, duration_msec, amplitude);
    }

No sound

Please why ?

Your program doesn't compile. It is missing setup() and loop().

Because a DC motor isn't a speaker. Far more inductance and inertia than any practical speaker,
and no way to couple any rotation to air movement (unless you fit vanes to the axle?). Basically
everything is against you.

Stepper motors, on the other hand, completely different story.

MorganS:
Your program doesn't compile. It is missing setup() and loop().

Normal, I did not copy all the rest of the program, make a small sound is only a small part.

MarkT:
Because a DC motor isn't a speaker. Far more inductance and inertia than any practical speaker,
and no way to couple any rotation to air movement (unless you fit vanes to the axle?). Basically
everything is against you.

Stepper motors, on the other hand, completely different story.

Your answer does not take into account the data I have indicated.
By sending a pwm in the audible frequencies we can create a sound while having an engine that does not run because the pulses are too short.
My program does not produce sound because it should not cause an audible pwm.
Where I need help is how to at least have a sound, then I would be able to vary it in frequency and intensity.

Please try to cut your code down to the smallest possible example which will compile.

You know those annoying declarations which seem useless? They are required and often that is where the problem is. The parts of the code you think are unrelated to the problem might not be.

If anything, the process of cutting the code will show your error.