generating complementary PWM instead of DAC using the audio data #452
-
after getting the data, how can I generate PWM using it instead of DAC?
// In the setup function:
a2dp_sink.set_stream_reader(read_data_stream);
// Then somewhere in your sketch:
void read_data_stream(const uint8_t *data, uint32_t length)
{
int16_t *samples = (int16_t*) data;
uint32_t sample_count = length/2;
// Do something with the data packet
} |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Just use the AudioTools project (as suggested in the documentation). |
Beta Was this translation helpful? Give feedback.
-
That would be your starting point: Not sure what the best approach for the phase shift is: you might want to implement this using some digital filters. There is a chapter in the Wiki. |
Beta Was this translation helpful? Give feedback.
-
First thought: did you adjust the volume on your phone. |
Beta Was this translation helpful? Give feedback.
-
Just one more question: I don't quite understand your statement 'power supply whose output is modulated by the audio signal'. Do you really need to have a resolution of 44100 updates per second to adjust your power supply ? |
Beta Was this translation helpful? Give feedback.
-
This confirms my suspicion: I think the low resolution, high sampling rate approach of the PWMStream does not help you at all. You want to update your voltage based on the actual volume and not based on the individual audio waves! |
Beta Was this translation helpful? Give feedback.
Just use the AudioTools project (as suggested in the documentation).
In the basic-api-exmples you can find an a2dp example which outputs to i2s. Just use the https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_p_w_m_audio_output.html as output class instead.