Skip to content

Commit f067742

Browse files
committed
cleanup CodecConfig
1 parent 76aa336 commit f067742

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/Driver.h

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ class CodecConfig : public codec_config_t {
6868
return 0;
6969
}
7070

71-
// sets the bits per sample with a numeric value
72-
int setBitsNumeric(int bits) {
71+
/// Sets the bits per sample with a numeric value
72+
bool setBitsNumeric(int bits) {
7373
switch (bits) {
7474
case 16:
7575
i2s.bits = BIT_LENGTH_16BITS;
76-
return bits;
76+
return true;
7777
case 18:
7878
i2s.bits = BIT_LENGTH_18BITS;
79-
return bits;
79+
return true;
8080
case 20:
8181
i2s.bits = BIT_LENGTH_20BITS;
82-
return bits;
82+
return true;
8383
case 24:
8484
i2s.bits = BIT_LENGTH_24BITS;
85-
return bits;
85+
return true;
8686
case 32:
8787
i2s.bits = BIT_LENGTH_32BITS;
88-
return bits;
88+
return true;
8989
}
90-
return 0;
90+
return false;
9191
}
9292

9393
/// get the sample rate as number
@@ -103,26 +103,41 @@ class CodecConfig : public codec_config_t {
103103

104104
int getChannelsNumeric() { return i2s.channels; }
105105

106-
void setChannelsNumeric(int channels) { i2s.channels = (channels_t)channels; }
106+
bool setChannelsNumeric(int channels) {
107+
switch(2){
108+
case CHANNELS2:
109+
i2s.channels = (channels_t)channels;
110+
return true;
111+
case CHANNELS8:
112+
i2s.channels = (channels_t)channels;
113+
return true;
114+
case CHANNELS16:
115+
i2s.channels = (channels_t)channels;
116+
return true;
117+
default:
118+
i2s.channels = CHANNELS2;
119+
return false;
120+
}
121+
}
107122

108-
/// sets the sample rate as number
109-
int setRateNumeric(int rateNum) {
123+
/// sets the sample rate as number: returns the effectively set rate
124+
int setRateNumeric(int requestedRate) {
110125
int diff = 99999;
111126
int result = 0;
112127
for (int j = 0; j < 14; j++) {
113-
if (rate_num[j] == rateNum) {
128+
if (rate_num[j] == requestedRate) {
114129
AD_LOGD("-> %d", rate_num[j]);
115130
i2s.rate = rate_code[j];
116-
return rateNum;
131+
return requestedRate;
117132
} else {
118-
int new_diff = abs(rate_code[j] - rateNum);
133+
int new_diff = abs(rate_code[j] - requestedRate);
119134
if (new_diff < diff) {
120135
result = j;
121136
diff = new_diff;
122137
}
123138
}
124139
}
125-
AD_LOGE("Sample Rate not supported: %d - using %d", rateNum,
140+
AD_LOGE("Sample Rate not supported: %d - using %d", requestedRate,
126141
rate_num[result]);
127142
i2s.rate = rate_code[result];
128143
return rate_num[result];

0 commit comments

Comments
 (0)