forked from thesofproject/sof
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_stream.c
More file actions
56 lines (47 loc) · 1.83 KB
/
Copy pathaudio_stream.c
File metadata and controls
56 lines (47 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2023 Intel Corporation. All rights reserved.
//
#include <rtos/symbol.h>
#include <sof/audio/audio_stream.h>
#include <sof/audio/audio_buffer.h>
#include <sof/audio/buffer.h>
static uint32_t audio_stream_frame_align_get(const uint32_t byte_align,
const uint32_t frame_align_req,
uint32_t frame_size)
{
/* Figure out how many frames are needed to meet the byte_align alignment requirements */
uint32_t frame_num = byte_align / gcd(byte_align, frame_size);
/** return the lcm of frame_num and frame_align_req*/
return frame_align_req * frame_num / gcd(frame_num, frame_align_req);
}
void audio_stream_recalc_align(struct audio_stream *stream)
{
const uint32_t byte_align = stream->byte_align_req;
const uint32_t frame_align_req = stream->frame_align_req;
uint32_t process_size;
uint32_t frame_size = audio_stream_frame_bytes(stream);
stream->runtime_stream_params.align_frame_cnt =
audio_stream_frame_align_get(byte_align, frame_align_req, frame_size);
process_size = stream->runtime_stream_params.align_frame_cnt * frame_size;
stream->runtime_stream_params.align_shift_idx =
(is_power_of_2(process_size) ? 31 : 32) - clz(process_size);
}
EXPORT_SYMBOL(audio_stream_recalc_align);
void audio_stream_set_align(const uint32_t byte_align,
const uint32_t frame_align_req,
struct audio_stream *stream)
{
stream->byte_align_req = byte_align;
stream->frame_align_req = frame_align_req;
audio_stream_recalc_align(stream);
}
EXPORT_SYMBOL(audio_stream_set_align);
void audio_stream_init(struct audio_stream *audio_stream, void *buff_addr, uint32_t size)
{
audio_stream->size = size;
audio_stream->addr = buff_addr;
audio_stream->end_addr = (char *)audio_stream->addr + size;
audio_stream_set_align(1, 1, audio_stream);
audio_stream_reset(audio_stream);
}