Skip to content

Commit 51de413

Browse files
committed
Module: Audio: Add s16/32 source_get_data and sink_get_buffer
This patch adds helper functions source_get_data_s16(), source_get_data_s32(), sink_get_buffer_s16(), and sink_get_buffer_s32(). The buffer_samples as number of samples simplifies the processing function with no division or shift needed to convert buffer size in bytes to samples. Also the int16_t and int32_t typed arguments for data pointer and buffer start avoid type casts in a typical simple processing function. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent b193c48 commit 51de413

4 files changed

Lines changed: 126 additions & 0 deletions

File tree

src/include/module/audio/sink_api.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,44 @@ size_t sink_get_free_frames(struct sof_sink *sink);
170170
int sink_get_buffer(struct sof_sink *sink, size_t req_size, void **data_ptr, void **buffer_start,
171171
size_t *buffer_size);
172172

173+
/**
174+
* Get a circular buffer to operate on (to write).
175+
*
176+
* Same as sink_get_buffer() except that the size of circular buffer is returned as
177+
* 16 bit samples count. The returned samples count simplifies pointer arithmetic in a
178+
* samples process function. The data pointers are int16_t type.
179+
*
180+
* @param sink a handler to sink
181+
* @param [in] req_size requested size of space
182+
* @param [out] data_ptr a pointer to the space will be provided there
183+
* @param [out] buffer_start pointer to circular buffer start
184+
* @param [out] buffer_samples number of s16 samples total in circular buffer
185+
*
186+
* @retval -ENODATA if req_size is bigger than free space
187+
*
188+
*/
189+
int sink_get_buffer_s16(struct sof_sink *sink, size_t req_size, int16_t **data_ptr,
190+
int16_t **buffer_start, int *buffer_samples);
191+
192+
/**
193+
* Get a circular buffer to operate on (to write).
194+
*
195+
* Same as sink_get_buffer() except that the size of circular buffer is returned as
196+
* 32 bit samples count. The returned samples count simplifies pointer arithmetic in a
197+
* samples process function. The data pointers are int32_t type.
198+
*
199+
* @param sink a handler to sink
200+
* @param [in] req_size requested size of space
201+
* @param [out] data_ptr a pointer to the space will be provided there
202+
* @param [out] buffer_start pointer to circular buffer start
203+
* @param [out] buffer_samples number of s32 samples total in circular buffer
204+
*
205+
* @retval -ENODATA if req_size is bigger than free space
206+
*
207+
*/
208+
int sink_get_buffer_s32(struct sof_sink *sink, size_t req_size, int32_t **data_ptr,
209+
int32_t **buffer_start, int *buffer_samples);
210+
173211
/**
174212
* Commits that the buffer previously obtained by get_buffer is filled with data
175213
* and ready to be used

src/include/module/audio/source_api.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,42 @@ size_t source_get_data_frames_available(struct sof_source *source);
184184
int source_get_data(struct sof_source *source, size_t req_size, void const **data_ptr,
185185
void const **buffer_start, size_t *buffer_size);
186186

187+
/**
188+
* Retrieves a fragment of circular data (to read)
189+
*
190+
* Same as source_get_data() except that the size of circular buffer is returned as
191+
* 16 bit samples count. The returned samples count simplifies pointer arithmetic in a
192+
* samples process function. The data pointers are int16_t type.
193+
*
194+
* @param source a handler to source
195+
* @param [in] req_size requested size of data.
196+
* @param [out] data_ptr a pointer to data will be provided there
197+
* @param [out] buffer_start pointer to circular buffer start
198+
* @param [out] buffer_samples number of 16 bit samples total in circular buffer
199+
*
200+
* @retval -ENODATA if req_size is bigger than available data
201+
*/
202+
int source_get_data_s16(struct sof_source *source, size_t req_size, int16_t const **data_ptr,
203+
int16_t const **buffer_start, int *buffer_samples);
204+
205+
/**
206+
* Retrieves a fragment of circular data (to read)
207+
*
208+
* Same as source_get_data() except that the size of circular buffer is returned as
209+
* 32 bit samples count. The returned samples count simplifies pointer arithmetic in a
210+
* samples process function. The data pointers are int32_t type.
211+
*
212+
* @param source a handler to source
213+
* @param [in] req_size requested size of data.
214+
* @param [out] data_ptr a pointer to data will be provided there
215+
* @param [out] buffer_start pointer to circular buffer start
216+
* @param [out] buffer_samples number of 32 bit samples total in circular buffer
217+
*
218+
* @retval -ENODATA if req_size is bigger than available data
219+
*/
220+
int source_get_data_s32(struct sof_source *source, size_t req_size, int32_t const **data_ptr,
221+
int32_t const **buffer_start, int *buffer_samples);
222+
187223
/**
188224
* Releases fragment previously obtained by source_get_data()
189225
* Once called, the data are no longer available for the caller

src/module/audio/sink_api.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,32 @@ int sink_get_buffer(struct sof_sink *sink, size_t req_size,
3636
}
3737
EXPORT_SYMBOL(sink_get_buffer);
3838

39+
int sink_get_buffer_s16(struct sof_sink *sink, size_t req_size,
40+
int16_t **data_ptr, int16_t **buffer_start, int *buffer_samples)
41+
{
42+
size_t buffer_size;
43+
int ret;
44+
45+
ret = sink_get_buffer(sink, req_size, (void **)data_ptr, (void **)buffer_start,
46+
&buffer_size);
47+
*buffer_samples = buffer_size >> 1;
48+
return ret;
49+
}
50+
EXPORT_SYMBOL(sink_get_buffer_s16);
51+
52+
int sink_get_buffer_s32(struct sof_sink *sink, size_t req_size,
53+
int32_t **data_ptr, int32_t **buffer_start, int *buffer_samples)
54+
{
55+
size_t buffer_size;
56+
int ret;
57+
58+
ret = sink_get_buffer(sink, req_size, (void **)data_ptr, (void **)buffer_start,
59+
&buffer_size);
60+
*buffer_samples = buffer_size >> 2;
61+
return ret;
62+
}
63+
EXPORT_SYMBOL(sink_get_buffer_s32);
64+
3965
int sink_commit_buffer(struct sof_sink *sink, size_t commit_size)
4066
{
4167
int ret;

src/module/audio/source_api.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,32 @@ int source_get_data(struct sof_source *source, size_t req_size,
3535
}
3636
EXPORT_SYMBOL(source_get_data);
3737

38+
int source_get_data_s16(struct sof_source *source, size_t req_size, int16_t const **data_ptr,
39+
int16_t const **buffer_start, int *buffer_samples)
40+
{
41+
size_t buffer_size;
42+
int ret;
43+
44+
ret = source_get_data(source, req_size, (void const **)data_ptr,
45+
(void const **)buffer_start, &buffer_size);
46+
*buffer_samples = buffer_size >> 1;
47+
return ret;
48+
}
49+
EXPORT_SYMBOL(source_get_data_s16);
50+
51+
int source_get_data_s32(struct sof_source *source, size_t req_size, int32_t const **data_ptr,
52+
int32_t const **buffer_start, int *buffer_samples)
53+
{
54+
size_t buffer_size;
55+
int ret;
56+
57+
ret = source_get_data(source, req_size, (void const **)data_ptr,
58+
(void const **)buffer_start, &buffer_size);
59+
*buffer_samples = buffer_size >> 2;
60+
return ret;
61+
}
62+
EXPORT_SYMBOL(source_get_data_s32);
63+
3864
int source_release_data(struct sof_source *source, size_t free_size)
3965
{
4066
int ret;

0 commit comments

Comments
 (0)