Skip to content

Commit bc66350

Browse files
committed
setTrue16Bits
1 parent 3ebb80d commit bc66350

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/sam_arduino.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ class SAM {
204204
}
205205
}
206206

207+
/// Enableds/disables the scaling to 16 bits - by default this is on
208+
void setTrue16Bits(bool active){
209+
true16Bins = active;
210+
}
211+
207212
/// Provides the sample rate (22050)
208213
static int sampleRate() {
209214
return SAMOutputBase::sampleRate();
@@ -213,6 +218,7 @@ class SAM {
213218
SAMOutputBase *arduino_output=nullptr;
214219
int bits_per_sample = 8;
215220
int channel_count = 1;
221+
bool true16Bins = true;
216222

217223
/// Used to feed the audio result back to this class
218224
static void outputByteCallback(void *cbdata, unsigned char b) {
@@ -253,10 +259,12 @@ class SAM {
253259
arduino_output->write((byte*)sample, channel_count);
254260
} else if (bits_per_sample==16) {
255261
int16_t s16 = b;
256-
// convert to signed
257-
s16 -= 128;
258-
// convert to int16
259-
s16 *= 128;
262+
if (true16Bins) {
263+
// convert to signed
264+
s16 -= 128;
265+
// convert to int16
266+
s16 *= 128;
267+
}
260268
int16_t sample[channel_count];
261269
for (int j=0;j<channel_count; j++){
262270
sample[j] = s16;

0 commit comments

Comments
 (0)