Skip to content

Commit d988917

Browse files
committed
Update PWM readme
1 parent 00437bc commit d988917

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ As “Audio Sinks” we will have e.g:
3131

3232
- external DAC – [I2SStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_i2_s_stream.html)
3333
- an Amplifier – [AnalogAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_analog_audio_stream.html)
34-
- Earphones – [PWMAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_pwm_audio_stream.html)
34+
- Earphones – [PWMAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_p_w_m_audio_stream_e_s_p32.html)
3535
- Bluetooth Speakers – [A2DPStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_a2_d_p_stream.html)
3636
- Serial to display the data as CSV – [CsvStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_csv_stream.html)
3737
- Any other Arduino Classes implementing Streams: SD, Ethernet etc

src/AudioPWM/PWMforESP32.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
#include "AudioTools/AudioLogger.h"
66
#include "AudioTools/Vector.h"
77
#include "Stream.h"
8-
#include <math.h> /* pow */
8+
#include <math.h>
99

1010
namespace audio_tools {
1111

1212
// forward declaration
13-
class AudioPWM;
13+
class PWMAudioStreamESP32;
14+
typedef PWMAudioStreamESP32 AudioPWM;
1415
void defaultPWMAudioOutputCallback();
15-
static AudioPWM *accessAudioPWM = nullptr;
16+
static PWMAudioStreamESP32 *accessAudioPWM = nullptr;
1617

1718
/**
1819
* @brief Configuration for PWM output
@@ -30,7 +31,7 @@ static AudioPWM *accessAudioPWM = nullptr;
3031
3132
*/
3233

33-
struct PWMConfig {
34+
struct PWMConfigESP32 {
3435
int sample_rate = 10000; // sample rate in Hz
3536
int channels = 2;
3637
int start_pin = 3;
@@ -39,28 +40,33 @@ struct PWMConfig {
3940
int resolution = 8; // must be between 8 and 11 -> drives pwm frequency
4041
} default_config;
4142

43+
typedef PWMConfigESP32 PWMConfig;
44+
4245
/**
4346
* @brief Information for a PIN
4447
* @author Phil Schatzmann
4548
* @copyright GPLv3
4649
*/
47-
struct PINInfo {
50+
struct PinInfoESP32 {
4851
int pwm_channel;
4952
int gpio;
5053
};
5154

55+
typedef PinInfoESP32 PinInfo;
56+
57+
5258
/**
5359
* @brief Audio output to PWM pins for the ESP32. The ESP32 supports up to 16 channels.
5460
* @author Phil Schatzmann
5561
* @copyright GPLv3
5662
*/
5763

58-
class PWMAudioStream : public Stream {
59-
friend void defaultAudioOutputCallback();
64+
class PWMAudioStreamESP32 : public Stream {
65+
friend void defaultPWMAudioOutputCallback();
6066

6167
public:
6268

63-
PWMAudioStream(){
69+
PWMAudioStreamESP32(){
6470
accessAudioPWM = this;
6571
}
6672

@@ -167,7 +173,7 @@ class PWMAudioStream : public Stream {
167173

168174
protected:
169175
PWMConfig audio_config;
170-
Vector<PINInfo> pins;
176+
Vector<PinInfo> pins;
171177
NBuffer<uint8_t> buffer = NBuffer<uint8_t>(PWM_BUFFER_SIZE, PWM_BUFFERS);
172178
hw_timer_t * timer = nullptr;
173179
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

src/AudioPWM/PWMforPico.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
namespace audio_tools {
1616

1717
// forwrd declaratioin of callback
18+
class PWMAudioStreamPico;
1819
bool defaultAudioOutputCallback(repeating_timer* ptr);
20+
typedef PWMAudioStreamESP32 AudioPWM;
1921

2022
/**
2123
* @brief Rasperry Pico Channel to pin assignments
@@ -34,7 +36,7 @@ struct PicoChannelOut {
3436
* @author Phil Schatzmann
3537
* @copyright GPLv3
3638
*/
37-
struct PWMConfig {
39+
struct PWMConfigPico {
3840
int sample_rate = 10000; // sample rate in Hz
3941
int channels = 2;
4042
int pwm_freq = 60000; // audable range is from 20 to 20,000Hz
@@ -43,6 +45,8 @@ struct PWMConfig {
4345
int start_pin = 2; // channel 0 will be on gpio 2, channel 1 on 3 etc
4446
} default_config;
4547

48+
typedef PWMConfigPico PWMConfig;
49+
4650
/**
4751
* @brief Audio output for the Rasperry Pico to PWM pins
4852
* @author Phil Schatzmann
@@ -51,12 +55,12 @@ struct PWMConfig {
5155
*/
5256

5357
template <class T>
54-
class PWMAudioStream : public Stream {
58+
class PWMAudioStreamPico : public Stream {
5559
friend bool defaultAudioOutputCallback(repeating_timer* ptr);
5660

5761
public:
5862

59-
PWMAudioStream(){
63+
PWMAudioStreamPico(){
6064
T amplitude_in = getDefaultAmplitude();
6165
audio_config.amplitude_in = amplitude_in;
6266
default_config.amplitude_in = amplitude_in;

0 commit comments

Comments
 (0)