Skip to content

Commit 4034961

Browse files
committed
Remove TimedStream
1 parent 859a168 commit 4034961

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

src/api/SnapOutput.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ class SnapOutput : public AudioInfoSupport {
9191
this->out = &output; // final output
9292
resample.setStream(output);
9393
vol_stream.setStream(resample); // adjust volume
94-
timed_stream.setStream(vol_stream);
95-
decoder_stream.setStream(&timed_stream); // decode to pcm
94+
decoder_stream.setStream(&vol_stream); // decode to pcm
9695
}
9796

9897
AudioOutput &getOutput() { return *out; }
@@ -110,7 +109,6 @@ class SnapOutput : public AudioInfoSupport {
110109
if (is_audio_begin_called) {
111110
vol_stream.setAudioInfo(info);
112111
out->setAudioInfo(info);
113-
timed_stream.setAudioInfo(info);
114112
}
115113
}
116114

@@ -123,10 +121,6 @@ class SnapOutput : public AudioInfoSupport {
123121

124122
bool isStarted() { return is_audio_begin_called; }
125123

126-
/// If set to true, the startup is using delay()
127-
void setSynchronizeStartWithDelay(bool flag){
128-
is_synchronize_with_delay = flag;
129-
}
130124

131125
protected:
132126
const char *TAG = "SnapOutput";
@@ -135,7 +129,6 @@ class SnapOutput : public AudioInfoSupport {
135129
EncodedAudioStream decoder_stream;
136130
VolumeStream vol_stream;
137131
ResampleStream resample;
138-
TimedStream timed_stream;
139132
float vol = 1.0; // volume in the range 0.0 - 1.0
140133
float vol_factor = 1.0; //
141134
bool is_mute = false;
@@ -145,7 +138,6 @@ class SnapOutput : public AudioInfoSupport {
145138
SnapTimeSync *p_snap_time_sync = &time_sync_default;
146139
bool is_sync_started = false;
147140
bool is_audio_begin_called = false;
148-
bool is_synchronize_with_delay = false;
149141

150142
/// setup of all audio objects
151143
bool audioBegin() {
@@ -173,13 +165,10 @@ class SnapOutput : public AudioInfoSupport {
173165

174166
// open resampler
175167
auto res_cfg = resample.defaultConfig();
176-
res_cfg.step_size = p_snap_time_sync-;
168+
res_cfg.step_size = p_snap_time_sync->getFactor();
177169
res_cfg.copyFrom(audio_info);
178170
resample.begin(res_cfg);
179171

180-
// set up timed stream
181-
timed_stream.begin(audio_info);
182-
183172
ESP_LOGD(TAG, "end");
184173
is_audio_begin_called = true;
185174
return true;
@@ -254,17 +243,6 @@ class SnapOutput : public AudioInfoSupport {
254243
// wait for the audio to become valid
255244
ESP_LOGI(TAG, "starting after %d ms", delay_ms);
256245
setPlaybackFactor(p_snap_time_sync->getFactor());
257-
// replaced delay(delay_ms); with timed_stream
258-
if (is_synchronize_with_delay){
259-
timed_stream.setStartMs(0);
260-
timed_stream.begin();
261-
// When we feed the data from a queue, delay is the best solution
262-
delay(delay_ms);
263-
264-
} else {
265-
timed_stream.setStartMs(delay_ms);
266-
timed_stream.begin();
267-
}
268246
is_sync_started = true;
269247
result = true;
270248
}

src/api/SnapProcessor.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class SnapProcessor {
270270
// Wait for timeout
271271
// uint64_t end = millis() + CONFIG_WEBSOCKET_SERVER_TIMEOUT_SEC * 1000;
272272
while (p_client->available() < BASE_MESSAGE_SIZE) {
273-
delay(100);
273+
delay(10);
274274
}
275275

276276
// Read Header Record with size
@@ -328,7 +328,7 @@ class SnapProcessor {
328328
if (!processMessageCodecHeaderExt(OGG))
329329
return false;
330330
} else if (strcmp(codec_header_message.codec(), "pcm") == 0) {
331-
if (!processMessageCodecHeaderExt(PCM))
331+
if (!processMessageCodecHeaderWav(PCM))
332332
return false;
333333
} else {
334334
ESP_LOGI(TAG, "Codec : %s not supported", codec_header_message.codec());
@@ -357,12 +357,21 @@ class SnapProcessor {
357357
return true;
358358
}
359359

360+
bool processMessageCodecHeaderWav(codec_type codecType) {
361+
ESP_LOGD(TAG, "start");
362+
codec_from_server = codecType;
363+
audioBegin();
364+
// send the wav header to the codec
365+
p_snap_output->audioWrite((const uint8_t*)start, 44);
366+
return true;
367+
}
368+
360369
bool processMessageCodecHeaderExt(codec_type codecType) {
361370
ESP_LOGD(TAG, "start");
362371
codec_from_server = codecType;
363372
audioBegin();
364373
// send the data to the codec
365-
p_snap_output->audioWrite((const uint8_t*)start, size);
374+
//p_snap_output->audioWrite((const uint8_t*)start, size);
366375
return true;
367376
}
368377

src/api/SnapProcessorRTOS.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class SnapProcessorRTOS : public SnapProcessor {
2525
}
2626

2727
bool begin() override {
28-
// we use a simple delay to delay the start
29-
p_snap_output->setSynchronizeStartWithDelay(true);
3028
// regular begin logic
3129
bool result = SnapProcessor::begin();
3230
// empty buffer

0 commit comments

Comments
 (0)