Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ffmpeg-doc / usr / share / doc / ffmpeg-doc / api / resampling__audio_8c_source.html
Size: Mime:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>FFmpeg: doc/examples/resampling_audio.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">FFmpeg
   &#160;<span id="projectnumber">2.7.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">doc/examples/resampling_audio.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="resampling__audio_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (c) 2012 Stefano Sabatini</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<a name="l00005"></a>00005 <span class="comment"> * of this software and associated documentation files (the &quot;Software&quot;), to deal</span>
<a name="l00006"></a>00006 <span class="comment"> * in the Software without restriction, including without limitation the rights</span>
<a name="l00007"></a>00007 <span class="comment"> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<a name="l00008"></a>00008 <span class="comment"> * copies of the Software, and to permit persons to whom the Software is</span>
<a name="l00009"></a>00009 <span class="comment"> * furnished to do so, subject to the following conditions:</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included in</span>
<a name="l00012"></a>00012 <span class="comment"> * all copies or substantial portions of the Software.</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00015"></a>00015 <span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span>
<a name="l00017"></a>00017 <span class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00019"></a>00019 <span class="comment"> * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<a name="l00020"></a>00020 <span class="comment"> * THE SOFTWARE.</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022 <span class="comment"></span>
<a name="l00023"></a>00023 <span class="comment">/**</span>
<a name="l00024"></a>00024 <span class="comment"> * @example resampling_audio.c</span>
<a name="l00025"></a>00025 <span class="comment"> * libswresample API use example.</span>
<a name="l00026"></a>00026 <span class="comment"> */</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;<a class="code" href="opt_8h.html" title="AVOptions.">libavutil/opt.h</a>&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;<a class="code" href="channel__layout_8h.html" title="audio channel layout utility functions">libavutil/channel_layout.h</a>&gt;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;<a class="code" href="samplefmt_8h.html">libavutil/samplefmt.h</a>&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;<a class="code" href="swresample_8h.html" title="libswresample public header">libswresample/swresample.h</a>&gt;</span>
<a name="l00032"></a>00032 
<a name="l00033"></a><a class="code" href="resampling__audio_8c.html#a5e068fc5e6dc5c59638ec235f7f6db89">00033</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="resampling__audio_8c.html#a5e068fc5e6dc5c59638ec235f7f6db89">get_format_from_sample_fmt</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> **fmt,
<a name="l00034"></a>00034                                       <span class="keyword">enum</span> <a class="code" href="group__lavu__sampfmts.html#gaf9a51ca15301871723577c730b5865c5" title="Audio sample formats.">AVSampleFormat</a> sample_fmt)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036     <span class="keywordtype">int</span> i;
<a name="l00037"></a>00037     <span class="keyword">struct </span>sample_fmt_entry {
<a name="l00038"></a>00038         <span class="keyword">enum</span> <a class="code" href="group__lavu__sampfmts.html#gaf9a51ca15301871723577c730b5865c5" title="Audio sample formats.">AVSampleFormat</a> sample_fmt; <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt_be, *fmt_le;
<a name="l00039"></a>00039     } sample_fmt_entries[] = {
<a name="l00040"></a>00040         { <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5adf0f66f21492f8fd5db6debb8b3f932a" title="unsigned 8 bits">AV_SAMPLE_FMT_U8</a>,  <span class="stringliteral">&quot;u8&quot;</span>,    <span class="stringliteral">&quot;u8&quot;</span>    },
<a name="l00041"></a>00041         { <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5aea6132df57aebc3f76e10665395c46af" title="signed 16 bits">AV_SAMPLE_FMT_S16</a>, <span class="stringliteral">&quot;s16be&quot;</span>, <span class="stringliteral">&quot;s16le&quot;</span> },
<a name="l00042"></a>00042         { <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5ab7ae6bb6718c07cd316778783a57a63b" title="signed 32 bits">AV_SAMPLE_FMT_S32</a>, <span class="stringliteral">&quot;s32be&quot;</span>, <span class="stringliteral">&quot;s32le&quot;</span> },
<a name="l00043"></a>00043         { <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5a5251d62cc3c7f18e56bc8e0c48a27903" title="float">AV_SAMPLE_FMT_FLT</a>, <span class="stringliteral">&quot;f32be&quot;</span>, <span class="stringliteral">&quot;f32le&quot;</span> },
<a name="l00044"></a>00044         { <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5ae35a2a6a7593723d9fe4bcefb2876606" title="double">AV_SAMPLE_FMT_DBL</a>, <span class="stringliteral">&quot;f64be&quot;</span>, <span class="stringliteral">&quot;f64le&quot;</span> },
<a name="l00045"></a>00045     };
<a name="l00046"></a>00046     *fmt = NULL;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048     <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="common_8h.html#a3508a98d3ee7e2c9a4841fe264cf70f7">FF_ARRAY_ELEMS</a>(sample_fmt_entries); i++) {
<a name="l00049"></a>00049         <span class="keyword">struct </span>sample_fmt_entry *entry = &amp;sample_fmt_entries[i];
<a name="l00050"></a>00050         <span class="keywordflow">if</span> (sample_fmt == entry-&gt;sample_fmt) {
<a name="l00051"></a>00051             *fmt = <a class="code" href="common_8h.html#a309bdca20f6a78431379fc69442d98ea">AV_NE</a>(entry-&gt;fmt_be, entry-&gt;fmt_le);
<a name="l00052"></a>00052             <span class="keywordflow">return</span> 0;
<a name="l00053"></a>00053         }
<a name="l00054"></a>00054     }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056     fprintf(stderr,
<a name="l00057"></a>00057             <span class="stringliteral">&quot;Sample format %s not supported as output format\n&quot;</span>,
<a name="l00058"></a>00058             <a class="code" href="group__lavu__sampfmts.html#ga31b9d149b2de9821a65f4f5612970838" title="Return the name of sample_fmt, or NULL if sample_fmt is not recognized.">av_get_sample_fmt_name</a>(sample_fmt));
<a name="l00059"></a>00059     <span class="keywordflow">return</span> <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(EINVAL);
<a name="l00060"></a>00060 }
<a name="l00061"></a>00061 <span class="comment"></span>
<a name="l00062"></a>00062 <span class="comment">/**</span>
<a name="l00063"></a>00063 <span class="comment"> * Fill dst buffer with nb_samples, generated starting from t.</span>
<a name="l00064"></a>00064 <span class="comment"> */</span>
<a name="l00065"></a><a class="code" href="resampling__audio_8c.html#af40a34d598e4ae80bc0539e9f5761c5f">00065</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="resampling__audio_8c.html#af40a34d598e4ae80bc0539e9f5761c5f" title="Fill dst buffer with nb_samples, generated starting from t.">fill_samples</a>(<span class="keywordtype">double</span> *dst, <span class="keywordtype">int</span> nb_samples, <span class="keywordtype">int</span> nb_channels, <span class="keywordtype">int</span> sample_rate, <span class="keywordtype">double</span> *t)
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067     <span class="keywordtype">int</span> i, j;
<a name="l00068"></a>00068     <span class="keywordtype">double</span> tincr = 1.0 / sample_rate, *dstp = dst;
<a name="l00069"></a>00069     <span class="keyword">const</span> <span class="keywordtype">double</span> c = 2 * M_PI * 440.0;
<a name="l00070"></a>00070 
<a name="l00071"></a>00071     <span class="comment">/* generate sin tone with 440Hz frequency and duplicated channels */</span>
<a name="l00072"></a>00072     <span class="keywordflow">for</span> (i = 0; i &lt; nb_samples; i++) {
<a name="l00073"></a>00073         *dstp = sin(c * *t);
<a name="l00074"></a>00074         <span class="keywordflow">for</span> (j = 1; j &lt; nb_channels; j++)
<a name="l00075"></a>00075             dstp[j] = dstp[0];
<a name="l00076"></a>00076         dstp += nb_channels;
<a name="l00077"></a>00077         *t += tincr;
<a name="l00078"></a>00078     }
<a name="l00079"></a>00079 }
<a name="l00080"></a>00080 
<a name="l00081"></a><a class="code" href="resampling__audio_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">00081</a> <span class="keywordtype">int</span> <a class="code" href="avio__list__dir_8c.html#a0ddf1224851353fc92bfbff6f499fa97">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)
<a name="l00082"></a>00082 {
<a name="l00083"></a>00083     int64_t src_ch_layout = <a class="code" href="group__channel__mask__c.html#gabc6d6651bba254cd0fa2c42a57228e65">AV_CH_LAYOUT_STEREO</a>, dst_ch_layout = <a class="code" href="group__channel__mask__c.html#ga625aec7f2285dc35e3ed801e91889564">AV_CH_LAYOUT_SURROUND</a>;
<a name="l00084"></a>00084     <span class="keywordtype">int</span> src_rate = 48000, dst_rate = 44100;
<a name="l00085"></a>00085     uint8_t **src_data = NULL, **dst_data = NULL;
<a name="l00086"></a>00086     <span class="keywordtype">int</span> src_nb_channels = 0, dst_nb_channels = 0;
<a name="l00087"></a>00087     <span class="keywordtype">int</span> src_linesize, dst_linesize;
<a name="l00088"></a>00088     <span class="keywordtype">int</span> src_nb_samples = 1024, dst_nb_samples, max_dst_nb_samples;
<a name="l00089"></a>00089     <span class="keyword">enum</span> <a class="code" href="group__lavu__sampfmts.html#gaf9a51ca15301871723577c730b5865c5" title="Audio sample formats.">AVSampleFormat</a> src_sample_fmt = <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5ae35a2a6a7593723d9fe4bcefb2876606" title="double">AV_SAMPLE_FMT_DBL</a>, dst_sample_fmt = <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5aea6132df57aebc3f76e10665395c46af" title="signed 16 bits">AV_SAMPLE_FMT_S16</a>;
<a name="l00090"></a>00090     <span class="keyword">const</span> <span class="keywordtype">char</span> *dst_filename = NULL;
<a name="l00091"></a>00091     FILE *dst_file;
<a name="l00092"></a>00092     <span class="keywordtype">int</span> dst_bufsize;
<a name="l00093"></a>00093     <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt;
<a name="l00094"></a>00094     <span class="keyword">struct </span><a class="code" href="group__lswr.html#ga4aa775b7fba31d2c8dc14c7b7e282863" title="The libswresample context.">SwrContext</a> *swr_ctx;
<a name="l00095"></a>00095     <span class="keywordtype">double</span> t;
<a name="l00096"></a>00096     <span class="keywordtype">int</span> ret;
<a name="l00097"></a>00097 
<a name="l00098"></a>00098     <span class="keywordflow">if</span> (argc != 2) {
<a name="l00099"></a>00099         fprintf(stderr, <span class="stringliteral">&quot;Usage: %s output_file\n&quot;</span>
<a name="l00100"></a>00100                 <span class="stringliteral">&quot;API example program to show how to resample an audio stream with libswresample.\n&quot;</span>
<a name="l00101"></a>00101                 <span class="stringliteral">&quot;This program generates a series of audio frames, resamples them to a specified &quot;</span>
<a name="l00102"></a>00102                 <span class="stringliteral">&quot;output format and rate and saves them to an output file named output_file.\n&quot;</span>,
<a name="l00103"></a>00103             argv[0]);
<a name="l00104"></a>00104         exit(1);
<a name="l00105"></a>00105     }
<a name="l00106"></a>00106     dst_filename = argv[1];
<a name="l00107"></a>00107 
<a name="l00108"></a>00108     dst_file = fopen(dst_filename, <span class="stringliteral">&quot;wb&quot;</span>);
<a name="l00109"></a>00109     <span class="keywordflow">if</span> (!dst_file) {
<a name="l00110"></a>00110         fprintf(stderr, <span class="stringliteral">&quot;Could not open destination file %s\n&quot;</span>, dst_filename);
<a name="l00111"></a>00111         exit(1);
<a name="l00112"></a>00112     }
<a name="l00113"></a>00113 
<a name="l00114"></a>00114     <span class="comment">/* create resampler context */</span>
<a name="l00115"></a>00115     swr_ctx = <a class="code" href="group__lswr.html#gaf58c4ff10f73d74bdab8e5aa7193147c" title="Allocate SwrContext.">swr_alloc</a>();
<a name="l00116"></a>00116     <span class="keywordflow">if</span> (!swr_ctx) {
<a name="l00117"></a>00117         fprintf(stderr, <span class="stringliteral">&quot;Could not allocate resampler context\n&quot;</span>);
<a name="l00118"></a>00118         ret = <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(ENOMEM);
<a name="l00119"></a>00119         <span class="keywordflow">goto</span> end;
<a name="l00120"></a>00120     }
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     <span class="comment">/* set options */</span>
<a name="l00123"></a>00123     <a class="code" href="group__opt__set__funcs.html#ga3adf7185c21cc080890a5ec02c2e56b2">av_opt_set_int</a>(swr_ctx, <span class="stringliteral">&quot;in_channel_layout&quot;</span>,    src_ch_layout, 0);
<a name="l00124"></a>00124     <a class="code" href="group__opt__set__funcs.html#ga3adf7185c21cc080890a5ec02c2e56b2">av_opt_set_int</a>(swr_ctx, <span class="stringliteral">&quot;in_sample_rate&quot;</span>,       src_rate, 0);
<a name="l00125"></a>00125     <a class="code" href="group__opt__set__funcs.html#gad446f7a7b92442e464d43e400e661040">av_opt_set_sample_fmt</a>(swr_ctx, <span class="stringliteral">&quot;in_sample_fmt&quot;</span>, src_sample_fmt, 0);
<a name="l00126"></a>00126 
<a name="l00127"></a>00127     <a class="code" href="group__opt__set__funcs.html#ga3adf7185c21cc080890a5ec02c2e56b2">av_opt_set_int</a>(swr_ctx, <span class="stringliteral">&quot;out_channel_layout&quot;</span>,    dst_ch_layout, 0);
<a name="l00128"></a>00128     <a class="code" href="group__opt__set__funcs.html#ga3adf7185c21cc080890a5ec02c2e56b2">av_opt_set_int</a>(swr_ctx, <span class="stringliteral">&quot;out_sample_rate&quot;</span>,       dst_rate, 0);
<a name="l00129"></a>00129     <a class="code" href="group__opt__set__funcs.html#gad446f7a7b92442e464d43e400e661040">av_opt_set_sample_fmt</a>(swr_ctx, <span class="stringliteral">&quot;out_sample_fmt&quot;</span>, dst_sample_fmt, 0);
<a name="l00130"></a>00130 
<a name="l00131"></a>00131     <span class="comment">/* initialize the resampling context */</span>
<a name="l00132"></a>00132     <span class="keywordflow">if</span> ((ret = <a class="code" href="group__lswr.html#gae173e8ed91717700471a1dcd06f00f67" title="Initialize context after user parameters have been set.">swr_init</a>(swr_ctx)) &lt; 0) {
<a name="l00133"></a>00133         fprintf(stderr, <span class="stringliteral">&quot;Failed to initialize the resampling context\n&quot;</span>);
<a name="l00134"></a>00134         <span class="keywordflow">goto</span> end;
<a name="l00135"></a>00135     }
<a name="l00136"></a>00136 
<a name="l00137"></a>00137     <span class="comment">/* allocate source and destination samples buffers */</span>
<a name="l00138"></a>00138 
<a name="l00139"></a>00139     src_nb_channels = <a class="code" href="group__channel__mask__c.html#gac95619abeb32e4a3daa18e3ff3419380" title="Return the number of channels in the channel layout.">av_get_channel_layout_nb_channels</a>(src_ch_layout);
<a name="l00140"></a>00140     ret = <a class="code" href="group__lavu__sampmanip.html#gae8b9f22f2f659d023f111390d9545273" title="Allocate a data pointers array, samples buffer for nb_samples samples, and fill data pointers and lin...">av_samples_alloc_array_and_samples</a>(&amp;src_data, &amp;src_linesize, src_nb_channels,
<a name="l00141"></a>00141                                              src_nb_samples, src_sample_fmt, 0);
<a name="l00142"></a>00142     <span class="keywordflow">if</span> (ret &lt; 0) {
<a name="l00143"></a>00143         fprintf(stderr, <span class="stringliteral">&quot;Could not allocate source samples\n&quot;</span>);
<a name="l00144"></a>00144         <span class="keywordflow">goto</span> end;
<a name="l00145"></a>00145     }
<a name="l00146"></a>00146 
<a name="l00147"></a>00147     <span class="comment">/* compute the number of converted samples: buffering is avoided</span>
<a name="l00148"></a>00148 <span class="comment">     * ensuring that the output buffer will contain at least all the</span>
<a name="l00149"></a>00149 <span class="comment">     * converted input samples */</span>
<a name="l00150"></a>00150     max_dst_nb_samples = dst_nb_samples =
<a name="l00151"></a>00151         <a class="code" href="group__lavu__math.html#gad686ab94939ed4c65218309e94bdca72" title="Rescale a 64-bit integer with specified rounding.">av_rescale_rnd</a>(src_nb_samples, dst_rate, src_rate, <a class="code" href="group__lavu__math.html#gga921d656eaf2c4d6800a734a13af021d0aa1d28e08e2f8b49b256e056f93038c1a" title="Round toward +infinity.">AV_ROUND_UP</a>);
<a name="l00152"></a>00152 
<a name="l00153"></a>00153     <span class="comment">/* buffer is going to be directly written to a rawaudio file, no alignment */</span>
<a name="l00154"></a>00154     dst_nb_channels = <a class="code" href="group__channel__mask__c.html#gac95619abeb32e4a3daa18e3ff3419380" title="Return the number of channels in the channel layout.">av_get_channel_layout_nb_channels</a>(dst_ch_layout);
<a name="l00155"></a>00155     ret = <a class="code" href="group__lavu__sampmanip.html#gae8b9f22f2f659d023f111390d9545273" title="Allocate a data pointers array, samples buffer for nb_samples samples, and fill data pointers and lin...">av_samples_alloc_array_and_samples</a>(&amp;dst_data, &amp;dst_linesize, dst_nb_channels,
<a name="l00156"></a>00156                                              dst_nb_samples, dst_sample_fmt, 0);
<a name="l00157"></a>00157     <span class="keywordflow">if</span> (ret &lt; 0) {
<a name="l00158"></a>00158         fprintf(stderr, <span class="stringliteral">&quot;Could not allocate destination samples\n&quot;</span>);
<a name="l00159"></a>00159         <span class="keywordflow">goto</span> end;
<a name="l00160"></a>00160     }
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     t = 0;
<a name="l00163"></a>00163     <span class="keywordflow">do</span> {
<a name="l00164"></a>00164         <span class="comment">/* generate synthetic audio */</span>
<a name="l00165"></a>00165         <a class="code" href="resampling__audio_8c.html#af40a34d598e4ae80bc0539e9f5761c5f" title="Fill dst buffer with nb_samples, generated starting from t.">fill_samples</a>((<span class="keywordtype">double</span> *)src_data[0], src_nb_samples, src_nb_channels, src_rate, &amp;t);
<a name="l00166"></a>00166 
<a name="l00167"></a>00167         <span class="comment">/* compute destination number of samples */</span>
<a name="l00168"></a>00168         dst_nb_samples = <a class="code" href="group__lavu__math.html#gad686ab94939ed4c65218309e94bdca72" title="Rescale a 64-bit integer with specified rounding.">av_rescale_rnd</a>(<a class="code" href="group__lswr.html#ga5121a5a7890a2d23b72dc871dd0ebb06" title="Gets the delay the next input sample will experience relative to the next output sample.">swr_get_delay</a>(swr_ctx, src_rate) +
<a name="l00169"></a>00169                                         src_nb_samples, dst_rate, src_rate, <a class="code" href="group__lavu__math.html#gga921d656eaf2c4d6800a734a13af021d0aa1d28e08e2f8b49b256e056f93038c1a" title="Round toward +infinity.">AV_ROUND_UP</a>);
<a name="l00170"></a>00170         <span class="keywordflow">if</span> (dst_nb_samples &gt; max_dst_nb_samples) {
<a name="l00171"></a>00171             <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...">av_freep</a>(&amp;dst_data[0]);
<a name="l00172"></a>00172             ret = <a class="code" href="group__lavu__sampmanip.html#ga4db4c77f928d32c7d8854732f50b8c04" title="Allocate a samples buffer for nb_samples samples, and fill data pointers and linesize accordingly...">av_samples_alloc</a>(dst_data, &amp;dst_linesize, dst_nb_channels,
<a name="l00173"></a>00173                                    dst_nb_samples, dst_sample_fmt, 1);
<a name="l00174"></a>00174             <span class="keywordflow">if</span> (ret &lt; 0)
<a name="l00175"></a>00175                 <span class="keywordflow">break</span>;
<a name="l00176"></a>00176             max_dst_nb_samples = dst_nb_samples;
<a name="l00177"></a>00177         }
<a name="l00178"></a>00178 
<a name="l00179"></a>00179         <span class="comment">/* convert to destination format */</span>
<a name="l00180"></a>00180         ret = <a class="code" href="group__lswr.html#gaa5bb6cab830146efa8c760fa66ee582a" title="Convert audio.">swr_convert</a>(swr_ctx, dst_data, dst_nb_samples, (<span class="keyword">const</span> uint8_t **)src_data, src_nb_samples);
<a name="l00181"></a>00181         <span class="keywordflow">if</span> (ret &lt; 0) {
<a name="l00182"></a>00182             fprintf(stderr, <span class="stringliteral">&quot;Error while converting\n&quot;</span>);
<a name="l00183"></a>00183             <span class="keywordflow">goto</span> end;
<a name="l00184"></a>00184         }
<a name="l00185"></a>00185         dst_bufsize = <a class="code" href="group__lavu__sampfmts.html#gaa7368bc4e3a366b688e81938ed55eb06" title="Get the required buffer size for the given audio parameters.">av_samples_get_buffer_size</a>(&amp;dst_linesize, dst_nb_channels,
<a name="l00186"></a>00186                                                  ret, dst_sample_fmt, 1);
<a name="l00187"></a>00187         <span class="keywordflow">if</span> (dst_bufsize &lt; 0) {
<a name="l00188"></a>00188             fprintf(stderr, <span class="stringliteral">&quot;Could not get sample buffer size\n&quot;</span>);
<a name="l00189"></a>00189             <span class="keywordflow">goto</span> end;
<a name="l00190"></a>00190         }
<a name="l00191"></a>00191         printf(<span class="stringliteral">&quot;t:%f in:%d out:%d\n&quot;</span>, t, src_nb_samples, ret);
<a name="l00192"></a>00192         fwrite(dst_data[0], 1, dst_bufsize, dst_file);
<a name="l00193"></a>00193     } <span class="keywordflow">while</span> (t &lt; 10);
<a name="l00194"></a>00194 
<a name="l00195"></a>00195     <span class="keywordflow">if</span> ((ret = <a class="code" href="resampling__audio_8c.html#a5e068fc5e6dc5c59638ec235f7f6db89">get_format_from_sample_fmt</a>(&amp;fmt, dst_sample_fmt)) &lt; 0)
<a name="l00196"></a>00196         <span class="keywordflow">goto</span> end;
<a name="l00197"></a>00197     fprintf(stderr, <span class="stringliteral">&quot;Resampling succeeded. Play the output file with the command:\n&quot;</span>
<a name="l00198"></a>00198             <span class="stringliteral">&quot;ffplay -f %s -channel_layout %&quot;</span>PRId64<span class="stringliteral">&quot; -channels %d -ar %d %s\n&quot;</span>,
<a name="l00199"></a>00199             fmt, dst_ch_layout, dst_nb_channels, dst_rate, dst_filename);
<a name="l00200"></a>00200 
<a name="l00201"></a>00201 end:
<a name="l00202"></a>00202     fclose(dst_file);
<a name="l00203"></a>00203 
<a name="l00204"></a>00204     <span class="keywordflow">if</span> (src_data)
<a name="l00205"></a>00205         <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...">av_freep</a>(&amp;src_data[0]);
<a name="l00206"></a>00206     <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...">av_freep</a>(&amp;src_data);
<a name="l00207"></a>00207 
<a name="l00208"></a>00208     <span class="keywordflow">if</span> (dst_data)
<a name="l00209"></a>00209         <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...">av_freep</a>(&amp;dst_data[0]);
<a name="l00210"></a>00210     <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba" title="Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...">av_freep</a>(&amp;dst_data);
<a name="l00211"></a>00211 
<a name="l00212"></a>00212     <a class="code" href="group__lswr.html#ga818f7d78b1ad7d8d5b70de374b668c34" title="Free the given SwrContext and set the pointer to NULL.">swr_free</a>(&amp;swr_ctx);
<a name="l00213"></a>00213     <span class="keywordflow">return</span> ret &lt; 0;
<a name="l00214"></a>00214 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>