@@ -68,26 +68,26 @@ class CodecConfig : public codec_config_t {
68
68
return 0 ;
69
69
}
70
70
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) {
73
73
switch (bits) {
74
74
case 16 :
75
75
i2s.bits = BIT_LENGTH_16BITS;
76
- return bits ;
76
+ return true ;
77
77
case 18 :
78
78
i2s.bits = BIT_LENGTH_18BITS;
79
- return bits ;
79
+ return true ;
80
80
case 20 :
81
81
i2s.bits = BIT_LENGTH_20BITS;
82
- return bits ;
82
+ return true ;
83
83
case 24 :
84
84
i2s.bits = BIT_LENGTH_24BITS;
85
- return bits ;
85
+ return true ;
86
86
case 32 :
87
87
i2s.bits = BIT_LENGTH_32BITS;
88
- return bits ;
88
+ return true ;
89
89
}
90
- return 0 ;
90
+ return false ;
91
91
}
92
92
93
93
// / get the sample rate as number
@@ -103,26 +103,41 @@ class CodecConfig : public codec_config_t {
103
103
104
104
int getChannelsNumeric () { return i2s.channels ; }
105
105
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
+ }
107
122
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 ) {
110
125
int diff = 99999 ;
111
126
int result = 0 ;
112
127
for (int j = 0 ; j < 14 ; j++) {
113
- if (rate_num[j] == rateNum ) {
128
+ if (rate_num[j] == requestedRate ) {
114
129
AD_LOGD (" -> %d" , rate_num[j]);
115
130
i2s.rate = rate_code[j];
116
- return rateNum ;
131
+ return requestedRate ;
117
132
} else {
118
- int new_diff = abs (rate_code[j] - rateNum );
133
+ int new_diff = abs (rate_code[j] - requestedRate );
119
134
if (new_diff < diff) {
120
135
result = j;
121
136
diff = new_diff;
122
137
}
123
138
}
124
139
}
125
- AD_LOGE (" Sample Rate not supported: %d - using %d" , rateNum ,
140
+ AD_LOGE (" Sample Rate not supported: %d - using %d" , requestedRate ,
126
141
rate_num[result]);
127
142
i2s.rate = rate_code[result];
128
143
return rate_num[result];
0 commit comments