Developer World
Spresense SDK Library v3.2.0-ebc0364
frame_samples.h
1/****************************************************************************
2 * modules/include/audio/utilities/frame_samples.h
3 *
4 * Copyright 2019 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
35
36#ifndef MODULES_INCLUDE_AUDIO_UTILITIES_FRAME_SAMPLES_H
37#define MODULES_INCLUDE_AUDIO_UTILITIES_FRAME_SAMPLES_H
38
40
41/* When MP3 encode and fs is 16kHz, 22.05kHz, 24kHz, sample num of
42 * 1au(access unit) is 1152/2 = 576 (It depend on MPEG2 compliant).
43 * Therefore, at first, value is (#1)"CapSampleNumPerFrame[m_codec_type] / 2".
44 * And sample num of captured and SRC filterd data is to be 576,
45 * return ((#1) * 48000 / m_sampling_rate(Hz)).
46 *
47 * The process below is only for fs is 48kHz, 16kHz.
48 * To correspontd to 32000Hz, 44100Hz..., need conversion process to
49 * sample num per 1au to be 1152.
50 */
51
52
53inline uint32_t getCapSampleNumPerFrame(uint8_t codec_type, uint32_t fs)
54{
55 const uint32_t CapSampleNumPerFrame[] =
56 {
57 1152, /* MP3 */
58 768, /* WAV */ /* Any integer in capable */
59 1024, /* AAC */
60 160, /* OPUS */
61 1024, /* AAC */
62 768, /* LPCM */
63 };
64
65 if (codec_type > AS_CODECTYPE_LPCM)
66 {
67 return 0;
68 }
69
70 if (codec_type == AS_CODECTYPE_MP3 && fs < 32000)
71 {
72 return (CapSampleNumPerFrame[codec_type] / 2 * 48000 /
73 fs);
74 }
75 else if (codec_type == AS_CODECTYPE_OPUS)
76 {
77 /* 20ms. */
78
79 return ((fs / 50) * (48000 / fs));
80 }
81 else
82 {
83 }
84
85 return CapSampleNumPerFrame[codec_type];
86}
87
88#endif /* MODULES_INCLUDE_AUDIO_UTILITIES_FRAME_SAMPLES_H */
89
CXD5602 Audio Common Definitions.
#define AS_CODECTYPE_OPUS
Definition: audio_common_defs.h:135
#define AS_CODECTYPE_MP3
Definition: audio_common_defs.h:123
#define AS_CODECTYPE_LPCM
Definition: audio_common_defs.h:143