You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I'm encountering an issue when playing wav files, once in a while a pop sounds
appear at the very beginning. The beginning of the file is silence though.
I'm starting this discussion after going through wiki , documentation & discussion board, but there's something I'd like
to try and failed to implement myself, in the following code, I would like the volume to raise a few millisecond
after I start playing the file.
I looked into the way "fade" is implemented in the audioplayer, but failed at implementing it in Fileloop.
Maybe I don't need to fade in, but just wait for some time after I start playing the file.
here's the code I've come up with, any help at using the volume to raise after the file is started is welcome:
#define initPMU()
#define disablePeripherals()
int currentTrack = 0;
unsigned long lastTime = 0;
int inBytes = 0;
int lastInBytes = 0;
int counter = 0;
FileLister fileLister;
int *fileCounts = fileLister.getFileCounts();
int folderIndex = 0;
char MAC[23];
int id = -1;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I'm encountering an issue when playing wav files, once in a while a pop sounds
appear at the very beginning. The beginning of the file is silence though.
I'm starting this discussion after going through wiki , documentation & discussion board, but there's something I'd like
to try and failed to implement myself, in the following code, I would like the volume to raise a few millisecond
after I start playing the file.
I looked into the way "fade" is implemented in the audioplayer, but failed at implementing it in Fileloop.
Maybe I don't need to fade in, but just wait for some time after I start playing the file.
here's the code I've come up with, any help at using the volume to raise after the file is started is welcome:
#define LoRa_frequency 433E6
#define UNUSE_PIN (0)
#define RADIO_SCLK_PIN 5
#define RADIO_MISO_PIN 19
#define RADIO_MOSI_PIN 27
#define RADIO_CS_PIN 18
#define RADIO_DIO0_PIN 26
#define RADIO_RST_PIN 23
#define RADIO_DIO1_PIN 33
#define RADIO_BUSY_PIN 32
#include <LoRa.h>
#include "AudioTools.h"
#include "AudioCodecs/CodecWAV.h"
#include "AudioLibs/FileLoop.h"
#include "AudioLibs/AudioSourceSD.h"
#include <SPI.h>
#include <SD.h>
#include "FileLister.h"
#include <Arduino.h>
#include <Wire.h>
#define initPMU()
#define disablePeripherals()
int currentTrack = 0;
unsigned long lastTime = 0;
int inBytes = 0;
int lastInBytes = 0;
int counter = 0;
FileLister fileLister;
int *fileCounts = fileLister.getFileCounts();
int folderIndex = 0;
char MAC[23];
int id = -1;
SPIClass SDSPI(HSPI);
I2SStream i2s;
const char *startFilePath = "/";
const char *ext = "wav";
VolumeStream volume(i2s);
EncodedAudioStream decoder(&volume, new WAVDecoder());
FileLoop loopingFile;
StreamCopy copier(decoder, loopingFile);
void initBoard() {
Serial.println("initBoard");
SPI.begin(RADIO_SCLK_PIN, RADIO_MISO_PIN, RADIO_MOSI_PIN);
}
void setup() {
Serial.begin(115200);
initBoard();
delay(1500);
int folderCount = fileLister.readDirectoriesAndFiles();
printList();
snprintf(MAC, 23, "%llX", ESP.getEfuseMac());
Serial.println("LoRa Receiver");
Serial.println(MAC);
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
if (!LoRa.begin(LoRa_frequency)) {
Serial.println("Starting LoRa failed!");
while (1) ;
}
LoRa.setTxPower(20);
//AudioLogger::instance().begin(Serial, AudioLogger::Info);
auto cfg = i2s.defaultConfig(TX_MODE);
cfg.pin_bck = 4;
cfg.pin_ws = 12;
cfg.pin_data = 25;
i2s.begin(cfg);
volume.begin(cfg);
volume.setVolume(1);
decoder.begin();
Serial.println(fileCounts[0]);
// handlePlayFile(0, 1);
}
void loop() {
copier.copy();
int packetSize = LoRa.parsePacket();
if (packetSize) {
String recv = "";
while (LoRa.available()) {
char c = LoRa.read();
if (c == ' ') {
break;
} else {
recv += c;
}
}
recv.trim();
if (recv == "t") {
handlePlayFile(1, 0);
} else if (recv == "l") {
loopingFile.end();
currentTrack = 0;
} else if (recv == "s") {
if (!copier.copy()) {
handlePlayFile(0, currentTrack);
} else if (copier.copy()) {
volume.setVolume(0);
loopingFile.end();
currentTrack = (currentTrack + 1) % fileCounts[0];
}
}
}
}
void handlePlayFile(int folderIndex, int fileIndex) {
loopingFile.setLoopCount(0);
String filePath = fileLister.getFilePath(folderIndex, fileIndex);
File wavFile = SD.open(filePath);
loopingFile.setStartPos(44);
loopingFile.setFile(wavFile);
volume.setVolume(1);
}
Cheers
Beta Was this translation helpful? Give feedback.
All reactions