Skip to content

Commit 46d329e

Browse files
authored
Merge pull request #1429 from arduino/karlsoderby/giga-r1-audio-update
[GIGA R1] Audio Guide Update
2 parents 2ade31e + 7b646fa commit 46d329e

File tree

1 file changed

+33
-33
lines changed
  • content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-audio

1 file changed

+33
-33
lines changed

content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-audio/content.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ The following example shows how to output an 8kHz square wave on `DAC0`:
195195
// This example outputs an 8KHz square wave on A12/DAC0.
196196
#include <Arduino_AdvancedAnalog.h>
197197
198-
AdvancedDAC dac1(A12);
198+
AdvancedDAC dac0(A12);
199199
200200
void setup() {
201201
Serial.begin(9600);
@@ -204,8 +204,8 @@ void setup() {
204204
205205
}
206206
207-
if (!dac1.begin(AN_RESOLUTION_12, 8000, 32, 64)) {
208-
Serial.println("Failed to start DAC1 !");
207+
if (!dac0.begin(AN_RESOLUTION_12, 8000, 32, 64)) {
208+
Serial.println("Failed to start DAC0 !");
209209
while (1);
210210
}
211211
}
@@ -227,7 +227,7 @@ void dac_output_sq(AdvancedDAC &dac_out) {
227227
}
228228
229229
void loop() {
230-
dac_output_sq(dac1);
230+
dac_output_sq(dac0);
231231
}
232232
```
233233

@@ -239,8 +239,8 @@ It is also possible to simultaneously output at both DAC channels, `DAC0` and `D
239239
// This example outputs an 8KHz square wave on A12/DAC0 and 16KHz square wave on ADC13/DAC1.
240240
#include <Arduino_AdvancedAnalog.h>
241241
242-
AdvancedDAC dac1(A12);
243-
AdvancedDAC dac2(A13);
242+
AdvancedDAC dac0(A12);
243+
AdvancedDAC dac1(A13);
244244
245245
void setup() {
246246
Serial.begin(9600);
@@ -249,13 +249,13 @@ void setup() {
249249
250250
}
251251
252-
if (!dac1.begin(AN_RESOLUTION_12, 8000, 32, 64)) {
253-
Serial.println("Failed to start DAC1 !");
252+
if (!dac0.begin(AN_RESOLUTION_12, 8000, 32, 64)) {
253+
Serial.println("Failed to start DAC0 !");
254254
while (1);
255255
}
256256
257-
if (!dac2.begin(AN_RESOLUTION_12, 16000, 32, 64)) {
258-
Serial.println("Failed to start DAC2 !");
257+
if (!dac1.begin(AN_RESOLUTION_12, 16000, 32, 64)) {
258+
Serial.println("Failed to start DAC1 !");
259259
while (1);
260260
}
261261
}
@@ -277,8 +277,8 @@ void dac_output_sq(AdvancedDAC &dac_out) {
277277
}
278278
279279
void loop() {
280+
dac_output_sq(dac0);
280281
dac_output_sq(dac1);
281-
dac_output_sq(dac2);
282282
}
283283
```
284284

@@ -290,7 +290,7 @@ A 32kHz sine wave output on `DAC0` can be generated using the following example:
290290
// This example outputs a 32KHz sine wave on A12/DAC1.
291291
#include <Arduino_AdvancedAnalog.h>
292292
293-
AdvancedDAC dac1(A12);
293+
AdvancedDAC dac0(A12);
294294
295295
uint16_t lut[] = {
296296
0x0800,0x08c8,0x098f,0x0a52,0x0b0f,0x0bc5,0x0c71,0x0d12,0x0da7,0x0e2e,0x0ea6,0x0f0d,0x0f63,0x0fa7,0x0fd8,0x0ff5,
@@ -303,7 +303,7 @@ static size_t lut_size = sizeof(lut) / sizeof(lut[0]);
303303
304304
void setup() {
305305
Serial.begin(9600);
306-
if (!dac1.begin(AN_RESOLUTION_12, 32000 * lut_size, 64, 128)) {
306+
if (!dac0.begin(AN_RESOLUTION_12, 32000 * lut_size, 64, 128)) {
307307
Serial.println("Failed to start DAC1 !");
308308
while (1);
309309
}
@@ -312,17 +312,17 @@ void setup() {
312312
void loop() {
313313
static size_t lut_offs = 0;
314314
315-
if (dac1.available()) {
315+
if (dac0.available()) {
316316
// Get a free buffer for writing.
317-
SampleBuffer buf = dac1.dequeue();
317+
SampleBuffer buf = dac0.dequeue();
318318
319319
// Write data to buffer.
320320
for (size_t i=0; i<buf.size(); i++, lut_offs++) {
321321
buf[i] = lut[lut_offs % lut_size];
322322
}
323323
324324
// Write the buffer to DAC.
325-
dac1.write(buf);
325+
dac0.write(buf);
326326
}
327327
}
328328
```
@@ -346,7 +346,7 @@ The following example allows you to switch between several waveforms via a seria
346346
#define N_SAMPLES (256)
347347
#define DEFAULT_FREQUENCY (16000)
348348
349-
AdvancedDAC dac1(A12);
349+
AdvancedDAC dac0(A12);
350350
uint8_t SAMPLES_BUFFER[N_SAMPLES];
351351
size_t dac_frequency = DEFAULT_FREQUENCY;
352352
@@ -397,9 +397,9 @@ void generate_waveform(int cmd)
397397
break;
398398
}
399399
400-
dac1.stop();
400+
dac0.stop();
401401
delay(500);
402-
if (!dac1.begin(AN_RESOLUTION_8, dac_frequency * N_SAMPLES, N_SAMPLES, 32)) {
402+
if (!dac0.begin(AN_RESOLUTION_8, dac_frequency * N_SAMPLES, N_SAMPLES, 32)) {
403403
Serial.println("Failed to start DAC1 !");
404404
}
405405
delay(500);
@@ -434,7 +434,7 @@ void setup() {
434434
generate_waveform('s');
435435
436436
// DAC initialization
437-
if (!dac1.begin(AN_RESOLUTION_8, DEFAULT_FREQUENCY * N_SAMPLES, N_SAMPLES, 32)) {
437+
if (!dac0.begin(AN_RESOLUTION_8, DEFAULT_FREQUENCY * N_SAMPLES, N_SAMPLES, 32)) {
438438
Serial.println("Failed to start DAC1 !");
439439
while (1);
440440
}
@@ -448,16 +448,16 @@ void loop() {
448448
}
449449
}
450450
451-
if (dac1.available()) {
451+
if (dac0.available()) {
452452
// Get a free buffer for writing.
453-
SampleBuffer buf = dac1.dequeue();
453+
SampleBuffer buf = dac0.dequeue();
454454
455455
// Write data to buffer.
456456
for (size_t i=0; i<buf.size(); i++) {
457457
buf[i] = SAMPLES_BUFFER[i];
458458
}
459459
460-
dac1.write(buf);
460+
dac0.write(buf);
461461
}
462462
}
463463
```
@@ -510,7 +510,7 @@ Note that to start the sketch, you need to open Serial Monitor due to the `while
510510
#include <Arduino_USBHostMbed5.h>
511511
#include <FATFileSystem.h>
512512
513-
AdvancedDAC dac1(A12);
513+
AdvancedDAC dac0(A12);
514514
515515
USBHostMSD msd;
516516
mbed::FATFileSystem usb("USB_DRIVE");
@@ -625,7 +625,7 @@ void setup()
625625
snprintf(msg, sizeof(msg), "Samples count = %i", samples_count); Serial.println(msg);
626626
627627
/* Configure the advanced DAC. */
628-
if (!dac1.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16))
628+
if (!dac0.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16))
629629
{
630630
Serial.println("Failed to start DAC1 !");
631631
return;
@@ -634,14 +634,14 @@ void setup()
634634
635635
void loop()
636636
{
637-
if (dac1.available() && !feof(file))
637+
if (dac0.available() && !feof(file))
638638
{
639639
/* Read data from file. */
640640
uint16_t sample_data[256] = {0};
641641
fread(sample_data, sample_size, 256, file);
642642
643643
/* Get a free buffer for writing. */
644-
SampleBuffer buf = dac1.dequeue();
644+
SampleBuffer buf = dac0.dequeue();
645645
646646
/* Write data to buffer. */
647647
for (size_t i = 0; i < buf.size(); i++)
@@ -652,7 +652,7 @@ void loop()
652652
}
653653
654654
/* Write the buffer to DAC. */
655-
dac1.write(buf);
655+
dac0.write(buf);
656656
}
657657
}
658658
```
@@ -684,7 +684,7 @@ You can download them from [this link](/resources/misc/giga_audio_examples.zip).
684684
#include <Arduino_USBHostMbed5.h>
685685
#include <FATFileSystem.h>
686686
687-
AdvancedDAC dac1(A12);
687+
AdvancedDAC dac0(A12);
688688
689689
USBHostMSD msd;
690690
mbed::FATFileSystem usb("usb");
@@ -719,13 +719,13 @@ void setup() {
719719
}
720720
721721
void loop() {
722-
if (dac1.available() && !feof(file)) {
722+
if (dac0.available() && !feof(file)) {
723723
/* Read data from file. */
724724
uint16_t sample_data[256] = { 0 };
725725
fread(sample_data, sample_size, 256, file);
726726
727727
/* Get a free buffer for writing. */
728-
SampleBuffer buf = dac1.dequeue();
728+
SampleBuffer buf = dac0.dequeue();
729729
730730
/* Write data to buffer. */
731731
for (size_t i = 0; i < buf.size(); i++) {
@@ -735,7 +735,7 @@ void loop() {
735735
}
736736
737737
/* Write the buffer to DAC. */
738-
dac1.write(buf);
738+
dac0.write(buf);
739739
740740
if(feof(file)){
741741
fclose(file);
@@ -851,7 +851,7 @@ void configFile() {
851851
Serial.println(msg);
852852
853853
/* Configure the advanced DAC. */
854-
if (!dac1.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16)) {
854+
if (!dac0.begin(AN_RESOLUTION_12, header.sampleRate, 256, 16)) {
855855
Serial.println("Failed to start DAC1 !");
856856
return;
857857
}

0 commit comments

Comments
 (0)