Skip to content

Commit b97d683

Browse files
committed
prevent copy & littlefs
1 parent c6bac7b commit b97d683

File tree

20 files changed

+413
-70
lines changed

20 files changed

+413
-70
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file player-littlefs-i2s.ino
3+
* @brief example using the LittleFS library
4+
*
5+
* @author Phil Schatzmann
6+
* @copyright GPLv3
7+
*/
8+
9+
#include "AudioTools.h"
10+
#include "AudioLibs/AudioSourceLittleFS.h"
11+
#include "AudioCodecs/CodecMP3Helix.h"
12+
13+
const char *startFilePath="/";
14+
const char* ext="mp3";
15+
AudioSourceLittleFS source(startFilePath, ext);
16+
I2SStream i2s;
17+
MP3DecoderHelix decoder;
18+
AudioPlayer player(source, i2s, decoder);
19+
20+
void printMetaData(MetaDataType type, const char* str, int len){
21+
Serial.print("==> ");
22+
Serial.print(toStr(type));
23+
Serial.print(": ");
24+
Serial.println(str);
25+
}
26+
27+
void setup() {
28+
Serial.begin(115200);
29+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
30+
31+
// setup output
32+
auto cfg = i2s.defaultConfig(TX_MODE);
33+
i2s.begin(cfg);
34+
35+
// setup player
36+
//source.setFileFilter("*Bob Dylan*");
37+
player.setMetadataCallback(printMetaData);
38+
player.begin();
39+
}
40+
41+
void loop() {
42+
player.copy();
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @file player-littlefs-i2s.ino
3+
* @brief example using the SD library
4+
*
5+
* @author Phil Schatzmann
6+
* @copyright GPLv3
7+
*/
8+
9+
#include "AudioTools.h"
10+
#include "AudioLibs/AudioSourceSD.h"
11+
#include "AudioCodecs/CodecMP3Helix.h"
12+
13+
const char *startFilePath="/";
14+
const char* ext="mp3";
15+
AudioSourceSD source(startFilePath, ext);
16+
I2SStream i2s;
17+
MP3DecoderHelix decoder;
18+
AudioPlayer player(source, i2s, decoder);
19+
20+
void printMetaData(MetaDataType type, const char* str, int len){
21+
Serial.print("==> ");
22+
Serial.print(toStr(type));
23+
Serial.print(": ");
24+
Serial.println(str);
25+
}
26+
27+
void setup() {
28+
Serial.begin(115200);
29+
AudioLogger::instance().begin(Serial, AudioLogger::Info);
30+
31+
// setup output
32+
auto cfg = i2s.defaultConfig(TX_MODE);
33+
i2s.begin(cfg);
34+
35+
// setup player
36+
//source.setFileFilter("*Bob Dylan*");
37+
player.setMetadataCallback(printMetaData);
38+
player.begin();
39+
}
40+
41+
void loop() {
42+
player.copy();
43+
}

src/AudioBasic/Collections/Vector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ class Vector {
296296
return p_data;
297297
}
298298

299+
operator bool() const {
300+
return p_data!=nullptr;
301+
}
302+
299303
protected:
300304
int bufferLen=0;
301305
int len = 0;

src/AudioBasic/StrExt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class StrExt : public Str {
5050
// move constructor
5151
StrExt (StrExt &&obj) = default;
5252

53-
// copy assignment
53+
// move assignment
5454
StrExt& operator = (StrExt &&obj) = default;
5555

56-
// move assingment
56+
// copy assingment
5757
StrExt& operator = (StrExt &obj) {
5858
set(obj.c_str());
5959
return *this;

src/AudioCodecs/AudioEncoded.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class AudioDecoder : public AudioWriter, public AudioBaseInfoSource {
1717
public:
1818
AudioDecoder() = default;
1919
virtual ~AudioDecoder() = default;
20+
AudioDecoder(AudioDecoder const&) = delete;
21+
AudioDecoder& operator=(AudioDecoder const&) = delete;
22+
2023
virtual AudioBaseInfo audioInfo() = 0;
2124
// for most decoder this is not needed
2225
virtual void setAudioInfo(AudioBaseInfo from) override {}
@@ -44,6 +47,8 @@ class AudioEncoder : public AudioWriter {
4447
public:
4548
AudioEncoder() = default;
4649
virtual ~AudioEncoder() = default;
50+
AudioEncoder(AudioEncoder const&) = delete;
51+
AudioEncoder& operator=(AudioEncoder const&) = delete;
4752
virtual const char *mime() = 0;
4853
};
4954

src/AudioCodecs/CodecFloat.h

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#pragma once
2+
3+
#include "AudioCodecs/AudioEncoded.h"
4+
5+
namespace audio_tools {
6+
7+
8+
/**
9+
* @brief DecoderFloat - Converts an 8 Bit Stream into Floats
10+
*
11+
* @author Phil Schatzmann
12+
* @copyright GPLv3
13+
*/
14+
class DecoderFloat : public AudioDecoder {
15+
public:
16+
/**
17+
* @brief Construct a new RAWDecoder object
18+
*/
19+
20+
DecoderFloat(){
21+
TRACED();
22+
}
23+
24+
/**
25+
* @brief Construct a new RAWDecoder object
26+
*
27+
* @param out_stream Output Stream to which we write the decoded result
28+
*/
29+
DecoderFloat(Print &out_stream, bool active=true){
30+
TRACED();
31+
p_print = &out_stream;
32+
this->active = active;
33+
}
34+
35+
/**
36+
* @brief Construct a new RAWDecoder object
37+
*
38+
* @param out_stream Output Stream to which we write the decoded result
39+
* @param bi Object that will be notified about the Audio Formt (Changes)
40+
*/
41+
42+
DecoderFloat(Print &out_stream, AudioBaseInfoDependent &bi){
43+
TRACED();
44+
p_print = &out_stream;
45+
}
46+
47+
/// Defines the output Stream
48+
void setOutputStream(Print &out_stream) override {
49+
p_print = &out_stream;
50+
}
51+
52+
void setNotifyAudioChange(AudioBaseInfoDependent &bi) override {
53+
this->bid = &bi;
54+
}
55+
56+
AudioBaseInfo audioInfo() override {
57+
return cfg;
58+
}
59+
60+
void begin(AudioBaseInfo info) {
61+
TRACED();
62+
cfg = info;
63+
if (bid!=nullptr){
64+
bid->setAudioInfo(cfg);
65+
}
66+
active = true;
67+
}
68+
69+
void begin() override {
70+
TRACED();
71+
active = true;
72+
}
73+
74+
void end() override {
75+
TRACED();
76+
active = false;
77+
}
78+
79+
/// Converts data from float to int16_t
80+
virtual size_t write(const void *data, size_t in_size) override {
81+
if (p_print==nullptr) return 0;
82+
int samples = in_size/sizeof(float);
83+
buffer.resize(samples);
84+
float* p_float = (float*) data;
85+
for (int j=0;j<samples;j++){
86+
buffer[j] = p_float[j]*32767;
87+
}
88+
return p_print->write((uint8_t*)buffer.data(), samples*sizeof(int16_t));
89+
}
90+
91+
virtual operator bool() override {
92+
return active;
93+
}
94+
95+
protected:
96+
Print *p_print=nullptr;
97+
AudioBaseInfoDependent *bid=nullptr;
98+
AudioBaseInfo cfg;
99+
bool active;
100+
Vector<int16_t> buffer;
101+
102+
};
103+
104+
/**
105+
* @brief EncoderFloats - Encodes 16 bit PCM data stream to floats
106+
* data.
107+
* @author Phil Schatzmann
108+
* @copyright GPLv3
109+
*/
110+
class EncoderFloat : public AudioEncoder {
111+
public:
112+
// Empty Constructor - the output stream must be provided with begin()
113+
EncoderFloat(){
114+
}
115+
116+
// Constructor providing the output stream
117+
EncoderFloat(Print &out){
118+
p_print = &out;
119+
}
120+
121+
/// Defines the output Stream
122+
void setOutputStream(Print &out_stream) override {
123+
p_print = &out_stream;
124+
}
125+
126+
/// Provides "audio/pcm"
127+
const char* mime() override{
128+
return mime_pcm;
129+
}
130+
131+
/// We actually do nothing with this
132+
virtual void setAudioInfo(AudioBaseInfo from) override {
133+
}
134+
135+
/// starts the processing using the actual RAWAudioInfo
136+
virtual void begin() override{
137+
is_open = true;
138+
}
139+
140+
/// starts the processing
141+
void begin(Print &out) {
142+
p_print = &out;
143+
begin();
144+
}
145+
146+
/// stops the processing
147+
void end() override {
148+
is_open = false;
149+
}
150+
151+
/// Converts data from int16_t to float
152+
virtual size_t write(const void *in_ptr, size_t in_size) override {
153+
if (p_print==nullptr) return 0;
154+
int16_t *pt16 = (int16_t*)in_ptr;
155+
size_t samples = in_size / sizeof(int16_t);
156+
buffer.resize(samples);
157+
for (int j=0;j<samples;j++){
158+
buffer[j] = static_cast<float>(pt16[j]) / 32768.0;
159+
}
160+
return p_print->write((uint8_t*)buffer.data(), samples*sizeof(float));
161+
}
162+
163+
operator bool() override {
164+
return is_open;
165+
}
166+
167+
bool isOpen(){
168+
return is_open;
169+
}
170+
171+
protected:
172+
Print* p_print=nullptr;;
173+
volatile bool is_open;
174+
Vector<float> buffer;
175+
176+
177+
};
178+
179+
}

src/AudioEffects/Synthesizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ class Synthesizer : public SoundGenerator<int16_t> {
210210
Synthesizer(AbstractSynthesizerChannel *ch){
211211
defaultChannel = ch;
212212
}
213+
214+
Synthesizer(Synthesizer const&) = delete;
215+
Synthesizer& operator=(Synthesizer const&) = delete;
213216

214217
~Synthesizer(){
215218
TRACED();

src/AudioFilter/Filter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Filter {
1515
// construct without coefs
1616
Filter() = default;
1717
virtual ~Filter() = default;
18+
Filter(Filter const&) = delete;
19+
Filter& operator=(Filter const&) = delete;
20+
1821
virtual T process(T in) = 0;
1922
};
2023

src/AudioI2S/I2SStream.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,6 @@
1515

1616
namespace audio_tools {
1717

18-
// /**
19-
// * @brief A Simple I2S interface class for multiple Architectures that supports the reading and writing with a defined data type
20-
// * @author Phil Schatzmann
21-
// * @copyright GPLv3
22-
// */
23-
// template<typename T>
24-
// class I2S : public I2SBase {
25-
26-
// public:
27-
// /// Default Constructor
28-
// I2S() {
29-
// TRACED();
30-
// }
31-
32-
// /// Destructor
33-
// ~I2S() {
34-
// end();
35-
// }
36-
37-
// bool begin(I2SConfig cfg) {
38-
// TRACED();
39-
// // define bits per sampe from data type
40-
// cfg.bits_per_sample = sizeof(T) * 8;
41-
// return I2SBase::begin(cfg);
42-
// }
43-
44-
// /// writes the data to the I2S interface
45-
// size_t write(T (*src)[2], size_t frameCount){
46-
// TRACED();
47-
// return writeBytes(src, frameCount * sizeof(T) * 2); // 2 bytes * 2 channels
48-
// }
49-
50-
// /// Reads data from I2S
51-
// size_t read(T (*src)[2], size_t frameCount){
52-
// size_t len = readBytes(src, frameCount * sizeof(T) * 2); // 2 bytes * 2 channels
53-
// size_t result = len / (sizeof(T) * 2);
54-
// return result;
55-
// }
56-
57-
// virtual void end() {}
58-
59-
// };
60-
61-
6218
/**
6319
* @brief We support the Stream interface for the I2S access. In addition we allow a separate mute pin which might also be used
6420
* to drive a LED...

src/AudioLibs/AudioKit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ class AudioKitStream : public AudioStreamX {
567567
int volume_value = 40;
568568
bool active = true;
569569
// channel and sample size conversion support
570-
AudioKitStreamAdapter kit_stream = AudioKitStreamAdapter(&kit);
571-
ChannelFormatConverterStream converter = ChannelFormatConverterStream(kit_stream);
570+
AudioKitStreamAdapter kit_stream{&kit};
571+
ChannelFormatConverterStream converter{kit_stream};
572572
bool is_started = false;
573573

574574
/// Determines the action logic (ActiveLow or ActiveTouch) for the pin

0 commit comments

Comments
 (0)