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 / api / resampling_audio_8c-example.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"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>FFmpeg: resampling_audio.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<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">3.0.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<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><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><!-- top -->
<!-- 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>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</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>

<div class="header">
  <div class="headertitle">
<div class="title">resampling_audio.c</div>  </div>
</div><!--header-->
<div class="contents">
<p>libswresample API use example.</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * Copyright (c) 2012 Stefano Sabatini</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a copy</span></div>
<div class="line"><span class="comment"> * of this software and associated documentation files (the &quot;Software&quot;), to deal</span></div>
<div class="line"><span class="comment"> * in the Software without restriction, including without limitation the rights</span></div>
<div class="line"><span class="comment"> * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span></div>
<div class="line"><span class="comment"> * copies of the Software, and to permit persons to whom the Software is</span></div>
<div class="line"><span class="comment"> * furnished to do so, subject to the following conditions:</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * The above copyright notice and this permission notice shall be included in</span></div>
<div class="line"><span class="comment"> * all copies or substantial portions of the Software.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span></div>
<div class="line"><span class="comment"> * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span></div>
<div class="line"><span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</span></div>
<div class="line"><span class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span></div>
<div class="line"><span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span></div>
<div class="line"><span class="comment"> * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span></div>
<div class="line"><span class="comment"> * THE SOFTWARE.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * @example resampling_audio.c</span></div>
<div class="line"><span class="comment"> * libswresample API use example.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="opt_8h.html">libavutil/opt.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="channel__layout_8h.html">libavutil/channel_layout.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="samplefmt_8h.html">libavutil/samplefmt.h</a>&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;<a class="code" href="swresample_8h.html">libswresample/swresample.h</a>&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> <a name="a0"></a><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,</div>
<div class="line">                                      <span class="keyword">enum</span> <a class="code" href="group__lavu__sampfmts.html#gaf9a51ca15301871723577c730b5865c5">AVSampleFormat</a> sample_fmt)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">int</span> i;</div>
<div class="line">    <span class="keyword">struct </span>sample_fmt_entry {</div>
<div class="line">        <span class="keyword">enum</span> <a class="code" href="group__lavu__sampfmts.html#gaf9a51ca15301871723577c730b5865c5">AVSampleFormat</a> sample_fmt; <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt_be, *fmt_le;</div>
<div class="line">    } sample_fmt_entries[] = {</div>
<div class="line">        { <a name="a1"></a><a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5adf0f66f21492f8fd5db6debb8b3f932a">AV_SAMPLE_FMT_U8</a>,  <span class="stringliteral">&quot;u8&quot;</span>,    <span class="stringliteral">&quot;u8&quot;</span>    },</div>
<div class="line">        { <a name="a2"></a><a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5aea6132df57aebc3f76e10665395c46af">AV_SAMPLE_FMT_S16</a>, <span class="stringliteral">&quot;s16be&quot;</span>, <span class="stringliteral">&quot;s16le&quot;</span> },</div>
<div class="line">        { <a name="a3"></a><a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5ab7ae6bb6718c07cd316778783a57a63b">AV_SAMPLE_FMT_S32</a>, <span class="stringliteral">&quot;s32be&quot;</span>, <span class="stringliteral">&quot;s32le&quot;</span> },</div>
<div class="line">        { <a name="a4"></a><a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5a5251d62cc3c7f18e56bc8e0c48a27903">AV_SAMPLE_FMT_FLT</a>, <span class="stringliteral">&quot;f32be&quot;</span>, <span class="stringliteral">&quot;f32le&quot;</span> },</div>
<div class="line">        { <a name="a5"></a><a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5ae35a2a6a7593723d9fe4bcefb2876606">AV_SAMPLE_FMT_DBL</a>, <span class="stringliteral">&quot;f64be&quot;</span>, <span class="stringliteral">&quot;f64le&quot;</span> },</div>
<div class="line">    };</div>
<div class="line">    *fmt = NULL;</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">for</span> (i = 0; i &lt; <a name="a6"></a><a class="code" href="common_8h.html#a3508a98d3ee7e2c9a4841fe264cf70f7">FF_ARRAY_ELEMS</a>(sample_fmt_entries); i++) {</div>
<div class="line">        <span class="keyword">struct </span>sample_fmt_entry *entry = &amp;sample_fmt_entries[i];</div>
<div class="line">        <span class="keywordflow">if</span> (sample_fmt == entry-&gt;sample_fmt) {</div>
<div class="line">            *fmt = <a name="a7"></a><a class="code" href="common_8h.html#a309bdca20f6a78431379fc69442d98ea">AV_NE</a>(entry-&gt;fmt_be, entry-&gt;fmt_le);</div>
<div class="line">            <span class="keywordflow">return</span> 0;</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    fprintf(stderr,</div>
<div class="line">            <span class="stringliteral">&quot;Sample format %s not supported as output format\n&quot;</span>,</div>
<div class="line">            <a name="a8"></a><a class="code" href="group__lavu__sampfmts.html#ga31b9d149b2de9821a65f4f5612970838">av_get_sample_fmt_name</a>(sample_fmt));</div>
<div class="line">    <span class="keywordflow">return</span> <a name="a9"></a><a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(EINVAL);</div>
<div class="line">}</div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">/**</span></div>
<div class="line"><span class="comment"> * Fill dst buffer with nb_samples, generated starting from t.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span> <a name="a10"></a><a class="code" href="resampling__audio_8c.html#af40a34d598e4ae80bc0539e9f5761c5f">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)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">int</span> i, j;</div>
<div class="line">    <span class="keywordtype">double</span> tincr = 1.0 / sample_rate, *dstp = dst;</div>
<div class="line">    <span class="keyword">const</span> <span class="keywordtype">double</span> c = 2 * <a name="a11"></a><a class="code" href="mathematics_8h.html#ae71449b1cc6e6250b91f539153a7a0d3">M_PI</a> * 440.0;</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* generate sin tone with 440Hz frequency and duplicated channels */</span></div>
<div class="line">    <span class="keywordflow">for</span> (i = 0; i &lt; nb_samples; i++) {</div>
<div class="line">        *dstp = sin(c * *t);</div>
<div class="line">        <span class="keywordflow">for</span> (j = 1; j &lt; nb_channels; j++)</div>
<div class="line">            dstp[j] = dstp[0];</div>
<div class="line">        dstp += nb_channels;</div>
<div class="line">        *t += tincr;</div>
<div class="line">    }</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> <a name="a12"></a><a class="code" href="resampling__audio_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div>
<div class="line">{</div>
<div class="line">    int64_t src_ch_layout = <a name="a13"></a><a class="code" href="group__channel__mask__c.html#gabc6d6651bba254cd0fa2c42a57228e65">AV_CH_LAYOUT_STEREO</a>, dst_ch_layout = <a name="a14"></a><a class="code" href="group__channel__mask__c.html#ga625aec7f2285dc35e3ed801e91889564">AV_CH_LAYOUT_SURROUND</a>;</div>
<div class="line">    <span class="keywordtype">int</span> src_rate = 48000, dst_rate = 44100;</div>
<div class="line">    uint8_t **src_data = NULL, **dst_data = NULL;</div>
<div class="line">    <span class="keywordtype">int</span> src_nb_channels = 0, dst_nb_channels = 0;</div>
<div class="line">    <span class="keywordtype">int</span> src_linesize, dst_linesize;</div>
<div class="line">    <span class="keywordtype">int</span> src_nb_samples = 1024, dst_nb_samples, max_dst_nb_samples;</div>
<div class="line">    <span class="keyword">enum</span> <a class="code" href="group__lavu__sampfmts.html#gaf9a51ca15301871723577c730b5865c5">AVSampleFormat</a> src_sample_fmt = <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5ae35a2a6a7593723d9fe4bcefb2876606">AV_SAMPLE_FMT_DBL</a>, dst_sample_fmt = <a class="code" href="group__lavu__sampfmts.html#ggaf9a51ca15301871723577c730b5865c5aea6132df57aebc3f76e10665395c46af">AV_SAMPLE_FMT_S16</a>;</div>
<div class="line">    <span class="keyword">const</span> <span class="keywordtype">char</span> *dst_filename = NULL;</div>
<div class="line">    FILE *dst_file;</div>
<div class="line">    <span class="keywordtype">int</span> dst_bufsize;</div>
<div class="line">    <span class="keyword">const</span> <span class="keywordtype">char</span> *fmt;</div>
<div class="line">    <span class="keyword">struct </span><a class="code" href="group__lswr.html#ga4aa775b7fba31d2c8dc14c7b7e282863">SwrContext</a> *swr_ctx;</div>
<div class="line">    <span class="keywordtype">double</span> t;</div>
<div class="line">    <span class="keywordtype">int</span> ret;</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> (argc != 2) {</div>
<div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Usage: %s output_file\n&quot;</span></div>
<div class="line">                <span class="stringliteral">&quot;API example program to show how to resample an audio stream with libswresample.\n&quot;</span></div>
<div class="line">                <span class="stringliteral">&quot;This program generates a series of audio frames, resamples them to a specified &quot;</span></div>
<div class="line">                <span class="stringliteral">&quot;output format and rate and saves them to an output file named output_file.\n&quot;</span>,</div>
<div class="line">            argv[0]);</div>
<div class="line">        exit(1);</div>
<div class="line">    }</div>
<div class="line">    dst_filename = argv[1];</div>
<div class="line"></div>
<div class="line">    dst_file = fopen(dst_filename, <span class="stringliteral">&quot;wb&quot;</span>);</div>
<div class="line">    <span class="keywordflow">if</span> (!dst_file) {</div>
<div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Could not open destination file %s\n&quot;</span>, dst_filename);</div>
<div class="line">        exit(1);</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* create resampler context */</span></div>
<div class="line">    swr_ctx = <a name="a15"></a><a class="code" href="group__lswr.html#gaf58c4ff10f73d74bdab8e5aa7193147c">swr_alloc</a>();</div>
<div class="line">    <span class="keywordflow">if</span> (!swr_ctx) {</div>
<div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Could not allocate resampler context\n&quot;</span>);</div>
<div class="line">        ret = <a class="code" href="group__lavu__error.html#gae4bb6f165973d09584e0ec0f335f69ca">AVERROR</a>(ENOMEM);</div>
<div class="line">        <span class="keywordflow">goto</span> end;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* set options */</span></div>
<div class="line">    <a name="a16"></a><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);</div>
<div class="line">    <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);</div>
<div class="line">    <a name="a17"></a><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);</div>
<div class="line"></div>
<div class="line">    <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);</div>
<div class="line">    <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);</div>
<div class="line">    <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);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* initialize the resampling context */</span></div>
<div class="line">    <span class="keywordflow">if</span> ((ret = <a name="a18"></a><a class="code" href="group__lswr.html#gae173e8ed91717700471a1dcd06f00f67">swr_init</a>(swr_ctx)) &lt; 0) {</div>
<div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Failed to initialize the resampling context\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">goto</span> end;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* allocate source and destination samples buffers */</span></div>
<div class="line"></div>
<div class="line">    src_nb_channels = <a name="a19"></a><a class="code" href="group__channel__mask__c.html#gac95619abeb32e4a3daa18e3ff3419380">av_get_channel_layout_nb_channels</a>(src_ch_layout);</div>
<div class="line">    ret = <a name="a20"></a><a class="code" href="group__lavu__sampmanip.html#gae8b9f22f2f659d023f111390d9545273">av_samples_alloc_array_and_samples</a>(&amp;src_data, &amp;src_linesize, src_nb_channels,</div>
<div class="line">                                             src_nb_samples, src_sample_fmt, 0);</div>
<div class="line">    <span class="keywordflow">if</span> (ret &lt; 0) {</div>
<div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Could not allocate source samples\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">goto</span> end;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* compute the number of converted samples: buffering is avoided</span></div>
<div class="line"><span class="comment">     * ensuring that the output buffer will contain at least all the</span></div>
<div class="line"><span class="comment">     * converted input samples */</span></div>
<div class="line">    max_dst_nb_samples = dst_nb_samples =</div>
<div class="line">        <a name="a21"></a><a class="code" href="group__lavu__math.html#gad686ab94939ed4c65218309e94bdca72">av_rescale_rnd</a>(src_nb_samples, dst_rate, src_rate, <a name="a22"></a><a class="code" href="group__lavu__math.html#gga921d656eaf2c4d6800a734a13af021d0aa1d28e08e2f8b49b256e056f93038c1a">AV_ROUND_UP</a>);</div>
<div class="line"></div>
<div class="line">    <span class="comment">/* buffer is going to be directly written to a rawaudio file, no alignment */</span></div>
<div class="line">    dst_nb_channels = <a class="code" href="group__channel__mask__c.html#gac95619abeb32e4a3daa18e3ff3419380">av_get_channel_layout_nb_channels</a>(dst_ch_layout);</div>
<div class="line">    ret = <a class="code" href="group__lavu__sampmanip.html#gae8b9f22f2f659d023f111390d9545273">av_samples_alloc_array_and_samples</a>(&amp;dst_data, &amp;dst_linesize, dst_nb_channels,</div>
<div class="line">                                             dst_nb_samples, dst_sample_fmt, 0);</div>
<div class="line">    <span class="keywordflow">if</span> (ret &lt; 0) {</div>
<div class="line">        fprintf(stderr, <span class="stringliteral">&quot;Could not allocate destination samples\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">goto</span> end;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    t = 0;</div>
<div class="line">    <span class="keywordflow">do</span> {</div>
<div class="line">        <span class="comment">/* generate synthetic audio */</span></div>
<div class="line">        <a class="code" href="resampling__audio_8c.html#af40a34d598e4ae80bc0539e9f5761c5f">fill_samples</a>((<span class="keywordtype">double</span> *)src_data[0], src_nb_samples, src_nb_channels, src_rate, &amp;t);</div>
<div class="line"></div>
<div class="line">        <span class="comment">/* compute destination number of samples */</span></div>
<div class="line">        dst_nb_samples = <a class="code" href="group__lavu__math.html#gad686ab94939ed4c65218309e94bdca72">av_rescale_rnd</a>(<a name="a23"></a><a class="code" href="group__lswr.html#ga5121a5a7890a2d23b72dc871dd0ebb06">swr_get_delay</a>(swr_ctx, src_rate) +</div>
<div class="line">                                        src_nb_samples, dst_rate, src_rate, <a class="code" href="group__lavu__math.html#gga921d656eaf2c4d6800a734a13af021d0aa1d28e08e2f8b49b256e056f93038c1a">AV_ROUND_UP</a>);</div>
<div class="line">        <span class="keywordflow">if</span> (dst_nb_samples &gt; max_dst_nb_samples) {</div>
<div class="line">            <a name="a24"></a><a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba">av_freep</a>(&amp;dst_data[0]);</div>
<div class="line">            ret = <a name="a25"></a><a class="code" href="group__lavu__sampmanip.html#ga4db4c77f928d32c7d8854732f50b8c04">av_samples_alloc</a>(dst_data, &amp;dst_linesize, dst_nb_channels,</div>
<div class="line">                                   dst_nb_samples, dst_sample_fmt, 1);</div>
<div class="line">            <span class="keywordflow">if</span> (ret &lt; 0)</div>
<div class="line">                <span class="keywordflow">break</span>;</div>
<div class="line">            max_dst_nb_samples = dst_nb_samples;</div>
<div class="line">        }</div>
<div class="line"></div>
<div class="line">        <span class="comment">/* convert to destination format */</span></div>
<div class="line">        ret = <a name="a26"></a><a class="code" href="group__lswr.html#gaa5bb6cab830146efa8c760fa66ee582a">swr_convert</a>(swr_ctx, dst_data, dst_nb_samples, (<span class="keyword">const</span> uint8_t **)src_data, src_nb_samples);</div>
<div class="line">        <span class="keywordflow">if</span> (ret &lt; 0) {</div>
<div class="line">            fprintf(stderr, <span class="stringliteral">&quot;Error while converting\n&quot;</span>);</div>
<div class="line">            <span class="keywordflow">goto</span> end;</div>
<div class="line">        }</div>
<div class="line">        dst_bufsize = <a name="a27"></a><a class="code" href="group__lavu__sampfmts.html#gaa7368bc4e3a366b688e81938ed55eb06">av_samples_get_buffer_size</a>(&amp;dst_linesize, dst_nb_channels,</div>
<div class="line">                                                 ret, dst_sample_fmt, 1);</div>
<div class="line">        <span class="keywordflow">if</span> (dst_bufsize &lt; 0) {</div>
<div class="line">            fprintf(stderr, <span class="stringliteral">&quot;Could not get sample buffer size\n&quot;</span>);</div>
<div class="line">            <span class="keywordflow">goto</span> end;</div>
<div class="line">        }</div>
<div class="line">        printf(<span class="stringliteral">&quot;t:%f in:%d out:%d\n&quot;</span>, t, src_nb_samples, ret);</div>
<div class="line">        fwrite(dst_data[0], 1, dst_bufsize, dst_file);</div>
<div class="line">    } <span class="keywordflow">while</span> (t &lt; 10);</div>
<div class="line"></div>
<div class="line">    <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)</div>
<div class="line">        <span class="keywordflow">goto</span> end;</div>
<div class="line">    fprintf(stderr, <span class="stringliteral">&quot;Resampling succeeded. Play the output file with the command:\n&quot;</span></div>
<div class="line">            <span class="stringliteral">&quot;ffplay -f %s -channel_layout %&quot;</span>PRId64<span class="stringliteral">&quot; -channels %d -ar %d %s\n&quot;</span>,</div>
<div class="line">            fmt, dst_ch_layout, dst_nb_channels, dst_rate, dst_filename);</div>
<div class="line"></div>
<div class="line">end:</div>
<div class="line">    fclose(dst_file);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> (src_data)</div>
<div class="line">        <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba">av_freep</a>(&amp;src_data[0]);</div>
<div class="line">    <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba">av_freep</a>(&amp;src_data);</div>
<div class="line"></div>
<div class="line">    <span class="keywordflow">if</span> (dst_data)</div>
<div class="line">        <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba">av_freep</a>(&amp;dst_data[0]);</div>
<div class="line">    <a class="code" href="group__lavu__mem.html#ga0cc84043ea2167ad005c86e11d0bcdba">av_freep</a>(&amp;dst_data);</div>
<div class="line"></div>
<div class="line">    <a name="a28"></a><a class="code" href="group__lswr.html#ga818f7d78b1ad7d8d5b70de374b668c34">swr_free</a>(&amp;swr_ctx);</div>
<div class="line">    <span class="keywordflow">return</span> ret &lt; 0;</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<!-- start footer part -->
<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.8.6
</small></address>
</body>
</html>