Skip to content

Commit 22d3c7d

Browse files
committed
bug in synchronization of audio data with stream
1 parent 06465f3 commit 22d3c7d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/sam_arduino.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ class SAM {
5959
setVoice(Sam);
6060
}
6161

62+
/// Constructor - for output with a SAMOutputBase class
63+
SAM(SAMOutputBase &out){
64+
SAM_LOG("SAM SAMOutputBase");
65+
setOutput(&out);
66+
setVoice(Sam);
67+
}
68+
6269
/// Constructor - for output with a SAMOutputBase class
6370
SAM(SAMOutputBase *out){
6471
SAM_LOG("SAM SAMOutputBase");
@@ -209,11 +216,20 @@ class SAM {
209216
true16Bits = active;
210217
}
211218

212-
/// Provides the sample rate (22050)
219+
/// Provides the sample rate (44100)
213220
static int sampleRate() {
214221
return SAMOutputBase::sampleRate();
215222
}
216223

224+
225+
int bitsPerSample() {
226+
return bits_per_sample;
227+
}
228+
229+
int channels() {
230+
return channel_count;
231+
}
232+
217233
protected:
218234
SAMOutputBase *arduino_output=nullptr;
219235
int bits_per_sample = 8;
@@ -232,12 +248,16 @@ class SAM {
232248
SAM_LOG("setOutput");
233249
arduino_output = out;
234250

235-
// force output definition as defined in arduino_output
251+
// synchronize output definition with arduino_output
236252
if (arduino_output->channels()!=-1){
237253
this->channel_count = arduino_output->channels();
254+
} else {
255+
arduino_output->setChannels(channel_count);
238256
}
239257
if (arduino_output->bitsPerSample()!=-1){
240258
this->bits_per_sample = arduino_output->bitsPerSample();
259+
} else {
260+
arduino_output->setBitsPerSample(bits_per_sample);
241261
}
242262
SAM_LOG("-> channel_count: %d",this->channel_count);
243263
SAM_LOG("-> bits_per_sample: %d",this->bits_per_sample);

src/sam_arduino_out.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef void (*sam_callback)(size_t size, void *values);
2424

2525
// Application Callback
2626
static void OutputByteCallback(void *cbdata, unsigned char b);
27-
static uint32_t SAM_sample_rate = 44100;
27+
static uint32_t SAM_sample_rate = 22050;
2828
/**
2929
* @brief Base Output Class with common functionality
3030
*

0 commit comments

Comments
 (0)