How to make the volume louder from this code in the process?

I have a code to play some sound from arduino. The song was encoded from numerical values. but how do I get him to play louder with arduino?

#include <PCM.h> int switchPin = 8; const unsigned char sample[] PROGMEM = { 140, 124, 130, 126, 129, 126, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 127, 128, 128, 128, 128, }; void setup() { pinMode(switchPin, INPUT); } void loop() { if(digitalRead(switchPin) == HIGH) { startPlayback(sample, sizeof(sample)); } } 
+4
source share
3 answers

This code example uses a routine that uses the PCM method to control the intervals at which digital contacts turn on and off (and assuming these output contacts are connected to a simple speaker). Remember that sound frequency is what makes tones and volume the amplitude of these frequencies. So you ask, to make the sound louder, how to increase the amplitude of the signal. But since this simple demonstration is only able to change the time during which the digital signals switch (frequency), and not the amplitude (bit is the value “On Off”, Bit is never “REALLY ON” [caps denote the cry here: - )]), so your only choice is to add another level of hardware between the Arduino and the speaker to increase the amplitude of the tone, for example, an amplifier. It may be something as simple as the operating system described in this design tutorial or replacing the speaker with a jack for the boombox input.

+4
source

Sound signals are inherently signs. If your library uses unsigned char for audio data, then it probably displays 0 → -128 and 255 → 127. So let's look at your signal.

The first 6 samples:

 140, 124, 130, 126, 129, 126 

- a slight wobble around 127. Then the rest of your signal

 128, 127, 128, 127, ... 

more or less DC. It will be inaudible.

Try to signal {0, 255, 0, 255, ...}, it should be much louder.

+1
source

If you read the comments in pcm.h, you will see that the volume will be very low. The PCM method adjusts the percentage of time the pin is high. I agree with jdh's recommendation that the volume will be limited no matter what the amplifier will help. Something louder in software, I would think that you need more square wave with adjustable frequency, so that the pin will be high, as often as low, and in fact the frequency is adjustable. I have not used it, but I will look at the arduino Tone () library.

0
source

Source: https://habr.com/ru/post/1395078/


All Articles