Skip to content

Commit fd14b58

Browse files
committed
Jupyter support
1 parent d6f0b81 commit fd14b58

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

src/AudioConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ typedef uint32_t eps32_i2s_sample_rate_type;
490490

491491
#ifdef IS_DESKTOP
492492
#define USE_URL_ARDUINO
493+
#define USE_STREAM_WRITE_OVERRIDE
493494
#endif
494495

495496
#ifndef ARDUINO

src/AudioHttp/AbstractURLStream.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ namespace audio_tools {
55
/**
66
* @brief Abstract Base class for all URLStream implementations
77
* @author Phil Schatzmann
8+
* @ingroup http
89
* @copyright GPLv3
910
*/
1011
class AbstractURLStream : public AudioStream {
1112
public:
1213
// executes the URL request
1314
virtual bool begin(const char* urlStr, const char* acceptMime=nullptr, MethodID action=GET, const char* reqMime="", const char*reqData="") = 0;
1415
// ends the request
15-
virtual void end()=0;
16+
virtual void end() override =0;
1617
/// provides access to the HttpRequest
1718
virtual HttpRequest &httpRequest()=0;
1819
// only the ICYStream supports this
1920
virtual bool setMetadataCallback(void (*fn)(MetaDataType info, const char* str, int len)) {
2021
return false;
2122
}
2223
/// Writes are not supported
23-
int availableForWrite() {
24+
int availableForWrite() override {
2425
return 0;
2526
}
2627

src/AudioLibs/Jupyter/JupyterAudio.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class FilePrint : public Print {
2525
p_audio_stream->write((const char*)buffer,size);
2626
return size;
2727
}
28+
int availableForWrite() override {
29+
return 1024;
30+
}
2831
protected:
2932
std::fstream *p_audio_stream=nullptr;
3033
};
@@ -128,15 +131,17 @@ class JupyterAudioT : public AudioStreamX {
128131

129132
// fills a wav file with data once, the first time it was requested
130133
void createWAVFile(){
131-
if (!fileExists()){
132-
std::fstream fstream(fname, fstream.binary | fstream.trunc | fstream.out);
133-
FilePrint fp(fstream);
134-
WAVEncoder wave_encoder;
135-
EncodedAudioStream out(&fp, &wave_encoder); // output to decoder
136-
out.begin(cfg);
137-
StreamCopyT<T> copier(out, *p_audio_stream, buffer_count);
138-
copier.copyN(buffer_count);
139-
fstream.close();
134+
try{
135+
if (!fileExists()){
136+
std::fstream fstream(fname, fstream.binary | fstream.trunc | fstream.out);
137+
FilePrint fp(fstream);
138+
out.begin(&fp, &wave_encoder); // output to decoder
139+
copier.begin(out, *p_audio_stream);
140+
copier.copyN(buffer_count);
141+
fstream.close();
142+
}
143+
} catch(const std::exception& ex){
144+
std::cerr << ex.what();
140145
}
141146
}
142147

@@ -165,6 +170,9 @@ class JupyterAudioT : public AudioStreamX {
165170
protected:
166171
AudioStream *p_audio_stream=nullptr;
167172
ChartT<T> chrt;
173+
WAVEncoder wave_encoder;
174+
EncodedAudioPrint out;
175+
StreamCopyT<T> copier;
168176
AudioBaseInfo cfg;
169177
string fname;
170178
size_t buffer_count=0;

src/AudioTools/AudioPrint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace audio_tools {
1212

13-
#ifndef ARDUINO
13+
#if !defined(ARDUINO) || defined(IS_DESKTOP)
1414
# define FLUSH_OVERRIDE override
1515
#else
1616
# define FLUSH_OVERRIDE

0 commit comments

Comments
 (0)