Skip to content

Commit ddcc1e7

Browse files
authored
Merge pull request #14 from ranj063/tone
Tone related patches
2 parents 71fa73f + 3cae0f7 commit ddcc1e7

File tree

3 files changed

+110
-10
lines changed

3 files changed

+110
-10
lines changed

src/audio/tone.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@
6363
#define TONE_GAIN(v) Q_CONVERT_FLOAT(v, 31)
6464

6565
/* Set default tone amplitude and frequency */
66-
#define TONE_AMPLITUDE_DEFAULT TONE_GAIN(0.5) /* -6 dB */
67-
#define TONE_FREQUENCY_DEFAULT TONE_FREQ(82.41) /* E2 note */
68-
66+
#define TONE_AMPLITUDE_DEFAULT TONE_GAIN(0.1) /* -20 dB */
67+
#define TONE_FREQUENCY_DEFAULT TONE_FREQ(997.0)
6968
#define TONE_NUM_FS 13 /* Table size for 8-192 kHz range */
7069

7170
/* 2*pi/Fs lookup tables in Q1.31 for each Fs */
@@ -422,6 +421,8 @@ static struct comp_dev *tone_new(struct sof_ipc_comp *comp)
422421
comp_set_drvdata(dev, cd);
423422
cd->tone_func = tone_s32_default;
424423

424+
cd->rate = ipc_tone->sample_rate;
425+
425426
/* Reset tone generator and set channels volumes to default */
426427
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
427428
tonegen_reset(&cd->sg[i]);
@@ -448,17 +449,38 @@ static int tone_params(struct comp_dev *dev)
448449

449450
trace_tone("par");
450451

452+
/* Tone supports only S32_LE PCM format atm */
453+
if (config->frame_fmt != SOF_IPC_FRAME_S32_LE)
454+
return -EINVAL;
455+
456+
trace_value(config->frame_fmt);
457+
dev->params.frame_fmt = config->frame_fmt;
458+
451459
/* Need to compute this in non-host endpoint */
452-
dev->frame_bytes =
453-
dev->params.sample_container_bytes * dev->params.channels;
460+
dev->frame_bytes = comp_frame_bytes(dev);
454461

455462
/* calculate period size based on config */
456463
cd->period_bytes = dev->frames * dev->frame_bytes;
457464

458-
/* EQ supports only S32_LE PCM format */
459-
if (config->frame_fmt != SOF_IPC_FRAME_S32_LE)
460-
return -EINVAL;
465+
return 0;
466+
}
461467

468+
static int tone_cmd_get_value(struct comp_dev *dev,
469+
struct sof_ipc_ctrl_data *cdata)
470+
{
471+
struct comp_data *cd = comp_get_drvdata(dev);
472+
int j;
473+
474+
trace_tone("mgt");
475+
476+
if (cdata->cmd == SOF_CTRL_CMD_SWITCH) {
477+
for (j = 0; j < cdata->num_elems; j++) {
478+
cdata->chanv[j].channel = j;
479+
cdata->chanv[j].value = !cd->sg[j].mute;
480+
trace_value(j);
481+
trace_value(cd->sg[j].mute);
482+
}
483+
}
462484
return 0;
463485
}
464486

@@ -480,6 +502,7 @@ static int tone_cmd_set_value(struct comp_dev *dev, struct sof_ipc_ctrl_data *cd
480502
trace_tone_error("che");
481503
return -EINVAL;
482504
}
505+
483506
if (val)
484507
tonegen_unmute(&cd->sg[ch]);
485508
else
@@ -583,6 +606,9 @@ static int tone_cmd(struct comp_dev *dev, int cmd, void *data)
583606
case COMP_CMD_SET_VALUE:
584607
ret = tone_cmd_set_value(dev, cdata);
585608
break;
609+
case COMP_CMD_GET_VALUE:
610+
ret = tone_cmd_get_value(dev, cdata);
611+
break;
586612
}
587613

588614
return ret;
@@ -641,7 +667,6 @@ static int tone_prepare(struct comp_dev * dev)
641667
return ret;
642668

643669
cd->channels = dev->params.channels;
644-
cd->rate = dev->params.rate;
645670
tracev_value(cd->channels);
646671
tracev_value(cd->rate);
647672

src/include/uapi/ipc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ struct sof_ipc_comp_mux {
715715
struct sof_ipc_comp_tone {
716716
struct sof_ipc_comp comp;
717717
struct sof_ipc_comp_config config;
718+
int32_t sample_rate;
718719
int32_t frequency;
719720
int32_t amplitude;
720721
int32_t freq_mult;

src/ipc/handler.c

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*
3535
*/
3636

37+
#include <stdbool.h>
3738
#include <sof/debug.h>
3839
#include <sof/timer.h>
3940
#include <sof/interrupt.h>
@@ -86,6 +87,71 @@ static inline struct sof_ipc_hdr *mailbox_validate(void)
8687
return hdr;
8788
}
8889

90+
/* check if a pipeline is hostless when walking downstream */
91+
static bool is_hostless_downstream(struct comp_dev *current)
92+
{
93+
struct list_item *clist;
94+
95+
/* check if current is a HOST comp */
96+
if (current->comp.type == SOF_COMP_HOST ||
97+
current->comp.type == SOF_COMP_SG_HOST)
98+
return false;
99+
100+
/* check if the pipeline has a HOST comp downstream */
101+
list_for_item(clist, &current->bsink_list) {
102+
struct comp_buffer *buffer;
103+
104+
buffer = container_of(clist, struct comp_buffer, source_list);
105+
106+
/* don't go downstream if this component is not connected */
107+
if (!buffer->connected)
108+
continue;
109+
110+
/* dont go downstream if this comp belongs to another pipe */
111+
if (buffer->sink->comp.pipeline_id != current->comp.pipeline_id)
112+
continue;
113+
114+
/* return if there's a host comp downstream */
115+
if (!is_hostless_downstream(buffer->sink))
116+
return false;
117+
}
118+
119+
return true;
120+
}
121+
122+
/* check if a pipeline is hostless when walking upstream */
123+
static bool is_hostless_upstream(struct comp_dev *current)
124+
{
125+
struct list_item *clist;
126+
127+
/* check if current is a HOST comp */
128+
if (current->comp.type == SOF_COMP_HOST ||
129+
current->comp.type == SOF_COMP_SG_HOST)
130+
return false;
131+
132+
/* check if the pipeline has a HOST comp upstream */
133+
list_for_item(clist, &current->bsource_list) {
134+
struct comp_buffer *buffer;
135+
136+
buffer = container_of(clist, struct comp_buffer, sink_list);
137+
138+
/* don't go upstream if this component is not connected */
139+
if (!buffer->connected)
140+
continue;
141+
142+
/* dont go upstream if this comp belongs to another pipeline */
143+
if (buffer->source->comp.pipeline_id !=
144+
current->comp.pipeline_id)
145+
continue;
146+
147+
/* return if there is a host comp upstream */
148+
if (!is_hostless_upstream(buffer->source))
149+
return false;
150+
}
151+
152+
return true;
153+
}
154+
89155
/*
90156
* Stream IPC Operations.
91157
*/
@@ -134,8 +200,14 @@ static int ipc_stream_pcm_params(uint32_t stream)
134200
cd = pcm_dev->cd;
135201
cd->params = pcm_params->params;
136202

137-
#ifdef CONFIG_HOST_PTABLE
203+
/*
204+
* walk in both directions to check if the pipeline is hostless
205+
* skip page table set up if it is
206+
*/
207+
if (is_hostless_downstream(cd) && is_hostless_upstream(cd))
208+
goto pipe_params;
138209

210+
#ifdef CONFIG_HOST_PTABLE
139211
list_init(&elem_list);
140212

141213
/* use DMA to read in compressed page table ringbuffer from host */
@@ -172,6 +244,8 @@ static int ipc_stream_pcm_params(uint32_t stream)
172244
}
173245
#endif
174246

247+
pipe_params:
248+
175249
/* configure pipeline audio params */
176250
err = pipeline_params(pcm_dev->cd->pipeline, pcm_dev->cd, pcm_params);
177251
if (err < 0) {

0 commit comments

Comments
 (0)