Skip to content

Commit f25b69b

Browse files
committed
AudioWAVServer Callback Support - correction
1 parent 645a597 commit f25b69b

File tree

6 files changed

+374
-15
lines changed

6 files changed

+374
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Using Mozzi on Bluetooth
2+
3+
I am providing a simple sketch which reads Alice in Wonderland using SAM
4+
In this demo we provide the result as a result WAV stream which is available in the Web Browser
5+
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
const char *alice =
2+
" "
3+
" CHAPTER I: Down the Rabbit-Hole. "
4+
" "
5+
" Alice was beginning to get very tired of sitting by her sister "
6+
"on the bank, and of having nothing to do: once or twice she had "
7+
"peeped into the book her sister was reading, but it had no "
8+
"pictures or conversations in it, `and what is the use of a book,' "
9+
"thought Alice `without pictures or conversation?' "
10+
" "
11+
" So she was considering in her own mind (as well as she could, "
12+
"for the hot day made her feel very sleepy and stupid), whether "
13+
"the pleasure of making a daisy-chain would be worth the trouble "
14+
"of getting up and picking the daisies, when suddenly a White "
15+
"Rabbit with pink eyes ran close by her. "
16+
" "
17+
" There was nothing so VERY remarkable in that; nor did Alice "
18+
"think it so VERY much out of the way to hear the Rabbit say to "
19+
"itself, `Oh dear! Oh dear! I shall be late!' (when she thought "
20+
"it over afterwards, it occurred to her that she ought to have "
21+
"wondered at this, but at the time it all seemed quite natural); "
22+
"but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- "
23+
"POCKET, and looked at it, and then hurried on, Alice started to "
24+
"her feet, for it flashed across her mind that she had never "
25+
"before seen a rabbit with either a waistcoat-pocket, or a watch to "
26+
"take out of it, and burning with curiosity, she ran across the "
27+
"field after it, and fortunately was just in time to see it pop "
28+
"down a large rabbit-hole under the hedge. "
29+
" "
30+
" In another moment down went Alice after it, never once "
31+
"considering how in the world she was to get out again. "
32+
" "
33+
" The rabbit-hole went straight on like a tunnel for some way, "
34+
"and then dipped suddenly down, so suddenly that Alice had not a "
35+
"moment to think about stopping herself before she found herself "
36+
"falling down a very deep well. "
37+
" "
38+
" Either the well was very deep, or she fell very slowly, for she "
39+
"had plenty of time as she went down to look about her and to "
40+
"wonder what was going to happen next. First, she tried to look "
41+
"down and make out what she was coming to, but it was too dark to "
42+
"see anything; then she looked at the sides of the well, and "
43+
"noticed that they were filled with cupboards and book-shelves; "
44+
"here and there she saw maps and pictures hung upon pegs. She "
45+
"took down a jar from one of the shelves as she passed; it was "
46+
"labelled `ORANGE MARMALADE', but to her great disappointment it "
47+
"was empty: she did not like to drop the jar for fear of killing "
48+
"somebody, so managed to put it into one of the cupboards as she "
49+
"fell past it. "
50+
" "
51+
" `Well!' thought Alice to herself, `after such a fall as this, I "
52+
"shall think nothing of tumbling down stairs! How brave they'll "
53+
"all think me at home! Why, I wouldn't say anything about it, "
54+
"even if I fell off the top of the house!' (Which was very likely "
55+
"true.) "
56+
" "
57+
" Down, down, down. Would the fall NEVER come to an end! `I "
58+
"wonder how many miles I've fallen by this time?' she said aloud. "
59+
"`I must be getting somewhere near the centre of the earth. Let "
60+
"me see: that would be four thousand miles down, I think--' (for, "
61+
"you see, Alice had learnt several things of this sort in her "
62+
"lessons in the schoolroom, and though this was not a VERY good "
63+
"opportunity for showing off her knowledge, as there was no one to "
64+
"listen to her, still it was good practice to say it over) `--yes, "
65+
"that's about the right distance--but then I wonder what Latitude "
66+
"or Longitude I've got to?' (Alice had no idea what Latitude was, "
67+
"or Longitude either, but thought they were nice grand words to "
68+
"say.) "
69+
" "
70+
" Presently she began again. `I wonder if I shall fall right "
71+
"THROUGH the earth! How funny it'll seem to come out among the "
72+
"people that walk with their heads downward! The Antipathies, I "
73+
"think--' (she was rather glad there WAS no one listening, this "
74+
"time, as it didn't sound at all the right word) `--but I shall "
75+
"have to ask them what the name of the country is, you know. "
76+
"Please, Ma'am, is this New Zealand or Australia?' (and she tried "
77+
"to curtsey as she spoke--fancy CURTSEYING as you're falling "
78+
"through the air! Do you think you could manage it?) `And what "
79+
"an ignorant little girl she'll think me for asking! No, it'll "
80+
"never do to ask: perhaps I shall see it written up somewhere.' "
81+
" "
82+
" Down, down, down. There was nothing else to do, so Alice soon "
83+
"began talking again. `Dinah'll miss me very much to-night, I "
84+
"should think!' (Dinah was the cat.) `I hope they'll remember "
85+
"her saucer of milk at tea-time. Dinah my dear! I wish you were "
86+
"down here with me! There are no mice in the air, I'm afraid, but "
87+
"you might catch a bat, and that's very like a mouse, you know. "
88+
"But do cats eat bats, I wonder?' And here Alice began to get "
89+
"rather sleepy, and went on saying to herself, in a dreamy sort of "
90+
"way, `Do cats eat bats? Do cats eat bats?' and sometimes, `Do "
91+
"bats eat cats?' for, you see, as she couldn't answer either "
92+
"question, it didn't much matter which way she put it. She felt "
93+
"that she was dozing off, and had just begun to dream that she "
94+
"was walking hand in hand with Dinah, and saying to her very "
95+
"earnestly, `Now, Dinah, tell me the truth: did you ever eat a "
96+
"bat?' when suddenly, thump! thump! down she came upon a heap of "
97+
"sticks and dry leaves, and the fall was over. "
98+
" "
99+
" Alice was not a bit hurt, and she jumped up on to her feet in a "
100+
"moment: she looked up, but it was all dark overhead; before her "
101+
"was another long passage, and the White Rabbit was still in "
102+
"sight, hurrying down it. There was not a moment to be lost: "
103+
"away went Alice like the wind, and was just in time to hear it "
104+
"say, as it turned a corner, `Oh my ears and whiskers, how late "
105+
"it's getting!' She was close behind it when she turned the "
106+
"corner, but the Rabbit was no longer to be seen: she found "
107+
"herself in a long, low hall, which was lit up by a row of lamps "
108+
"hanging from the roof. "
109+
" "
110+
" There were doors all round the hall, but they were all locked; "
111+
"and when Alice had been all the way down one side and up the "
112+
"other, trying every door, she walked sadly down the middle, "
113+
"wondering how she was ever to get out again. "
114+
" "
115+
" Suddenly she came upon a little three-legged table, all made of "
116+
"solid glass; there was nothing on it except a tiny golden key, "
117+
"and Alice's first thought was that it might belong to one of the "
118+
"doors of the hall; but, alas! either the locks were too large, or "
119+
"the key was too small, but at any rate it would not open any of "
120+
"them. However, on the second time round, she came upon a low "
121+
"curtain she had not noticed before, and behind it was a little "
122+
"door about fifteen inches high: she tried the little golden key "
123+
"in the lock, and to her great delight it fitted! "
124+
" "
125+
" Alice opened the door and found that it led into a small "
126+
"passage, not much larger than a rat-hole: she knelt down and "
127+
"looked along the passage into the loveliest garden you ever saw. "
128+
"How she longed to get out of that dark hall, and wander about "
129+
"among those beds of bright flowers and those cool fountains, but "
130+
"she could not even get her head though the doorway; `and even if "
131+
"my head would go through,' thought poor Alice, `it would be of "
132+
"very little use without my shoulders. Oh, how I wish "
133+
"I could shut up like a telescope! I think I could, if I only "
134+
"know how to begin.' For, you see, so many out-of-the-way things "
135+
"had happened lately, that Alice had begun to think that very few "
136+
"things indeed were really impossible. "
137+
" "
138+
" There seemed to be no use in waiting by the little door, so she "
139+
"went back to the table, half hoping she might find another key on "
140+
"it, or at any rate a book of rules for shutting people up like "
141+
"telescopes: this time she found a little bottle on it, (`which "
142+
"certainly was not here before,' said Alice,) and round the neck "
143+
"of the bottle was a paper label, with the words `DRINK ME' "
144+
"beautifully printed on it in large letters. "
145+
" "
146+
" It was all very well to say `Drink me,' but the wise little "
147+
"Alice was not going to do THAT in a hurry. `No, I'll look "
148+
"first,' she said, `and see whether it's marked 'poison' or not'; "
149+
"for she had read several nice little histories about children who "
150+
"had got burnt, and eaten up by wild beasts and other unpleasant "
151+
"things, all because they WOULD not remember the simple rules "
152+
"their friends had taught them: such as, that a red-hot poker "
153+
"will burn you if you hold it too long; and that if you cut your "
154+
"finger VERY deeply with a knife, it usually bleeds; and she had "
155+
"never forgotten that, if you drink much from a bottle marked "
156+
"`poison,' it is almost certain to disagree with you, sooner or "
157+
"later. "
158+
" "
159+
" However, this bottle was NOT marked `poison,' so Alice ventured "
160+
"to taste it, and finding it very nice, (it had, in fact, a sort "
161+
"of mixed flavour of cherry-tart, custard, pine-apple, roast "
162+
"turkey, toffee, and hot buttered toast,) she very soon finished "
163+
"it off. "
164+
" * * * * * * * "
165+
" "
166+
" * * * * * * "
167+
" "
168+
" * * * * * * * "
169+
" "
170+
" `What a curious feeling!' said Alice; `I must be shutting up "
171+
"like a telescope.' "
172+
" "
173+
" And so it was indeed: she was now only ten inches high, and "
174+
"her face brightened up at the thought that she was now the right "
175+
"size for going though the little door into that lovely garden. "
176+
"First, however, she waited for a few minutes to see if she was "
177+
"going to shrink any further: she felt a little nervous about "
178+
"this; `for it might end, you know,' said Alice to herself, `in my "
179+
"going out altogether, like a candle. I wonder what I should be "
180+
"like then?' And she tried to fancy what the flame of a candle is "
181+
"like after the candle is blown out, for she could not remember "
182+
"ever having seen such a thing. "
183+
" "
184+
" After a while, finding that nothing more happened, she decided "
185+
"on going into the garden at once; but, alas for poor Alice! when "
186+
"she got to the door, she found he had forgotten the little golden "
187+
"key, and when she went back to the table for it, she found she "
188+
"could not possibly reach it: she could see it quite plainly "
189+
"through the glass, and she tried her best to climb up one of the "
190+
"legs of the table, but it was too slippery; and when she had "
191+
"tired herself out with trying, the poor little thing sat down and "
192+
"cried. "
193+
" "
194+
" `Come, there's no use in crying like that!' said Alice to "
195+
"herself, rather sharply; `I advise you to leave off this minute!' "
196+
"She generally gave herself very good advice, (though she very "
197+
"seldom followed it), and sometimes she scolded herself so "
198+
"severely as to bring tears into her eyes; and once she remembered "
199+
"trying to box her own ears for having cheated herself in a game "
200+
"of croquet she was playing against herself, for this curious "
201+
"child was very fond of pretending to be two people. `But it's no "
202+
"use now,' thought poor Alice, `to pretend to be two people! Why, "
203+
"there's hardly enough of me left to make ONE respectable "
204+
"person!' "
205+
" "
206+
" Soon her eye fell on a little glass box that was lying under "
207+
"the table: she opened it, and found in it a very small cake, on "
208+
"which the words `EAT ME' were beautifully marked in currants. "
209+
"`Well, I'll eat it,' said Alice, `and if it makes me grow larger, "
210+
"I can reach the key; and if it makes me grow smaller, I can creep "
211+
"under the door; so either way I'll get into the garden, and I "
212+
"don't care which happens!' "
213+
" "
214+
" She ate a little bit, and said anxiously to herself, `Which "
215+
"way? Which way?', holding her hand on the top of her head to "
216+
"feel which way it was growing, and she was quite surprised to "
217+
"find that she remained the same size: to be sure, this generally "
218+
"happens when one eats cake, but Alice had got so much into the "
219+
"way of expecting nothing but out-of-the-way things to happen, "
220+
"that it seemed quite dull and stupid for life to go on in the "
221+
"common way. "
222+
" "
223+
" So she set to work, and very soon finished off the cake. ";
224+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @file experiment-sam-webserver.ino
3+
* @author Phil Schatzmann
4+
*
5+
* @author Phil Schatzmann
6+
* @copyright GPLv3
7+
*
8+
*/
9+
#include "AudioTools.h"
10+
#include "AudioWAVServer.h"
11+
#include "sam_arduino.h"
12+
13+
using namespace audio_tools;
14+
15+
extern const char *alice;
16+
AudioWAVServer server("network", "password");
17+
int channels = 1;
18+
int audio_rate = 22050;
19+
20+
21+
// Callback which provides the audio data
22+
void outputData(Stream &out){
23+
Serial.println("providing audio data...");
24+
SAM sam(out, false, channels);
25+
sam.say(alice);
26+
}
27+
28+
void setup(){
29+
Serial.begin(115200);
30+
31+
// start data sink
32+
server.begin(outputData, audio_rate, channels);
33+
}
34+
35+
36+
// Arduino loop
37+
void loop() {
38+
// Handle new connections
39+
server.doLoop();
40+
}

src/AudioESP8266.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AudioOutputWithCallback : public AudioOutput, public BufferedStream {
3131
return true;
3232
}
3333

34-
/// puts the sample into a buffer
34+
/// For ESP8266 Audio Framework - puts the sample into a buffer
3535
virtual bool ConsumeSample(int16_t sample[2]) {
3636
Channels c;
3737
c.channel1 = sample[0];

src/AudioTools/Streams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ class UrlStream : public Stream {
552552

553553
size_t write(uint8_t) {
554554
LOGE("UrlStream write - not supported");
555+
return 0;
555556
}
556557

557558
void end(){

0 commit comments

Comments
 (0)