blob: c01e0f4e70aac6a482028051f72441598ff477fb [file] [log] [blame]
Diego Biurrun8ca6e522012-03-06 18:07:101/*
2 * common code shared by all WMA variants
3 *
Thilo Borgmannd814a832013-08-15 21:12:514 * This file is part of FFmpeg.
Diego Biurrun8ca6e522012-03-06 18:07:105 *
Thilo Borgmannd814a832013-08-15 21:12:516 * FFmpeg is free software; you can redistribute it and/or
Diego Biurrun8ca6e522012-03-06 18:07:107 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
Thilo Borgmannd814a832013-08-15 21:12:5111 * FFmpeg is distributed in the hope that it will be useful,
Diego Biurrun8ca6e522012-03-06 18:07:1012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
Thilo Borgmannd814a832013-08-15 21:12:5117 * License along with FFmpeg; if not, write to the Free Software
Diego Biurrun8ca6e522012-03-06 18:07:1018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/attributes.h"
Gabriel Dumed2a4e4b2014-09-02 19:28:5022
Diego Biurrun8ca6e522012-03-06 18:07:1023#include "wma_common.h"
24
25/**
26 *@brief Get the samples per frame for this stream.
27 *@param sample_rate output sample_rate
28 *@param version wma version
29 *@param decode_flags codec compression features
30 *@return log2 of the number of output samples per frame
31 */
Diego Biurrun3dde1472012-03-30 21:34:2232av_cold int ff_wma_get_frame_len_bits(int sample_rate, int version,
Diego Biurrun8ca6e522012-03-06 18:07:1033 unsigned int decode_flags)
34{
Diego Biurrun8ca6e522012-03-06 18:07:1035 int frame_len_bits;
36
Gabriel Dumed2a4e4b2014-09-02 19:28:5037 if (sample_rate <= 16000)
Diego Biurrun8ca6e522012-03-06 18:07:1038 frame_len_bits = 9;
Gabriel Dumed2a4e4b2014-09-02 19:28:5039 else if (sample_rate <= 22050 || (sample_rate <= 32000 && version == 1))
Diego Biurrun8ca6e522012-03-06 18:07:1040 frame_len_bits = 10;
Gabriel Dumed2a4e4b2014-09-02 19:28:5041 else if (sample_rate <= 48000 || version < 3)
Diego Biurrun8ca6e522012-03-06 18:07:1042 frame_len_bits = 11;
Gabriel Dumed2a4e4b2014-09-02 19:28:5043 else if (sample_rate <= 96000)
Diego Biurrun8ca6e522012-03-06 18:07:1044 frame_len_bits = 12;
Gabriel Dumed2a4e4b2014-09-02 19:28:5045 else
Diego Biurrun8ca6e522012-03-06 18:07:1046 frame_len_bits = 13;
Diego Biurrun8ca6e522012-03-06 18:07:1047
48 if (version == 3) {
49 int tmp = decode_flags & 0x6;
Gabriel Dumed2a4e4b2014-09-02 19:28:5050 if (tmp == 0x2)
Diego Biurrun8ca6e522012-03-06 18:07:1051 ++frame_len_bits;
Gabriel Dumed2a4e4b2014-09-02 19:28:5052 else if (tmp == 0x4)
Diego Biurrun8ca6e522012-03-06 18:07:1053 --frame_len_bits;
Gabriel Dumed2a4e4b2014-09-02 19:28:5054 else if (tmp == 0x6)
Diego Biurrun8ca6e522012-03-06 18:07:1055 frame_len_bits -= 2;
Diego Biurrun8ca6e522012-03-06 18:07:1056 }
57
58 return frame_len_bits;
59}