Skip to content

Commit fb61674

Browse files
committed
MetaDataICY
1 parent a7e2cd1 commit fb61674

File tree

4 files changed

+79
-7
lines changed

4 files changed

+79
-7
lines changed

src/AudioBasic/Str.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Str {
3232

3333
/// Creates a Str with the indicated buffer
3434
Str(char chars[], int maxlen, int len=0){
35-
set(chars,maxlen,len, false);
35+
set(chars, maxlen, len, false);
3636
}
3737

3838
Str (const Str & ) = default;

src/AudioEffects/SoundGenerator.h

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ class SilenceGenerator : public SoundGenerator<T> {
306306

307307
/**
308308
* @brief An Adapter Class which lets you use any Stream as a Generator
309-
*
309+
* @author Phil Schatzmann
310+
* @copyright GPLv3
310311
* @tparam T
311312
*/
312313
template <class T>
@@ -376,14 +377,16 @@ class GeneratorFromStream : public SoundGenerator<T> {
376377

377378
/**
378379
* @brief We generate the samples from an array which is provided in the constructor
379-
*
380+
* @author Phil Schatzmann
381+
* @copyright GPLv3
380382
* @tparam T
381383
*/
382384

383385
template <class T>
384386
class GeneratorFromArray : public SoundGenerator<T> {
385387
public:
386388

389+
GeneratorFromArray() = default;
387390
/**
388391
* @brief Construct a new Generator From Array object
389392
*
@@ -464,10 +467,68 @@ class GeneratorFromArray : public SoundGenerator<T> {
464467

465468
};
466469

470+
/**
471+
* @brief A sine generator based on a table. The table is created based using degress where one full wave is 360 degrees
472+
* @author Phil Schatzmann
473+
* @copyright GPLv3
474+
*/
475+
template <class T>
476+
class SineFromTable : public SoundGenerator<T> {
477+
public:
478+
SineFromTable(float amplitude = 32767.0){
479+
this->amplitude = amplitude;
480+
}
481+
482+
T readSample() {
483+
// update angle
484+
angle += step;
485+
if (angle >= 360){
486+
angle -= 360;
487+
}
488+
return amplitude * interpolate(angle);
489+
}
490+
491+
bool begin() {
492+
GeneratorFromArray<float>::begin();
493+
base_frequency = SoundGenerator<T>::audioInfo().sample_rate / 360.0; //122.5 hz (at 44100); 61 hz (at 22050)
494+
return true;
495+
}
496+
497+
bool begin(AudioBaseInfo info, float frequency) {
498+
SoundGenerator<T>::begin(info);
499+
setFrequency(frequency);
500+
return true;
501+
}
502+
503+
void setFrequency(float freq) {
504+
step = freq / base_frequency;
505+
LOGI("step: %f", step);
506+
}
507+
508+
protected:
509+
float amplitude;
510+
float base_frequency;
511+
float step = 1.0;
512+
float angle = 0;
513+
const float values[181] = {0, 0.0174524, 0.0348995, 0.052336, 0.0697565, 0.0871557, 0.104528, 0.121869, 0.139173, 0.156434, 0.173648, 0.190809, 0.207912, 0.224951, 0.241922, 0.258819, 0.275637, 0.292372, 0.309017, 0.325568, 0.34202, 0.358368, 0.374607, 0.390731, 0.406737, 0.422618, 0.438371, 0.45399, 0.469472, 0.48481, 0.5, 0.515038, 0.529919, 0.544639, 0.559193, 0.573576, 0.587785, 0.601815, 0.615661, 0.62932, 0.642788, 0.656059, 0.669131, 0.681998, 0.694658, 0.707107, 0.71934, 0.731354, 0.743145, 0.75471, 0.766044, 0.777146, 0.788011, 0.798636, 0.809017, 0.819152, 0.829038, 0.838671, 0.848048, 0.857167, 0.866025, 0.87462, 0.882948, 0.891007, 0.898794, 0.906308, 0.913545, 0.920505, 0.927184, 0.93358, 0.939693, 0.945519, 0.951057, 0.956305, 0.961262, 0.965926, 0.970296, 0.97437, 0.978148, 0.981627, 0.984808, 0.987688, 0.990268, 0.992546, 0.994522, 0.996195, 0.997564, 0.99863, 0.999391, 0.999848, 1, 0.999848, 0.999391, 0.99863, 0.997564, 0.996195, 0.994522, 0.992546, 0.990268, 0.987688, 0.984808, 0.981627, 0.978148, 0.97437, 0.970296, 0.965926, 0.961262, 0.956305, 0.951057, 0.945519, 0.939693, 0.93358, 0.927184, 0.920505, 0.913545, 0.906308, 0.898794, 0.891007, 0.882948, 0.87462, 0.866025, 0.857167, 0.848048, 0.838671, 0.829038, 0.819152, 0.809017, 0.798636, 0.788011, 0.777146, 0.766044, 0.75471, 0.743145, 0.731354, 0.71934, 0.707107, 0.694658, 0.681998, 0.669131, 0.656059, 0.642788, 0.62932, 0.615661, 0.601815, 0.587785, 0.573576, 0.559193, 0.544639, 0.529919, 0.515038, 0.5, 0.48481, 0.469472, 0.45399, 0.438371, 0.422618, 0.406737, 0.390731, 0.374607, 0.358368, 0.34202, 0.325568, 0.309017, 0.292372, 0.275637, 0.258819, 0.241922, 0.224951, 0.207912, 0.190809, 0.173648, 0.156434, 0.139173, 0.121869, 0.104528, 0.0871557, 0.0697565, 0.052336, 0.0348995, 0.0174524, 0};
514+
515+
float interpolate(float angle){
516+
bool positive = (angle<=180);
517+
float angle_positive = positive ? angle : angle - 180;
518+
int angle_int1 = angle_positive;
519+
int angle_int2 = angle_int1+1;
520+
float v1 = values[angle_int1];
521+
float v2 = values[angle_int2];
522+
float result = map(angle,angle_int1,angle_int2,v1, v2);
523+
return positive ? result : -result;
524+
}
525+
526+
};
467527

468528
/**
469529
* @brief Mixer which combines multiple sound generators into one output
470-
*
530+
* @author Phil Schatzmann
531+
* @copyright GPLv3
471532
* @tparam T
472533
*/
473534
template <class T>
@@ -501,6 +562,7 @@ class GeneratorMixer : public SoundGenerator<T> {
501562
}
502563
return result;;
503564
}
565+
504566
protected:
505567
Vector<SoundGenerator<T>*> vector;
506568
int actualChannel=0;

src/AudioHttp/URLStream.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ class URLStreamDefault : public AbstractURLStream {
173173
/// Process the Http request and handle redirects
174174
int process(MethodID action, Url &url, const char* reqMime, const char *reqData, int len=-1) {
175175
request.setClient(getClient(url.isSecure()));
176+
// keep icy across redirect requests ?
177+
const char* icy = request.header().get("Icy-MetaData");
178+
176179
// set timeout
177180
getClient(url.isSecure()).setTimeout(clientTimeout);
178181
int status_code = request.process(action, url, reqMime, reqData, len);
@@ -185,6 +188,9 @@ class URLStreamDefault : public AbstractURLStream {
185188
Client* p_client = &getClient(url.isSecure());
186189
p_client->stop();
187190
request.setClient(*p_client);
191+
if (icy){
192+
request.header().put("Icy-MetaData", icy);
193+
}
188194
status_code = request.process(action, url, reqMime, reqData, len);
189195
} else {
190196
LOGE("Location is null");

src/AudioMetaData/MetaDataICY.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ class MetaDataICY : public AbstractMetaData {
207207
LOGD(LOG_METHOD);
208208
metaData[len]=0;
209209
if (isAscii(metaData, 12)){
210-
LOGI("%s", metaData);
211-
Str meta(metaData, len);
210+
LOGI("%s: %d", metaData);
211+
Str meta(metaData,len+1, len);
212212
int start = meta.indexOf("StreamTitle=");
213213
if (start>=0){
214214
start+=12;
@@ -252,7 +252,11 @@ class ICYUrlSetup {
252252
LOGD(LOG_METHOD);
253253
p_http = &http;
254254
const char* iceMetaintStr = http.reply().get("icy-metaint");
255-
LOGI("icy-metaint: %s", iceMetaintStr);
255+
if (iceMetaintStr){
256+
LOGI("icy-metaint: %s", iceMetaintStr);
257+
} else {
258+
LOGE("icy-metaint not defined");
259+
}
256260
Str value(iceMetaintStr);
257261
int iceMetaint = value.toInt();
258262
return iceMetaint;

0 commit comments

Comments
 (0)