@@ -62,13 +62,16 @@ class AudioServerEx : public AudioPrint {
62
62
63
63
virtual bool begin () {
64
64
end (); // we (re) start with a clean state
65
+
65
66
if (info.input ==nullptr ){
66
67
p_stream = new ExtensionStream (info.path ,tinyhttp::GET, info.mime );
67
68
} else {
68
69
p_stream = new ExtensionStream (info.path , info.mime , *info.input );
69
70
}
70
71
p_stream->setReplyHeader (*getReplyHeader ());
71
- p_server = new HttpServer (wifi);
72
+ p_server = new tinyhttp::HttpServer (wifi);
73
+
74
+ // handling of WAV
72
75
p_server->addExtension (*p_stream);
73
76
return p_server->begin (info.port , info.ssid , info.password );
74
77
}
@@ -153,21 +156,25 @@ class AudioWAVServerEx : public AudioServerEx {
153
156
protected:
154
157
// wav files start with a 44 bytes header
155
158
virtual tinyhttp::Str* getReplyHeader () {
156
- MemoryPrint mp{(uint8_t *)header.c_str (), header.length ()};
159
+ header.allocate (44 );
160
+ MemoryPrint mp{(uint8_t *)header.c_str (), 44 };
157
161
WAVEncoder enc;
158
162
WAVAudioInfo wi;
163
+ wi.format = WAV_FORMAT_PCM;
159
164
wi.sample_rate = info.sample_rate ;
160
165
wi.bits_per_sample = info.bits_per_sample ;
161
166
wi.channels = info.channels ;
162
167
enc.setAudioInfo (wi);
163
168
// fill header with data
164
169
enc.writeHeader (&mp);
170
+ // make sure that the length is 44
171
+ assert (header.length () == 44 );
165
172
166
173
return &header;
167
174
}
168
175
169
- // Allocate memory for 44 bytes header
170
- tinyhttp::StrExt header{ 44 } ;
176
+ // Dynamic memory
177
+ tinyhttp::StrExt header;
171
178
172
179
};
173
180
0 commit comments