arduino-audio-tools
AudioRuntime.h
1 #pragma once
2 
3 #include "AudioConfig.h"
4 
5 
6 #if defined(ESP32_CMAKE) && !defined(ARDUINO)
7 #include "freertos/FreeRTOS.h"
8 #include "freertos/task.h"
9 // delay and millis is needed by this framework
10 #define DESKTOP_MILLIS_DEFINED
11 
12 inline void delay(uint32_t ms){ vTaskDelay(ms / portTICK_PERIOD_MS);}
13 inline uint32_t millis() {return (xTaskGetTickCount() * portTICK_PERIOD_MS);}
14 inline void delayMicroseconds(uint32_t ms) {esp_rom_delay_us(ms);}
15 inline uint64_t micros() { return xTaskGetTickCount() * portTICK_PERIOD_MS * 1000;}
16 
17 #endif
18 
19 namespace audio_tools {
20 
28 inline void stop() {
29  #ifdef EXIT_ON_STOP
30  exit(0);
31  #else
32  while(true){
33  delay(1000);
34  }
35  #endif
36 }
37 
39 inline static void checkMemory(bool memoryCheck=false) {
40  #if defined(ESP32) && defined(ARDUINO)
41  assert(heap_caps_check_integrity_all(true));
42  if (memoryCheck) printf("==> Available stack: %d - heap: %u\n",(int) uxTaskGetStackHighWaterMark(NULL), (unsigned)ESP.getFreeHeap());
43  #endif
44 }
45 
46 #ifdef ARDUINO
47 inline void printNChar(char ch, int n){
48  for (int j=0;j<n;j++) Serial.print(ch);
49  Serial.println();
50 }
51 
52 #ifndef ESP_ARDUINO_VERSION_STR
53 # define df2xstr(s) #s
54 # define df2str(s) df2xstr(s)
55 # define ESP_ARDUINO_VERSION_STR df2str(ESP_ARDUINO_VERSION_MAJOR) "." df2str(ESP_ARDUINO_VERSION_MINOR) "." df2str(ESP_ARDUINO_VERSION_PATCH)
56 #endif
57 
59 inline void printVersionInfo() {
60  printNChar('*',50);
61  Serial.print("AudioTools: ");
62  Serial.println(AUDIOTOOLS_VERSION);
63  Serial.print("Arduino: ");
64  Serial.println(ARDUINO);
65 #ifdef ESP32
66  Serial.print("Arduino ESP Core Version: ");
67  Serial.println(ESP_ARDUINO_VERSION_STR);
68  Serial.print("IDF Version: ");
69  Serial.println(IDF_VER);
70 #endif
71  printNChar('*',50);
72 }
73 
74 #endif
75 
76 }
static void checkMemory(bool memoryCheck=false)
Executes heap_caps_check_integrity_all()
Definition: AudioRuntime.h:39
void stop()
Public generic methods.
Definition: AudioRuntime.h:28
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition: AudioConfig.h:872
uint32_t millis()
Returns the milliseconds since the start.
Definition: Time.h:12