3#include "AudioTools/CoreAudio/AudioStreams.h"
4#include "AudioTools/CoreAudio/AudioOutput.h"
5#include "AudioTools/AudioCodecs/CodecWAV.h"
11#include "nlohmann/json.hpp"
12#include "xtl/xbase64.hpp"
22 p_audio_stream = &stream;
24 size_t write(
const uint8_t *data,
size_t len)
override {
25 p_audio_stream->write((
const char*)data,len);
28 int availableForWrite()
override {
32 std::fstream *p_audio_stream=
nullptr;
43 void setup(std::string fName,
int channelCount,
int channelNo) {
45 this->channels = channelCount;
46 if (this->channels==0){
47 LOGE(
"Setting channels to 0");
49 this->channel = channelNo;
53 return this->channels;
65 if (channel<channels){
67 is.open(fname, is.binary);
68 is.seekg(wav_header_size, is.beg);
69 std::list<int16_t> audioList;
71 size_t rec_size = channels*
sizeof(T);
72 while(is.read((
char *)buffer, rec_size)){
73 audioList.push_back(transform(buffer[channel]));
75 string str_size =
"102400";
76 str <<
"<style>div.x-svg {width: "<< str_size <<
"px; }</style>";
77 str <<
"<div class='x-svg'><svg viewBox='0 0 "<< str_size <<
" 100'> <polyline fill='none' stroke='blue' stroke-width='1' points ='";
80 for(int16_t sample: audioList){
81 str << idx++ <<
"," << sample <<
" ";
83 str <<
"'/></svg></div>";
85 str <<
"<p>Channel " << channel <<
" of " << channels <<
" does not exist!</p>";
91 std::stringstream str;
93 const int wav_header_size = 44;
98 int result = x / 1000;
117 buffer_count = bufferCount;
118 p_audio_stream = &stream;
120 copier.resize(bufferSize);
130 chrt.setup(fname, cfg.
channels, channel);
135 const std::string &name()
const {
140 const std::string path()
const {
141 std::filesystem::path p = fname;
142 std::string result = std::filesystem::absolute(p);
147 void createWAVFile(){
150 std::fstream fstream(fname, fstream.binary | fstream.trunc | fstream.out);
154 out.setEncoder(&wave_encoder);
156 copier.begin(out, *p_audio_stream);
157 copier.copyN(buffer_count);
160 }
catch(
const std::exception& ex){
161 std::cerr << ex.what();
166 ifstream f(fname.c_str());
175 std::string audio() {
176 std::ifstream fin(fname, std::ios::binary);
177 std::stringstream m_buffer;
178 m_buffer << fin.rdbuf();
179 return xtl::base64encode(m_buffer.str());
195 size_t buffer_count=0;
205nl::json mime_bundle_repr(Chart &in) {
206 auto bundle = nl::json::object();
207 bundle[
"text/html"] = in.chartData();
212nl::json mime_bundle_repr(JupyterAudio &in) {
213 auto bundle = nl::json::object();
215 bundle[
"text/html"] =
"<audio controls "
216 "src='data:audio/wav;base64," +
If you want to use the framework w/o Arduino you need to provide the implementation of a couple of cl...