SimpleSDAudio 库播放音乐声音怎么放大
如果是三极管 的话 请给个电路 改代码的话在下面
#include <SimpleSDAudio.h>
// Callback target, prints output to serial
void DirCallback(char *buf)
{
Serial.println(buf);
}
char AudioFileName;
// Create static buffer
#define BIGBUFSIZE (2*512) // bigger than 2*512 is often only possible on Arduino megas!
uint8_t bigbuf;
// helper function to determine free ram at runtime
int freeRam ()
{
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print(F("Free Ram: "));
Serial.println(freeRam());
// Setting the buffer manually for more flexibility
SdPlay.setWorkBuffer(bigbuf, BIGBUFSIZE);
Serial.print(F("\nInitializing SimpleSDAudio V" SSDA_VERSIONSTRING " ..."));
// If your SD card CS-Pin is not at Pin 4, enable and adapt the following line:
//SdPlay.setSDCSPin(10);
// Select between SSDA_MODE_FULLRATE or SSDA_MODE_HALFRATE (62.5kHz or 31.25kHz)
// and the output modes SSDA_MODE_MONO_BRIDGE, SSDA_MODE_MONO or SSDA_MODE_STEREO
if (!SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO | SSDA_MODE_AUTOWORKER))
{
Serial.println(F("initialization failed. Things to check:"));
Serial.println(F("* is a card is inserted?"));
Serial.println(F("* Is your wiring correct?"));
Serial.println(F("* maybe you need to change the chipSelect pin to match your shield or module?"));
Serial.print(F("Error code: "));
Serial.println(SdPlay.getLastError());
while(1);
}
else
{
Serial.println(F("Wiring is correct and a card is present."));
}
}
void loop(void)
{
uint8_t count = 0, c, flag;
Serial.println(F("Files on card:"));
SdPlay.dir(&DirCallback);
ReEnter:
count = 0;
Serial.println(F("\r\nEnter filename (send newline after input):"));
do
{
while(!Serial.available()) ;
c = Serial.read();
if(c > ' ') AudioFileName = c;
}
while((c != 0x0d) && (c != 0x0a) && (count < 14));
AudioFileName = 0;
Serial.print(F("Looking for file... "));
if(!SdPlay.setFile(AudioFileName))
{
Serial.println(F(" not found on card! Error code: "));
Serial.println(SdPlay.getLastError());
goto ReEnter;
}
else
{
Serial.println(F("found."));
}
Serial.println(F("Press s for stop, p for play, h for pause, f to select new file, d for deinit, v to view status."));
flag = 1;
while(flag)
{
SdPlay.worker();// You can remove this line if you like - worker is not necessary
if(Serial.available())
{
c = Serial.read();
switch(c)
{
case 's':
SdPlay.stop();
Serial.println(F("Stopped."));
break;
case 'p':
SdPlay.play();
Serial.println(F("Play."));
break;
case 'h':
SdPlay.pause();
Serial.println(F("Pause."));
break;
case 'd':
SdPlay.deInit();
Serial.println(F("SdPlay deinitialized. You can now safely remove card. System halted."));
while(1) ;
break;
case 'f':
flag = 0;
break;
case 'v':
Serial.print(F("Status: isStopped="));
Serial.print(SdPlay.isStopped());
Serial.print(F(", isPlaying="));
Serial.print(SdPlay.isPlaying());
Serial.print(F(", isPaused="));
Serial.print(SdPlay.isPaused());
Serial.print(F(", isUnderrunOccured="));
Serial.print(SdPlay.isUnderrunOccured());
Serial.print(F(", getLastError="));
Serial.println(SdPlay.getLastError());
Serial.print(F("Free RAM: "));
Serial.println(freeRam());
break;
}
}
}
}
用功放板算解决方案吗 播放和放大是两件事,我理解你已经解决播放的事了,现在想放大音量。音频放大和功放板子多的事,只是不知道你播放用什么板子,输出信号的规格,是否有音量控制?了解了这些才可能去找合适的放大器。
这个库,是利用PWM输出驱动喇叭发音的。在输出那边用一个较小的电容,比如103P~4.7uf隔离后,可以接比如说LM2822,8002等功率放大电路。参数需要你自己调整。但是,这有意义吗?这个库,解码能力很差,还不如找一个专门的Mp3/WAV解码芯片,外挂进行控制。
页:
[1]