Skip to content

Commit

Permalink
ftp example
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 8, 2023
1 parent 83767f4 commit f83465d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 53 additions & 0 deletions examples/examples-communication/ftp/ftp-client/ftp-client.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @file ftp-client.ino
* @author Phil Schatzmann
* @brief Receiving audio via FTP and writing to I2S of the AudioKit.
* Replace the userids, passwords and ip adresses with your own!
* @version 0.1
* @date 2023-11-09
*
* @copyright Copyright (c) 2023
*/

#include "WiFi.h"
#include "ArduinoFTPClient.h" // install https://github.com/pschatzmann/TinyFTPClient
#include "AudioTools.h"
#include "AudioCodecs/CodecMP3Helix.h"
#include "AudioLibs/AudioKit.h"

WiFiClient cmd;
WiFiClient data;
FTPClient client(cmd, data);
FTPFile file;
AudioKitStream kit; // or replace with e.g. I2SStream
MP3DecoderHelix mp3;
EncodedAudioStream decoder(&kit, &mp3);
StreamCopy copier(decoder, file);

void setup() {
Serial.begin(115200);

// connect to WIFI
WiFi.begin("network name", "password");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

// optional logging
FTPLogger::setOutput(Serial);
// FTPLogger::setLogLevel(LOG_DEBUG);

// open connection
client.begin(IPAddress(192, 168, 1, 10), "user", "password");

// copy data from file
file = client.open("/data/music/Neil Young/After the Gold Rush/08 Birds.mp3");

// open output device
kit.begin();
decoder.begin();

}

void loop() { copier.copy(); }
2 changes: 1 addition & 1 deletion src/AudioTools/AudioStreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ class Throttle : public AudioStream {
uint64_t durationUsEff = micros() - start_time;
uint64_t durationUsToBe = getDelayUs(sum_frames);
int64_t waitUs = durationUsToBe - durationUsEff + cfg.correction_us;
LOGI("wait us: %ld", waitUs);
LOGI("wait us: %ld", (long) waitUs);
if (waitUs > 0) {
int64_t waitMs = waitUs / 1000;
if (waitMs > 0) delay(waitMs);
Expand Down

0 comments on commit f83465d

Please sign in to comment.