update i2s write fn
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
AudioOutputI2S
|
AudioOutputI2S
|
||||||
Base class for I2S interface port
|
Base class for I2S interface port
|
||||||
|
|
||||||
Copyright (C) 2017 Earle F. Philhower, III
|
Copyright (C) 2017 Earle F. Philhower, III
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include "driver/i2s.h"
|
#include "driver/i2s.h"
|
||||||
#elif defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
|
#elif defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
|
||||||
#include <I2S.h>
|
#include <i2s.h>
|
||||||
#endif
|
#endif
|
||||||
#include "AudioOutputI2S.h"
|
#include "AudioOutputI2S.h"
|
||||||
|
|
||||||
@@ -269,7 +269,11 @@ bool AudioOutputI2S::ConsumeSample(int16_t sample[2])
|
|||||||
{
|
{
|
||||||
s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
|
s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
|
||||||
}
|
}
|
||||||
return i2s_write_bytes((i2s_port_t)portNo, (const char *)&s32, sizeof(uint32_t), 0);
|
// Deprecated. Use i2s_write
|
||||||
|
// return i2s_write_bytes((i2s_port_t)portNo, (const char *)&s32, sizeof(uint32_t), 0);
|
||||||
|
size_t bytes_written;
|
||||||
|
i2s_write((i2s_port_t)portNo, (const char*)&s32, sizeof(uint32_t), &bytes_written, 0);
|
||||||
|
return bytes_written;
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
|
uint32_t s32 = ((Amplify(ms[RIGHTCHANNEL])) << 16) | (Amplify(ms[LEFTCHANNEL]) & 0xffff);
|
||||||
return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true
|
return i2s_write_sample_nb(s32); // If we can't store it, return false. OTW true
|
||||||
@@ -308,4 +312,4 @@ bool AudioOutputI2S::stop()
|
|||||||
#endif
|
#endif
|
||||||
i2sOn = false;
|
i2sOn = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
AudioOutputI2SNoDAC
|
AudioOutputI2SNoDAC
|
||||||
Audio player using SW delta-sigma to generate "analog" on I2S data
|
Audio player using SW delta-sigma to generate "analog" on I2S data
|
||||||
|
|
||||||
Copyright (C) 2017 Earle F. Philhower, III
|
Copyright (C) 2017 Earle F. Philhower, III
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include "driver/i2s.h"
|
#include "driver/i2s.h"
|
||||||
#elif defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
|
#elif defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
|
||||||
#include <I2S.h>
|
#include <i2s.h>
|
||||||
#endif
|
#endif
|
||||||
#include "AudioOutputI2SNoDAC.h"
|
#include "AudioOutputI2SNoDAC.h"
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ void AudioOutputI2SNoDAC::DeltaSigma(int16_t sample[2], uint32_t dsBuff[8])
|
|||||||
|
|
||||||
for (int j = 0; j < oversample32; j++) {
|
for (int j = 0; j < oversample32; j++) {
|
||||||
uint32_t bits = 0; // The bits we convert the sample into, MSB to go on the wire first
|
uint32_t bits = 0; // The bits we convert the sample into, MSB to go on the wire first
|
||||||
|
|
||||||
for (int i = 32; i > 0; i--) {
|
for (int i = 32; i > 0; i--) {
|
||||||
bits = bits << 1;
|
bits = bits << 1;
|
||||||
if (cumErr < 0) {
|
if (cumErr < 0) {
|
||||||
@@ -95,7 +95,11 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
|
|||||||
|
|
||||||
// Either send complete pulse stream or nothing
|
// Either send complete pulse stream or nothing
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
if (!i2s_write_bytes((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), 0))
|
// Deprecated. Use i2s_write
|
||||||
|
// if (!i2s_write_bytes((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), 0))
|
||||||
|
size_t bytes_written;
|
||||||
|
i2s_write((i2s_port_t)portNo, (const char *)dsBuff, sizeof(uint32_t) * (oversample/32), &bytes_written, 0);
|
||||||
|
if (!bytes_written)
|
||||||
return false;
|
return false;
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
if (!i2s_write_sample_nb(dsBuff[0])) return false; // No room at the inn
|
if (!i2s_write_sample_nb(dsBuff[0])) return false; // No room at the inn
|
||||||
@@ -110,4 +114,4 @@ bool AudioOutputI2SNoDAC::ConsumeSample(int16_t sample[2])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user