@@ -60,7 +60,7 @@ void BoxDAC::begin() {
60
60
61
61
UDMAInit ();
62
62
UDMAChannelSelect (UDMA_CH5_I2S_TX, NULL );
63
-
63
+
64
64
writeBuffer = audioBuffer.getBuffer (BoxAudioBufferTriple::BufferType::WRITE);
65
65
writeBuffer->state = BoxAudioBufferTriple::BufferState::WRITING;
66
66
audioBuffer.logState (writeBuffer);
@@ -91,7 +91,7 @@ void BoxDAC::begin() {
91
91
(void *)I2S_TX_DMA_PORT,
92
92
UDMA_DST_INC_NONE
93
93
);
94
-
94
+
95
95
96
96
Log.info (" I2S" );
97
97
MAP_I2SIntEnable (I2S_BASE, I2S_INT_XDATA);
@@ -141,24 +141,96 @@ void BoxDAC::opusTest() {
141
141
}
142
142
Log.info("Mp3 finished");
143
143
*/
144
+ // AudioGeneratorTonie *opus;
145
+ AudioFileSourceFatFs *file;
146
+
147
+ // file = new AudioFileSourceFatFs("/gs-16b-2c-44100hz.opus");
148
+ /* file = new AudioFileSourceFatFs("/CONTENT/6977960C/500304E0");
149
+ opus = new AudioGeneratorTonie();
150
+ opus->begin(file, audioOutput);
151
+ while (opus->isRunning()) {
152
+ if (!opus->loop())
153
+ opus->stop();
154
+ }
155
+ free(file);
156
+ free(opus);
157
+ Log.info("Opus done");
158
+ */
159
+
160
+ playFile (" /piano2.wav" );
161
+ // file = new AudioFileSourceFatFs("/LRMonoPhase4.wav");
162
+ // file = new AudioFileSourceFatFs("/organfinale.wav");
163
+ // file = new AudioFileSourceFatFs("/piano2.wav");
164
+
144
165
/*
145
166
OpusDecoder* decoder;
146
167
int error;
147
168
int channels = 2;
148
169
170
+ Box.boxPower.feedSleepTimer();
171
+ Log.info("Needed heap %ib", opus_decoder_get_size(channels));
149
172
decoder = opus_decoder_create(16000, channels, &error);
150
173
if (error != OPUS_OK) {
151
174
Log.error("Could not create OPUS Decoder error=%i", error);
152
175
return;
153
176
}
154
-
177
+ Box.boxPower.feedSleepTimer();
155
178
opus_decoder_destroy(decoder);
156
179
157
180
//opus_decode(decoder, data, len, pcmout, frameSize, 0);*/
158
181
}
159
182
160
- void BoxDAC::loop () {
161
- generateZeroAudio (25 );
183
+ void BoxDAC::loop () {
184
+ loop (50 );
185
+ }
186
+ void BoxDAC::loop (uint16_t timeoutMs) {
187
+ if (audioPlaying) {
188
+ if (!audioGenerator || !audioSource) {
189
+ audioPlaying = false ;
190
+ return ;
191
+ }
192
+
193
+ BoxTimer timeout;
194
+ timeout.setTimer (timeoutMs);
195
+
196
+ while (timeout.isRunning () && audioGenerator->isRunning ()) {
197
+ if (!audioGenerator->loop ())
198
+ audioGenerator->stop ();
199
+ timeout.tick ();
200
+ }
201
+ if (!audioGenerator->isRunning ())
202
+ audioPlaying = false ;
203
+ } else {
204
+ generateZeroAudio (timeoutMs);
205
+ }
206
+ }
207
+
208
+ bool BoxDAC::playFile (const char * path) {
209
+ Log.info (" Start playing file %s..." , path);
210
+
211
+ if (audioGenerator && audioGenerator->isRunning ()) {
212
+ audioGenerator->stop ();
213
+ free (audioGenerator);
214
+ }
215
+ if (audioSource && audioSource->isOpen ()) {
216
+ audioSource->close ();
217
+ free (audioSource);
218
+ }
219
+
220
+ audioPlaying = false ;
221
+ return _playWAV (path);
222
+ }
223
+ bool BoxDAC::_playWAV (const char * path) {
224
+ audioGenerator = new AudioGeneratorWAV ();
225
+ audioSource = new AudioFileSourceFatFs (path);
226
+
227
+ if (!audioGenerator->begin (audioSource, audioOutput)) {
228
+ Log.error (" Could not play wav?!" );
229
+ return false ;
230
+ }
231
+ Log.info (" WAV file loaded..." );
232
+ audioPlaying = true ;
233
+ return true ;
162
234
}
163
235
164
236
void BoxDAC::generateFrequency (uint32_t frequency, uint16_t timeoutMs) {
@@ -167,15 +239,15 @@ void BoxDAC::generateFrequency(uint32_t frequency, uint16_t timeoutMs) {
167
239
timeout.setTimer (timeoutMs);
168
240
169
241
while (timeout.isRunning ()) {
170
- while (writeBuffer->position <writeBuffer->size && timeout.isRunning ()) {
242
+ while (writeBuffer->position <writeBuffer->size && timeout.isRunning ()) {
171
243
if (count % halfWavelength == 0 )
172
244
sample = -1 * sample; // invert the sample every half wavelength count multiple to generate square wave
173
- if (count % (2 *halfWavelength) == 0 )
245
+ if (count % (2 *halfWavelength) == 0 )
174
246
count = 0 ;
175
-
247
+
176
248
writeBuffer->buffer [writeBuffer->position ++] = sample;
177
249
writeBuffer->buffer [writeBuffer->position ++] = sample;
178
-
250
+
179
251
count++;
180
252
i2sElmCount++;
181
253
timeout.tick ();
@@ -196,7 +268,7 @@ void BoxDAC::generateZeroAudio(uint16_t timeoutMs) {
196
268
timeout.setTimer (timeoutMs);
197
269
198
270
while (timeout.isRunning ()) {
199
- while (writeBuffer->position <writeBuffer->size ) {
271
+ while (writeBuffer->position <writeBuffer->size ) {
200
272
writeBuffer->buffer [writeBuffer->position ++] = 0 ;
201
273
writeBuffer->buffer [writeBuffer->position ++] = 0 ;
202
274
}
@@ -216,7 +288,7 @@ void BoxDAC::dmaPingPingComplete() {
216
288
MAP_I2SIntClear (I2S_BASE, I2S_INT_XDMA);
217
289
218
290
unsigned long intStatus = MAP_uDMAIntStatus ();
219
-
291
+
220
292
dmaIRQcount++;
221
293
if (intStatus & 0x20 ) { // TX IRQ I2S_INT_XDMA?
222
294
unsigned long channelModePri = MAP_uDMAChannelModeGet (UDMA_CH5_I2S_TX | UDMA_PRI_SELECT);
@@ -335,11 +407,11 @@ void BoxDAC::beepRaw(uint16_t sin, uint16_t cos, uint32_t length, uint8_t volume
335
407
336
408
send (ADDR_P0_SERIAL::BEEP_R_GEN, 0x80 );
337
409
send (ADDR_P0_SERIAL::BEEP_L_GEN, 0x80 |(volume&0x3F )); // enable beep generator with right channel volume,
338
-
410
+
339
411
// send(ADDR_P0_SERIAL::DAC_NDAC_VAL, 0x84); //power up NDAC divider - Page 41 (but makes glitches?!)
340
412
341
413
send (ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x00 ); // unmute DACs optional
342
-
414
+
343
415
}
344
416
void BoxDAC::beepMidi (uint8_t midiId, uint16_t lengthMs, bool async) {
345
417
// TODO Check boundaries!
@@ -371,7 +443,7 @@ void BoxDAC::beepMidi(uint8_t midiId, uint16_t lengthMs, bool async) {
371
443
int32_t samples_opt = samplerate*(cycles)*100 /freq/2 ;
372
444
373
445
// int32_t samples = lengthMs * samplerate / 1000; //check length
374
- // Log.info("samplerate=%i, lengthMs=%i, freq=%i, sin=%i, cos=%i", samplerate, lengthMs, freq, sin, cos);
446
+ Log.info (" samplerate=%i, lengthMs=%i, freq=%i, sin=%i, cos=%i" , samplerate, lengthMs, freq, sin , cos );
375
447
// Log.info("samples=%i, cycles=%i, samples_opt=%i", samples, cycles, samples_opt);
376
448
377
449
beepRaw (sin , cos , samples_opt);
@@ -393,13 +465,13 @@ void BoxDAC::samSay(const char *text, enum ESP8266SAM::SAMVoice voice, uint8_t s
393
465
ESP8266SAM* sam = new ESP8266SAM ();
394
466
395
467
sam->SetVoice (voice);
396
- if (speed > 0 )
468
+ if (speed > 0 )
397
469
sam->SetSpeed (speed);
398
- if (pitch > 0 )
470
+ if (pitch > 0 )
399
471
sam->SetSpeed (pitch);
400
- if (throat > 0 )
472
+ if (throat > 0 )
401
473
sam->SetSpeed (throat);
402
- if (mouth > 0 )
474
+ if (mouth > 0 )
403
475
sam->SetSpeed (mouth);
404
476
sam->SetSingMode (sing);
405
477
sam->SetPhonetic (phoentic);
@@ -529,7 +601,7 @@ void BoxDAC::initDACI2C() {
529
601
// Extracted from logic analyzer capture of box
530
602
send (ADDR::PAGE_CONTROL, PAGE::SERIAL_IO);
531
603
send (ADDR_P0_SERIAL::SOFTWARE_RESET, 0x01 ); // Self-clearing software reset for control register
532
-
604
+
533
605
send (ADDR_P0_SERIAL::CLOCKGEN_MUX, 0x07 ); // 0000:reserved, 01:PLL_CLKIN=BCLK, 11:CODEC_CLKIN=PLL_CLK
534
606
send (ADDR_P0_SERIAL::PLL_J_VAL, 0x20 ); // 00:reserved, 100000:PLL multiplier J=32 (0x20)
535
607
send (ADDR_P0_SERIAL::PLL_D_VAL_MSB, 0x00 ); // 00:reserved, 000000:fraktional multiplier D-value = 0
@@ -541,7 +613,7 @@ void BoxDAC::initDACI2C() {
541
613
send (ADDR_P0_SERIAL::DAC_DOSR_VAL_LSB, 0x00 ); // 00000000:DAC OSR LSB
542
614
543
615
delay (10 ); // w PLL Start-Up
544
-
616
+
545
617
send (ADDR_P0_SERIAL::CODEC_IF_CTRL1, 0x00 ); // 00:Codec IF=I2S, 00: Codec IF WL=16 bits, 0:BCLK=Input, 0:WCKL=Output, 0:reserved // w IF statt INT
546
618
send (ADDR_P0_SERIAL::DAC_PROC_BLOCK_SEL, 0x19 ); // 000:reserved, 11001:DAC signal-processing block PRB_P25
547
619
@@ -560,12 +632,9 @@ void BoxDAC::initDACI2C() {
560
632
send (ADDR_P0_SERIAL::INT1_CTRL_REG, 0x80 ); // 1:Headset-insertion detect IRQ INT1, 0:Button-press detect, ...., 0=INT1 is only one pulse 2ms
561
633
send (ADDR_P0_SERIAL::GPIO1_INOUT_CTRL, 0x14 ); // XX:reserved, 0101:GPIO1=INT1 output, X=GPIO1 input buffer value, GPIO1 Output=X
562
634
563
-
564
-
565
635
// send(0x2E); Excel 161
566
636
567
637
// PAUSE 0,2s
568
-
569
638
// read 0x18 addr
570
639
571
640
@@ -585,8 +654,7 @@ void BoxDAC::initDACI2C() {
585
654
send (ADDR_P1_DAC_OUT::SPK_DRIVER, 0x00 ); // SPK driver is muted
586
655
587
656
send (ADDR_P1_DAC_OUT::SPK_DRIVER, 0x04 ); // an TEST gehört hier nicht hin
588
-
589
-
657
+
590
658
// PAUSE 50ms
591
659
delay (50 ); // w Ramp
592
660
@@ -599,7 +667,6 @@ void BoxDAC::initDACI2C() {
599
667
// PAUSE 50ms
600
668
delay (50 ); // w Ramp
601
669
602
-
603
670
send (ADDR_P1_DAC_OUT::HPL_DRIVER, 0x06 ); // HPL driver 0dB, not muted
604
671
send (ADDR_P1_DAC_OUT::HPR_DRIVER, 0x06 ); // HPR drvier 0dB, not muted
605
672
// send(ADDR_P1_DAC_OUT::HP_DRIVERS, 0xC2); // Falscher Wert must 1
@@ -621,7 +688,6 @@ void BoxDAC::initDACI2C() {
621
688
send (ADDR_P0_SERIAL::DAC_DATA_PATH_SETUP, 0xF1 ); // DAC power on, Left=left, Right=Right, DAC Softstep SPEAKER MONO
622
689
send (ADDR_P0_SERIAL::DAC_VOL_L_CTRL, 0xDC );
623
690
send (ADDR_P0_SERIAL::DAC_VOL_R_CTRL, 0xDC );
624
-
625
691
// Excel 219
626
692
// Extract END
627
693
send (ADDR::PAGE_CONTROL, PAGE::DAC_OUT_VOL);
0 commit comments