framework/media: Fix the search logic for the closest sample rate.
A default sample rate is now set as the maximum one supported by the device.
@@ -403,7 +403,7 @@ static audio_manager_result_t get_actual_audio_out_card_id()
static uint32_t get_closest_samprate(unsigned int origin_samprate, audio_io_direction_t direct)
{
int i;
- uint32_t result;
+ uint32_t result = 0;
uint32_t samprate_types;
int count = sizeof(g_audio_samprate_entry) / sizeof(struct audio_samprate_map_entry_s);
@@ -417,12 +417,11 @@ static uint32_t get_closest_samprate(unsigned int origin_samprate, audio_io_dire
samprate_types = g_audio_out_cards[g_actual_audio_out_card_id].resample.samprate_types;
}
- result = g_audio_samprate_entry[count - 1].samprate;
-
- for (i = count - 1; i >= 0; i--) {
+ for (i = 0; i < count; i++) {
if (g_audio_samprate_entry[i].samprate_types & samprate_types) {
- if (g_audio_samprate_entry[i].samprate >= origin_samprate) {
result = g_audio_samprate_entry[i].samprate;
+ if (g_audio_samprate_entry[i].samprate >= origin_samprate) {
+ break;
}
}
}
