Skip to content

Commit 5a2c200

Browse files
committed
bug fix and add sketch
1 parent 05d9455 commit 5a2c200

File tree

8 files changed

+276
-2
lines changed

8 files changed

+276
-2
lines changed

libraries/I2C/examples/I2CAdresTespiti/I2CAdresTespiti.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void loop()
2020

2121
Serial.println("taranıyor...");
2222
nDevices = 0;
23-
for(address = 1; address < 127; address++ )
23+
for(address = 1; address <= 127; address++ )
2424
{
2525
Wire.beginTransmission(address);
2626
error = Wire.endTransmission();

libraries/KutuAcilisUygulamalari/examples/KameraYayini/app_httpd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static esp_err_t index_handler(httpd_req_t *req){
584584
sensor_t * s = esp_camera_sensor_get();
585585
return httpd_resp_send(req, (const char *)index_ov2640_html_gz, index_ov2640_html_gz_len);
586586
}
587-
#if defined (ARDUINO_DYDK)
587+
#if defined (ARDUINO_DYDK) || defined (ARDUINO_DYDK1A)
588588
void startCameraServer(){
589589
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
590590

libraries/Mikrofon/examples/SesSeviyesiAlgilama/SesSeviyesiAlgilama.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* SesSeviyesiAlgilama örneği,
33
* Deneyap Karttaki dahili mikrofon ile kullanıcı ortamdaki ses verisini seri terminalde gözlemlemektedir.
44
* Karttaki mavi led ve D0 harici bağlanan ledler belirlenen değere göre yanıp sönmektedir.
5+
* Ses değişimini SERİ PORT ekranında grafiksel olarak izlenmelidir.
56
*
67
* Bu uygulama Deneyap Kart 1A ve Deneyap Mini Kartları ile gerçekleştirilmek istenirse harici mikrofon bağlanmalıdır ve gerekli bağlantı bilgileri değiştirilmelidir.
78
*
6.38 MB
Binary file not shown.
12.8 MB
Binary file not shown.
23.5 MB
Binary file not shown.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* SD Karttan .wav uzantılı ses dosyasını DAC pinleri ile çalma örneği.
3+
* Örnekte çalınan ses dosyaları örneğin yer aldığı klasörün içinde yer almaktadır.
4+
* Seri terminale yazılan sayıya karşılık gelen ses dosyasını çalmaktadır.
5+
* Oynatılan seslerin khz, sample değerleri farklıdır.
6+
* DENEYAP HOPARLÖR ile kullanılabilir.
7+
*
8+
* DENEYAP MİNİ kartını desteklememektedir.
9+
*/
10+
11+
#include <SPI.h>
12+
#include <SD.h>
13+
#include "AutoAnalogAudio.h"
14+
15+
#define AUDIO_DEBUG
16+
uint32_t adcReadings = MAX_BUFFER_SIZE;
17+
bool doADC = false;
18+
bool firstADC = false;
19+
20+
AutoAnalog aaAudio;
21+
File myFile;
22+
23+
#include "WAV.h"
24+
25+
void setup() {
26+
Serial.begin(115200);
27+
SPI.begin();
28+
/* SPI.begin(D15, D9, D14, D13); //DENEYAP KART'ta bu pinler ile kullanın
29+
pinMode(D9,INPUT_PULLUP); // SCK: D15, MISO: D9, MOSI: D14, SS: D13 */
30+
if (!SDCard.begin()) {
31+
Serial.println("SD bağlantısı başarısız!");
32+
}else
33+
Serial.println("SD bağlantısı başarılı");
34+
aaAudio.begin(1, 1);
35+
aaAudio.autoAdjust = 0;
36+
aaAudio.setSampleRate(80000);
37+
aaAudio.dacBitsPerSample = 8;
38+
}
39+
40+
uint8_t count = 0;
41+
uint32_t printTimer = millis();
42+
43+
uint32_t adcTimer = 0;
44+
bool doExtADC = false;
45+
bool doSine = false;
46+
47+
uint32_t testCounter = 0;
48+
49+
void loop() {
50+
if (doADC) {
51+
aaAudio.getADC(adcReadings);
52+
if (!firstADC) {
53+
for (int i = 0; i < adcReadings; i++) {
54+
int16_t tmpVar = (int16_t)aaAudio.adcBuffer16[i] - 0x800;
55+
//aaAudio.dacBuffer[i] = aaAudio.adcBuffer16[i];
56+
}
57+
aaAudio.feedDAC(0, adcReadings);
58+
} else {
59+
firstADC = false;
60+
memset(aaAudio.dacBuffer, 0, MAX_BUFFER_SIZE);
61+
aaAudio.feedDAC(0, MAX_BUFFER_SIZE);
62+
aaAudio.feedDAC(0, MAX_BUFFER_SIZE);
63+
}
64+
}
65+
if (doSine) {
66+
aaAudio.feedDAC(0, 32);
67+
}
68+
if (Serial.available()) {
69+
char input = Serial.read();
70+
switch (input) {
71+
/*Ses dosyaları: https://github.com/deneyapkart/deneyapkart-arduino-core/tree/master/libraries/SPI/examples/SDKarttanSesCalma */
72+
case '1': playAudio("/M8b24kM.wav"); break; // 8bit, 24khz, Mono
73+
case '2': playAudio("/M8b24kS.wav"); break; // 8bit, 24khz, Stereo
74+
case '3': playAudio("/M8b44kST.wav"); break; // 8bit, 44khz, Mono
75+
case '4': Serial.println("Tamam"); break;
76+
}
77+
}
78+
if (!useTasks) {
79+
DACC_Handler();
80+
}
81+
if (millis() - printTimer > 500) {
82+
printTimer = millis();
83+
Serial.print(".");
84+
count++;
85+
if (count >= 50) {
86+
count = 0;
87+
Serial.println("");
88+
}
89+
}
90+
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
2+
uint8_t channelSelection = 2;
3+
uint32_t loadBuffer();
4+
//Use FreeRTOS Tasks to load data and feed into the DAC, false to handle from main loop
5+
bool useTasks = true;
6+
7+
void DACC_Handler(void) {
8+
aaAudio.dacHandler(); //Link the DAC ISR/IRQ to the library. Called by the MCU when DAC is ready for data
9+
uint32_t samples = loadBuffer();
10+
if (samples) {
11+
aaAudio.feedDAC(channelSelection, samples);
12+
}
13+
14+
}
15+
16+
/*********************************************************/
17+
/* Function to open the audio file, seek to starting position and enable the DAC */
18+
uint32_t endPosition = 0;
19+
20+
void playAudio(const char *audioFile) {
21+
22+
uint32_t sampleRate = 16000;
23+
uint16_t numChannels = 1;
24+
uint16_t bitsPerSample = 8;
25+
uint32_t dataSize = 0;
26+
uint32_t startPosition = 44;
27+
28+
Serial.println("Play");
29+
30+
if (myFile) {
31+
Serial.println("Close Current");
32+
//Ramp in and ramp out functions prevent popping and clicking when starting/stopping playback
33+
aaAudio.rampOut(0);
34+
aaAudio.disableDAC();
35+
myFile.close();
36+
}
37+
38+
//Open the designated file
39+
myFile = SDCard.open(audioFile);
40+
if (myFile) {
41+
myFile.seek(22);
42+
myFile.read((byte*)&numChannels, 2);
43+
myFile.read((byte*)&sampleRate, 4);
44+
myFile.seek(34);
45+
myFile.read((byte*)&bitsPerSample, 2);
46+
myFile.seek(40);
47+
myFile.read((byte*)&dataSize, 4);
48+
endPosition = dataSize + 44;
49+
50+
#if defined (AUDIO_DEBUG)
51+
Serial.print("\nNow Playing ");
52+
Serial.println(audioFile);
53+
Serial.print("Channels ");
54+
Serial.print(numChannels);
55+
Serial.print(", SampleRate ");
56+
Serial.print(sampleRate);
57+
Serial.print(", BitsPerSample ");
58+
Serial.println(bitsPerSample);
59+
#endif
60+
61+
if (myFile.size() > endPosition) {
62+
//startPosition = myFile.size() - dataSize;
63+
endPosition = dataSize + 44;
64+
myFile.seek(endPosition);
65+
uint8_t buf[myFile.size() - (endPosition)];
66+
myFile.read(buf, myFile.size() - (endPosition));
67+
Serial.println("Metadata:");
68+
Serial.println(myFile.size() - (endPosition));
69+
for (int i = 0; i < myFile.size() - (endPosition); i++) {
70+
Serial.print((char)buf[i]);
71+
}
72+
Serial.println();
73+
}
74+
75+
if (bitsPerSample > 12) {
76+
bitsPerSample = 16;
77+
} else if (bitsPerSample > 10 ) {
78+
bitsPerSample = 12;
79+
} else if (bitsPerSample > 8) {
80+
bitsPerSample = 10;
81+
} else {
82+
bitsPerSample = 8;
83+
}
84+
85+
sampleRate *= numChannels;
86+
Serial.print("SampleRate ");
87+
Serial.println(sampleRate);
88+
Serial.println("Set smp rate");
89+
bool stereo = numChannels > 1 ? true : false;
90+
aaAudio.setSampleRate(sampleRate, stereo);
91+
aaAudio.dacBitsPerSample = bitsPerSample;
92+
93+
#if defined (AUDIO_DEBUG)
94+
Serial.print("Timer Rate ");
95+
Serial.print(sampleRate);
96+
Serial.print(", DAC Bits Per Sample ");
97+
Serial.println(bitsPerSample);
98+
#endif
99+
100+
//Skip past the WAV header
101+
myFile.seek(startPosition);
102+
103+
104+
//Load one buffer
105+
loadBuffer();
106+
//Feed the DAC to start playback
107+
108+
if (aaAudio.dacBitsPerSample == 8) {
109+
aaAudio.rampIn(aaAudio.dacBuffer[0]);
110+
} else {
111+
aaAudio.rampIn((uint8_t)aaAudio.dacBuffer16[0]);
112+
}
113+
114+
aaAudio.feedDAC(channelSelection, MAX_BUFFER_SIZE, useTasks);
115+
116+
} else {
117+
#if defined (AUDIO_DEBUG)
118+
Serial.print("Failed to open ");
119+
Serial.println(audioFile);
120+
#endif
121+
}
122+
}
123+
124+
/*********************************************************/
125+
/* Function called from DAC interrupt after dacHandler(). Loads data into the dacBuffer */
126+
127+
uint32_t loadBuffer() {
128+
129+
uint32_t samplesToRead = 0;
130+
uint32_t metaDataSize = myFile.size() - endPosition;
131+
132+
133+
if (myFile) {
134+
if (myFile.available() > metaDataSize + 1 ) {
135+
samplesToRead = MAX_BUFFER_SIZE;
136+
size_t availableBytes = 0;
137+
138+
if (aaAudio.dacBitsPerSample == 8) {
139+
//Load 32 samples into the 8-bit dacBuffer
140+
if ( (availableBytes = (myFile.available() - metaDataSize)) <= samplesToRead) {
141+
samplesToRead = availableBytes;
142+
Serial.print("File Size ");
143+
Serial.print(myFile.size());
144+
Serial.print(" Bytes Read ");
145+
Serial.println(myFile.position() + samplesToRead);
146+
}
147+
myFile.read(aaAudio.dacBuffer, samplesToRead);
148+
for (int i = 0; i < samplesToRead; i++) {
149+
int16_t tmpVar = (uint16_t)aaAudio.dacBuffer[i] - 0x80;
150+
}
151+
152+
} else {
153+
if ( (availableBytes = (myFile.available() - metaDataSize)) <= (samplesToRead * 2) ) {
154+
samplesToRead = availableBytes / 2;
155+
Serial.print("File Size16 ");
156+
Serial.print(myFile.size());
157+
Serial.print(" Bytes Read ");
158+
Serial.println(myFile.position() + availableBytes);
159+
}
160+
//Load 32 samples (64 bytes) into the 16-bit dacBuffer
161+
int16_t tmpBuffer[samplesToRead];
162+
myFile.read((byte*)tmpBuffer, samplesToRead * 2);
163+
}
164+
} else {
165+
#if defined (AUDIO_DEBUG)
166+
Serial.print("Close: ");
167+
#endif
168+
//aaAudio.disableDAC();
169+
//aaAudio.dacInterrupts(false);
170+
171+
Serial.println("File close");
172+
myFile.close();
173+
Serial.print("Dis DAC, ");
174+
aaAudio.rampOut(0);
175+
//If using tasks, disabling the active task and DAC will be done from within the task itself
176+
//Need to let aaAudio know by setting the parameter to 'true'. Using useTasks variable
177+
aaAudio.disableDAC(useTasks);
178+
}
179+
}
180+
return samplesToRead;
181+
}
182+
183+
/*********************************************************/

0 commit comments

Comments
 (0)