Skip to content

Commit 87993fb

Browse files
committed
Cleanup Logging
1 parent 2f7c981 commit 87993fb

File tree

5 files changed

+39
-36
lines changed

5 files changed

+39
-36
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ I am providing a simple webserver which can render the audio data as wav result.
118118
- [streams-generator-webserver_wav](examples/streams-generator-webserver_wav) A Webserver which renders some generated sound
119119
- [streams-sam-webserver_wav](examples/streams-sam-webserver_wav) A Webserver which renders the result from the SAM TTS engine
120120

121+
#### Logging
122+
123+
The application uses a built in logger. You can adapt the loging by changing AudioConfig.h
124+
125+
```
126+
#define USE_AUDIO_LOGGING false
127+
```
128+
129+
Per default we use the log level warning and the logging output is going to Serial. You can also change this in your sketch by calling AudioLogger begin with the output stream and the log level e.g:
130+
131+
```
132+
AudioLogger::instance().begin(Serial, AudioLogger::Debug);
133+
```
134+
121135

122136
## Optional Libraries
123137

sandbox/streams-mozzi-webserver/streams-mozzi-webserver.ino

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef int16_t sound_t; // sound will be repre
2323
uint8_t channels = 1; // The stream will have 2 channels
2424
MozziGenerator mozzi(CONTROL_RATE); // subclass of SoundGenerator
2525
GeneratedSoundStream<sound_t> in(mozzi, channels); // Stream generated with mozzi
26-
AudioWAVServer server;
26+
AudioWAVServer server("network", "password");
2727

2828
/// Copied from AMsynth.ino
2929
#define CONTROL_RATE 64 // Hz, powers of 2 are most reliable
@@ -48,19 +48,6 @@ Q8n0 octave_start_note = 42;
4848
void setup(){
4949
Serial.begin(115200);
5050

51-
// connect to WIFI
52-
WiFi.begin("network", "password");
53-
while (WiFi.status() != WL_CONNECTED){
54-
Serial.print(".");
55-
delay(500);
56-
}
57-
Serial.println();
58-
Serial.print("Connect to http://");
59-
Serial.print(WiFi.localIP());
60-
61-
//start stream
62-
in.begin();
63-
6451
// We send the audio via the server
6552
server.begin(in, mozzi.config().sample_rate, channels);
6653

@@ -69,6 +56,8 @@ void setup(){
6956
kNoteChangeDelay.set(200); // note duration ms, within resolution of CONTROL_RATE
7057
aModDepth.setFreq(13.f); // vary mod depth to highlight am effects
7158
randSeed(); // reseed the random generator for different results each time the sketch runs
59+
60+
// Start Mozzi Stream
7261
in.begin();
7362
}
7463

@@ -123,5 +112,5 @@ AudioOutput_t updateAudio(){
123112

124113
// Arduino loop
125114
void loop() {
126-
server.copy();
115+
server.doLoop();
127116
}

src/AudioConfig.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
#pragma once
88
#include <string.h>
9-
#include "AudioTools/AudioLogger.h"
109
/**
1110
* -------------------------------------------------------------------------
1211
* @brief Optional Functionality - comment out if not wanted
@@ -81,20 +80,5 @@
8180
#define USE_AUDIO_LOGGING true
8281
#endif
8382

84-
// Logging Implementation
85-
// #if USE_AUDIO_LOGGING && VARARG_SUPPORT
86-
// #define LOGD(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Debug, __VA_ARGS__)
87-
// #define LOGI(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Info, __VA_ARGS__)
88-
// #define LOGW(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Warning, __VA_ARGS__)
89-
// #define LOGE(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Error, __VA_ARGS__)
90-
#if USE_AUDIO_LOGGING
91-
#define LOGD(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Debug).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
92-
#define LOGI(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Info).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
93-
#define LOGW(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Warning).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
94-
#define LOGE(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Error).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
95-
#else
96-
#define LOGD(...)
97-
#define LOGI(...)
98-
#define LOGW(...)
99-
#define LOGE(...)
100-
#endif
83+
#define LOG_LEVEL AudioLogger::Warning
84+
#define LOG_STREAM Serial

src/AudioTools/AudioLogger.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@
1010
//#define VARARG_SUPPORT false
1111
//#endif
1212

13-
#define LOG_LEVEL AudioLogger::Warning
14-
#define LOG_STREAM Serial
15-
1613
#ifndef PRINTF_BUFFER_SIZE
1714
#define PRINTF_BUFFER_SIZE 160
1815
#endif
1916

17+
// Logging Implementation
18+
// #if USE_AUDIO_LOGGING && VARARG_SUPPORT
19+
// #define LOGD(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Debug, __VA_ARGS__)
20+
// #define LOGI(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Info, __VA_ARGS__)
21+
// #define LOGW(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Warning, __VA_ARGS__)
22+
// #define LOGE(...) AudioLogger::instance().printLog(__FILE__,__LINE__, AudioLogger::Error, __VA_ARGS__)
23+
#if USE_AUDIO_LOGGING
24+
#define LOGD(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Debug).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
25+
#define LOGI(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Info).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
26+
#define LOGW(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Warning).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
27+
#define LOGE(...) snprintf(AudioLogger::instance().prefix(__FILE__,__LINE__, AudioLogger::Error).str(),PRINTF_BUFFER_SIZE,__VA_ARGS__); AudioLogger::instance().println();
28+
#else
29+
#define LOGD(...)
30+
#define LOGI(...)
31+
#define LOGW(...)
32+
#define LOGE(...)
33+
#endif
2034

2135
namespace audio_tools {
2236

src/AudioTools/Buffers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
#pragma once
33

4+
#include "AudioTools/AudioLogger.h"
5+
46
#undef MIN
57
#define MIN(A,B) ((A) < (B) ? (A) : (B))
68

0 commit comments

Comments
 (0)