diff --git a/README.md b/README.md index f368d76a..0fdcb24f 100644 --- a/README.md +++ b/README.md @@ -146,9 +146,12 @@ apl * tplgtool2.py
Dumps info from tplg binary file. + SOF CI uses this to generate a topology graph. * tplgtool.py -
Dumps info from tplg binary file. (deprecated) +
Dumps info from tplg binary file. sof-tplgreader.py still use this but new features + will go to tplgtool2.py. When all functions are migrated to tplgtool2.py + it will be deprecated. ## System configuration tips diff --git a/tools/sof-tplgreader.py b/tools/sof-tplgreader.py index cb45cd73..26fd06a2 100755 --- a/tools/sof-tplgreader.py +++ b/tools/sof-tplgreader.py @@ -63,11 +63,13 @@ def loadFile(self, filename, sofcard=0): # supported formats of playback pipeline in formats[0] # supported formats of capture pipeline in formats[1] formats = TplgFormatter.get_pcm_fmt(pcm) + rates = TplgFormatter.get_pcm_rate_list(pcm) # if capture is present, pcm['capture'] = 1, otherwise, pcm['capture'] = 0, # same thing for pcm['playback'] pipeline_dict['fmts'] = " ".join(formats[pcm['capture']]) # use the first supported format for test pipeline_dict['fmt'] = pipeline_dict['fmts'].split(' ')[0] + pipeline_dict['rates'] = " ".join(rates[pcm['capture']]) pipeline_dict['rate_min'], pipeline_dict['rate_max'] = self._key2str(cap, 'rate') pipeline_dict['ch_min'], pipeline_dict['ch_max'] = self._key2str(cap, 'channels') # for pcm with both playback and capture capabilities, we can extract two pipelines. @@ -95,7 +97,17 @@ def loadFile(self, filename, sofcard=0): # format pipeline, this change for script direct access 'rate' 'channel' 'dev' 'snd' for pipeline in self._pipeline_lst: #pipeline['fmt']=pipeline['fmt'].upper().replace('LE', '_LE') - pipeline['rate'] = pipeline['rate_min'] if int(pipeline['rate_min']) != 0 else pipeline['rate_max'] + # If rates is available get first sampling rate from the list. + # If rates list doesn't have any, then get it from rate_min or rate_max. + # If none of them is available, then set rate to 0 + if pipeline['rates']: + pipeline['rate'] = pipeline['rates'].split(' ')[0] + elif int(pipeline['rate_min']) != 0: + pipeline['rate'] = pipeline['rate_min'] + elif int(pipeline['rate_max']) != 0: + pipeline['rate'] = pipeline['rate_max'] + else: + pipeline['rate'] = 0 pipeline['channel'] = pipeline['ch_min'] pipeline['dev'] = "hw:" + str(sofcard) + ',' + pipeline['id'] # the character devices for PCM under /dev/snd take the form of diff --git a/tools/tplgtool.py b/tools/tplgtool.py index 2e7873ef..3ae6150a 100755 --- a/tools/tplgtool.py +++ b/tools/tplgtool.py @@ -607,6 +607,17 @@ def _to_fmt_string(fmt): fmts.append("FLOAT") return fmts + + # transform number denoted pipeline sampling rates to string + @staticmethod + def _to_rate_string(rate): + # Note: intentionally put 48000 first to make first in the list + bit_rates_dict = {7 : 48000, + 1 : 8000, 3 : 16000, 4 : 22050, 5 : 32000, 6 : 44100, + 8 : 64000, 9 : 96000} + return [ str(bit_rates_dict[bit]) for bit in bit_rates_dict + if rate & (1 << bit) != 0 ] + # always return a list, playback stream fmt in fmt_list[0] # capture stream fmt in fmt_list[1], the format of absense # stream is UNKNOWN @@ -618,6 +629,12 @@ def get_pcm_fmt(pcm): fmt_list.append(TplgFormatter._to_fmt_string(cap["formats"])) return fmt_list + # always return a list, pcm rates in the list in ascending order + @staticmethod + def get_pcm_rate_list(pcm): + caps = pcm["caps"] + return [ TplgFormatter._to_rate_string(cap["rates"]) for cap in caps ] + @staticmethod def get_pcm_type(item): if item["playback"] == 1 and item["capture"] == 1: