4 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
29 #include "tizen-audio-internal.h"
31 /* ------ dump helper -------- */
32 #define MAX(a, b) ((a) > (b) ? (a) : (b))
34 #ifdef __USE_TINYALSA__
35 static const uint32_t g_format_convert_hal_table[] = {
36 [AUDIO_SAMPLE_U8] = PCM_FORMAT_S8,
37 [AUDIO_SAMPLE_S16LE] = PCM_FORMAT_S16_LE,
38 [AUDIO_SAMPLE_S32LE] = PCM_FORMAT_S32_LE,
39 [AUDIO_SAMPLE_S24_32LE] = PCM_FORMAT_S24_LE
42 static const uint32_t g_format_convert_native_table[] = {
43 [PCM_FORMAT_S8] = AUDIO_SAMPLE_U8,
44 [PCM_FORMAT_S16_LE] = AUDIO_SAMPLE_S16LE,
45 [PCM_FORMAT_S32_LE] = AUDIO_SAMPLE_S32LE,
46 [PCM_FORMAT_S24_LE] = AUDIO_SAMPLE_S24_32LE
49 static const uint32_t g_format_convert_hal_table[] = {
50 [AUDIO_SAMPLE_U8] = SND_PCM_FORMAT_U8,
51 [AUDIO_SAMPLE_ALAW] = SND_PCM_FORMAT_A_LAW,
52 [AUDIO_SAMPLE_ULAW] = SND_PCM_FORMAT_MU_LAW,
53 [AUDIO_SAMPLE_S16LE] = SND_PCM_FORMAT_S16_LE,
54 [AUDIO_SAMPLE_S16BE] = SND_PCM_FORMAT_S16_BE,
55 [AUDIO_SAMPLE_FLOAT32LE] = SND_PCM_FORMAT_FLOAT_LE,
56 [AUDIO_SAMPLE_FLOAT32BE] = SND_PCM_FORMAT_FLOAT_BE,
57 [AUDIO_SAMPLE_S32LE] = SND_PCM_FORMAT_S32_LE,
58 [AUDIO_SAMPLE_S32BE] = SND_PCM_FORMAT_S32_BE,
59 [AUDIO_SAMPLE_S24LE] = SND_PCM_FORMAT_S24_3LE,
60 [AUDIO_SAMPLE_S24BE] = SND_PCM_FORMAT_S24_3BE,
61 [AUDIO_SAMPLE_S24_32LE] = SND_PCM_FORMAT_S24_LE,
62 [AUDIO_SAMPLE_S24_32BE] = SND_PCM_FORMAT_S24_BE
65 static const snd_pcm_format_t g_format_convert_native_table[] = {
66 [SND_PCM_FORMAT_U8] = AUDIO_SAMPLE_U8,
67 [SND_PCM_FORMAT_A_LAW] = AUDIO_SAMPLE_ALAW,
68 [SND_PCM_FORMAT_MU_LAW] = AUDIO_SAMPLE_ULAW,
69 [SND_PCM_FORMAT_S16_LE] = AUDIO_SAMPLE_S16LE,
70 [SND_PCM_FORMAT_S16_BE] = AUDIO_SAMPLE_S16BE,
71 [SND_PCM_FORMAT_FLOAT_LE] = AUDIO_SAMPLE_FLOAT32LE,
72 [SND_PCM_FORMAT_FLOAT_BE] = AUDIO_SAMPLE_FLOAT32BE,
73 [SND_PCM_FORMAT_S32_LE] = AUDIO_SAMPLE_S32LE,
74 [SND_PCM_FORMAT_S32_BE] = AUDIO_SAMPLE_S32BE,
75 [SND_PCM_FORMAT_S24_3LE] = AUDIO_SAMPLE_S24LE,
76 [SND_PCM_FORMAT_S24_3BE] = AUDIO_SAMPLE_S24BE,
77 [SND_PCM_FORMAT_S24_LE] = AUDIO_SAMPLE_S24_32LE,
78 [SND_PCM_FORMAT_S24_BE] = AUDIO_SAMPLE_S24_32BE
82 static snd_pcm_format_t __convert_to_hal_format(audio_sample_format_s format)
84 return g_format_convert_hal_table[format];
87 static uint32_t __convert_to_native_format(snd_pcm_format_t format)
89 return g_format_convert_native_table[format];
92 /* src is pa_sample_spec which pulseaudio uses */
93 void convert_hal_format_from_sample_spec(void *src, audio_pcm_sample_spec_s *dst)
95 audio_sample_format_s format;
100 memcpy(dst, src, sizeof(audio_pcm_sample_spec_s));
102 format = ((audio_pcm_sample_spec_s *)src)->format;
104 dst->format = __convert_to_hal_format(format);
107 /* dst is pa_sample_spec which pulseaudio uses */
108 void convert_hal_format_to_sample_spec(audio_pcm_sample_spec_s *src, void *dst)
113 memcpy(dst, src, sizeof(audio_pcm_sample_spec_s));
115 ((audio_pcm_sample_spec_s *)dst)->format = __convert_to_native_format(src->format);
118 dump_data_t* _audio_dump_new(int length)
120 dump_data_t* dump = NULL;
122 if ((dump = malloc(sizeof(dump_data_t)))) {
123 memset(dump, 0, sizeof(dump_data_t));
124 if ((dump->strbuf = malloc(length))) {
125 dump->p = &dump->strbuf[0];
136 void _audio_dump_add_str(dump_data_t *dump, const char *fmt, ...)
145 len = vsnprintf(dump->p, dump->left, fmt, ap);
148 dump->p += MAX(0, len);
149 dump->left -= MAX(0, len);
152 char* _audio_dump_get_str(dump_data_t *dump)
154 return (dump) ? dump->strbuf : NULL;
157 void _audio_dump_free(dump_data_t *dump)
165 /* ------ dump helper -------- */