1 /*****************************************************************************
2  * resample.h
3  *****************************************************************************
4  * Copyright (C) 2012-2015 L-SMASH Works project
5  *
6  * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  *****************************************************************************/
20 
21 /* This file is available under an ISC license. */
22 
23 #include <string.h>
24 
25 typedef struct
26 {
27     uint64_t            channel_layout;
28     int                 sample_count;
29     enum AVSampleFormat sample_format;
30     uint8_t           **data;
31 } audio_samples_t;
32 
put_silence_audio_samples(int silence_data_size,int is_u8,uint8_t ** out_data)33 static inline void put_silence_audio_samples( int silence_data_size, int is_u8, uint8_t **out_data )
34 {
35     memset( *out_data, is_u8 ? 0x80 : 0x00, silence_data_size );
36     *out_data += silence_data_size;
37 }
38 
get_channel_layout_nb_channels(uint64_t channel_layout)39 static inline int get_channel_layout_nb_channels( uint64_t channel_layout )
40 {
41     int channels = av_get_channel_layout_nb_channels( channel_layout );
42     return channels > 0 ? channels : 1;
43 }
44 
get_linesize(int channel_count,int sample_count,enum AVSampleFormat sample_format)45 static inline int get_linesize( int channel_count, int sample_count, enum AVSampleFormat sample_format )
46 {
47     int linesize;
48     av_samples_get_buffer_size( &linesize, channel_count, sample_count, sample_format, 0 );
49     return linesize;
50 }
51 
52 int resample_s32_to_s24( uint8_t **out_data, uint8_t *in_data, int data_size );
53 int flush_resampler_buffers( AVAudioResampleContext *avr );
54 int update_resampler_configuration( AVAudioResampleContext *avr,
55                                     uint64_t out_channel_layout, int out_sample_rate, enum AVSampleFormat out_sample_fmt,
56                                     uint64_t  in_channel_layout, int  in_sample_rate, enum AVSampleFormat  in_sample_fmt,
57                                     int *input_planes, int *input_block_align );
58 int resample_audio( AVAudioResampleContext *avr, audio_samples_t *out, audio_samples_t *in );
59