Skip to content

Commit

Permalink
sof-tplgreader: support rates list
Browse files Browse the repository at this point in the history
WIP

Signed-off-by: Fred Oh <fred.oh@linux.intel.com>
  • Loading branch information
fredoh9 committed Apr 11, 2024
1 parent 74bcaa5 commit f388f07
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tools/sof-tplgreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ 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']])
# use the first supported format for test
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.
Expand Down Expand Up @@ -95,7 +98,14 @@ 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']
# set rate in order of rate_min, rate_max. If both are 0, get first
# sampling rate(rates[0]) from supported rates
if int(pipeline['rate_min']) != 0:
pipeline['rate'] = pipeline['rate_min']
elif int(pipeline['rate_max']) != 0:
pipeline['rate'] = pipeline['rate_max']
elif rates[0] != 0:
pipeline['rate'] = pipeline['rates'].split(' ')[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
Expand Down
36 changes: 36 additions & 0 deletions tools/tplgtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,31 @@ def _to_fmt_string(fmt):
fmts.append("FLOAT")
return fmts


# transform number denoted pipeline format to string
@staticmethod
def _to_rate_string(rate):
rates = []
# Fred: should we check highest freqency first to make decending order?
# Fred: is this all the rates supported?
if rate & (1 << 1) != 0:
rates.append("8000")
if rate & (1 << 3) != 0:
rates.append("16000")
if rate & (1 << 4) != 0:
rates.append("22050")
if rate & (1 << 5) != 0:
rates.append("32000")
if rate & (1 << 6) != 0:
rates.append("44100")
if rate & (1 << 7) != 0:
rates.append("48000")
if rate & (1 << 8) != 0:
rates.append("64000")
if rate & (1 << 9) != 0:
rates.append("96000")
return rates

# 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
Expand All @@ -618,6 +643,17 @@ 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):
#print("Fred: get_pcm_rates")
rate_list = []
caps = pcm["caps"]
#print(caps)
for cap in caps:
rate_list.append(TplgFormatter._to_rate_string(cap["rates"]))
return rate_list

@staticmethod
def get_pcm_type(item):
if item["playback"] == 1 and item["capture"] == 1:
Expand Down

0 comments on commit f388f07

Please sign in to comment.