scratch/output/Scratch/fr/blog/2010-10-14-Fun-with-wav/index.html
Yann Esposito (Yogsototh) ede5f5378f regeneration
2010-10-15 15:11:51 +02:00

432 lines
No EOL
30 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="shortcut icon" type="image/x-icon" href="/Scratch/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/Scratch/assets/css/main.css" />
<link rel="stylesheet" type="text/css" href="/Scratch/css/twilight.css" />
<link rel="stylesheet" type="text/css" href="/Scratch/css/idc.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="http://feeds.feedburner.com/yannespositocomfr"/>
<link rel="alternate" lang="fr" xml:lang="fr" title="S'amuser avec un .wav" type="text/html" hreflang="fr" href="/Scratch/fr/blog/2010-10-14-Fun-with-wav/" />
<link rel="alternate" lang="en" xml:lang="en" title="Fun with wav" type="text/html" hreflang="en" href="/Scratch/en/blog/2010-10-14-Fun-with-wav/" />
<script type="text/javascript" src="/Scratch/js/jquery-1.3.1.min.js"></script>
<script type="text/javascript" src="/Scratch/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/Scratch/js/index.js"></script>
<title>S'amuser avec un .wav</title>
</head>
<body lang="fr">
<script type="text/javascript">// <![CDATA[
document.write('<div id="blackpage"><img src="/Scratch/img/loading.gif" alt="Chargement en cours..."/></div>');
// ]]>
</script>
<div id="content">
<div id="choix">
<div class="return"><a href="#entete">&darr; Menu &darr;</a></div>
<div id="choixlang">
<a href="/Scratch/en/blog/2010-10-14-Fun-with-wav/" onclick="setLanguage('en')">in English</a>
</div>
</div>
<img src="/Scratch/img/presentation.png" alt="Presentation drawing"/>
<div id="titre">
<h1>
S'amuser avec un .wav
</h1>
</div>
<div class="flush"></div>
<div class="flush"></div>
<div id="afterheader">
<div class="corps">
<div class="intro">
<p><span class="sc"><abbr title="Trop long à lire">tlàl</abbr>&nbsp;: </span> Je me suis amusé à lire un fichier <code>wav</code>. Le <code>C</code> fut le langage le mieux adapté à ce traitement. Bien meilleur que Ruby par exemple.</p>
<p>edit: Je voulais que ce programme fonctionne sur une machine spécifique. En aucun cas je ne pensais publier ce code pour une utilisation autre que celle-ci.</p>
</div>
<p>J&rsquo;ai eu besoin de calculer la somme des valeurs absolue des données d&rsquo;un fichier <code>wav</code>.
Pour des raison d&rsquo;efficacité (et aussi de fun), j&rsquo;ai fait le programme en <code>C</code>.</p>
<p>Celà faisait longtemps que je n&rsquo;avais pas programmé en <code>C</code>.
De mémoire il était peu aisé de manipuler des fichiers.
Mais je dois concéder que j&rsquo;ai été étonné de la clarté du code que j&rsquo;ai obtenu.</p>
<p>Tout d&rsquo;abord, un fichier <code>wav</code> se compose d&rsquo;un entête qui contient pas mal de meta données.
Cet entête a été optimisé pour prendre peu de place.
Donc on discute de l&rsquo;entête avec des nombres d&rsquo;octets&nbsp;:</p>
<ul>
<li>Les 4 premiers octets doivent contenir <code>RIFF</code> en ASCII&nbsp;;</li>
<li>les 4 octects suivant correspondent à un entier codé sur 32 bits qui donne la taille du fichier moins 8 octets. etc..</li>
</ul>
<p>Etonnamment je pense que lire ce type de fichier avec un langage de haut niveau aurait été plus pénible qu&rsquo;en C.
La preuve, il m&rsquo;a suffit de chercher sur le net le format complet de l&rsquo;entête et de l&rsquo;écrire dans un struct.</p>
<pre class="twilight">
<span class="Storage">struct</span> wavfile
{
<span class="Storage">char</span> id[<span class="Constant">4</span>]; <span class="Comment"><span class="Comment">//</span> should always contain &quot;RIFF&quot;</span>
<span class="Storage">int</span> totallength; <span class="Comment"><span class="Comment">//</span> total file length minus 8</span>
<span class="Storage">char</span> wavefmt[<span class="Constant">8</span>]; <span class="Comment"><span class="Comment">//</span> should be &quot;WAVEfmt &quot;</span>
<span class="Storage">int</span> format; <span class="Comment"><span class="Comment">//</span> 16 for PCM format</span>
<span class="Storage">short</span> pcm; <span class="Comment"><span class="Comment">//</span> 1 for PCM format</span>
<span class="Storage">short</span> channels; <span class="Comment"><span class="Comment">//</span> channels</span>
<span class="Storage">int</span> frequency; <span class="Comment"><span class="Comment">//</span> sampling frequency</span>
<span class="Storage">int</span> bytes_per_second;
<span class="Storage">short</span> bytes_by_capture;
<span class="Storage">short</span> bits_per_sample;
<span class="Storage">char</span> data[<span class="Constant">4</span>]; <span class="Comment"><span class="Comment">//</span> should always contain &quot;data&quot;</span>
<span class="Storage">int</span> bytes_in_data;
};
</pre>
<p>Si j&rsquo;avais eu à faire ça en Ruby, je pense qu&rsquo;il m&rsquo;aurait fallu pour chaque bloc de l&rsquo;entête écrire un bout de code de lecture du bon nombre d&rsquo;octets.
Alors qu&rsquo;en <code>C</code> il m&rsquo;a suffit d&rsquo;écrire: </p>
<pre class="twilight">
<span class="SupportFunction">fread</span>(&amp;header,<span class="Keyword">sizeof</span>(header),<span class="Constant">1</span>,wav)
</pre>
<p>Et en une seule étape ma structure de donnée a été remplie avec les valeurs souhaitées. Magique&nbsp;!</p>
<p>Ensuite, récupérer un entier à partir de deux octets n&rsquo;est pas non plus une opération naturelle dans les nouveaux langages de programmation.
Alors qu&rsquo;en <code>C</code>. Pour récupérer un entier codé sur 16 bits il suffit d&rsquo;écrire&nbsp;:</p>
<pre class="twilight">
<span class="Storage">short</span> value=<span class="Constant">0</span>;
<span class="Keyword">while</span>( <span class="SupportFunction">fread</span>(&amp;value,<span class="Keyword">sizeof</span>(value),<span class="Constant">1</span>,wav) ) {
<span class="Comment"><span class="Comment">//</span> do something with value</span>
}
</pre>
<p>Finallement je suis arrivé au code suivant, sachant que le format de wav était connu, avec notamment échantillonage sur 16 bits en 48000Hz&nbsp;:</p>
<div class="code"><div class="file"><a href="/Scratch/fr/blog/2010-10-14-Fun-with-wav/code/wavsum.c"> &#x27A5; wavsum.c </a></div><div class="withfile">
<pre class="twilight">
<span class="CCCPreprocessorLine">#<span class="CCCPreprocessorDirective">include</span> <span class="String"><span class="String">&lt;</span>stdio.h<span class="String">&gt;</span></span></span>
<span class="CCCPreprocessorLine">#<span class="CCCPreprocessorDirective">include</span> <span class="String"><span class="String">&lt;</span>stdlib.h<span class="String">&gt;</span></span></span>
<span class="CCCPreprocessorLine">#<span class="CCCPreprocessorDirective">include</span> <span class="String"><span class="String">&lt;</span>stdint.h<span class="String">&gt;</span></span></span>
<span class="Storage">struct</span> wavfile
{
<span class="Storage">char</span> id[<span class="Constant">4</span>]; <span class="Comment"><span class="Comment">//</span> should always contain &quot;RIFF&quot;</span>
<span class="Storage">int</span> totallength; <span class="Comment"><span class="Comment">//</span> total file length minus 8</span>
<span class="Storage">char</span> wavefmt[<span class="Constant">8</span>]; <span class="Comment"><span class="Comment">//</span> should be &quot;WAVEfmt &quot;</span>
<span class="Storage">int</span> format; <span class="Comment"><span class="Comment">//</span> 16 for PCM format</span>
<span class="Storage">short</span> pcm; <span class="Comment"><span class="Comment">//</span> 1 for PCM format</span>
<span class="Storage">short</span> channels; <span class="Comment"><span class="Comment">//</span> channels</span>
<span class="Storage">int</span> frequency; <span class="Comment"><span class="Comment">//</span> sampling frequency</span>
<span class="Storage">int</span> bytes_per_second;
<span class="Storage">short</span> bytes_by_capture;
<span class="Storage">short</span> bits_per_sample;
<span class="Storage">char</span> data[<span class="Constant">4</span>]; <span class="Comment"><span class="Comment">//</span> should always contain &quot;data&quot;</span>
<span class="Storage">int</span> bytes_in_data;
};
<span class="Storage">int</span> <span class="Entity">ma<span class="Entity">in</span></span>(<span class="Storage">int</span> argc, <span class="Storage">char</span> *argv[]) {
<span class="Storage">char</span> *filename=argv[<span class="Constant">1</span>];
FILE *wav = <span class="SupportFunction">fopen</span>(filename,<span class="String"><span class="String">&quot;</span>rb<span class="String">&quot;</span></span>);
<span class="Storage">struct</span> wavfile header;
<span class="Keyword">if</span> ( wav == <span class="Constant">NULL</span> ) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>Can't open input file <span class="StringConstant">%s</span><span class="String">&quot;</span></span>, filename);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="Comment"><span class="Comment">//</span> read header</span>
<span class="Keyword">if</span> ( <span class="SupportFunction">fread</span>(&amp;header,<span class="Keyword">sizeof</span>(header),<span class="Constant">1</span>,wav) &lt; <span class="Constant">1</span> )
{
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>Can't read file header<span class="StringConstant">\n</span><span class="String">&quot;</span></span>);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="Keyword">if</span> ( header.id[<span class="Constant">0</span>]&nbsp;!= <span class="String"><span class="String">'</span>R<span class="String">'</span></span>
|| header.id[<span class="Constant">1</span>]&nbsp;!= <span class="String"><span class="String">'</span>I<span class="String">'</span></span>
|| header.id[<span class="Constant">2</span>]&nbsp;!= <span class="String"><span class="String">'</span>F<span class="String">'</span></span>
|| header.id[<span class="Constant">3</span>]&nbsp;!= <span class="String"><span class="String">'</span>F<span class="String">'</span></span> ) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>ERROR: Not wav format<span class="StringConstant">\n</span><span class="String">&quot;</span></span>);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>wav format<span class="StringConstant">\n</span><span class="String">&quot;</span></span>);
<span class="Comment"><span class="Comment">//</span> read data</span>
<span class="Storage">long</span> sum=<span class="Constant">0</span>;
<span class="Storage">short</span> value=<span class="Constant">0</span>;
<span class="Keyword">while</span>( <span class="SupportFunction">fread</span>(&amp;value,<span class="Keyword">sizeof</span>(value),<span class="Constant">1</span>,wav) ) {
<span class="Comment"><span class="Comment">//</span> fprintf(stderr,&quot;%d\n&quot;, value);</span>
<span class="Keyword">if</span> (value&lt;<span class="Constant">0</span>) { value=-value; }
sum += value;
}
<span class="SupportFunction">printf</span>(<span class="String"><span class="String">&quot;</span><span class="StringConstant">%ld</span><span class="StringConstant">\n</span><span class="String">&quot;</span></span>,sum);
<span class="SupportFunction">exit</span>(<span class="Constant">0</span>);
}
</pre>
</div></div>
<p>Bien entendu ce code n&rsquo;est qu&rsquo;un <em>hack</em>.
Mais on voit bien comment on peut facilement améliorer ce code, ajouter des cas possibles par exemple.
Comme je dis souvent&nbsp;: le bon outil pour la bonne tâche.
On voit en effet que pour cette tâche <code>C</code> est bien supérieur à Ruby par exemple.</p>
<p>_màj&nbsp;: pour des raisons de compatibilité (machines 64 bits) j&rsquo;ai utilisé <code>int16_t</code> au lieu de <code>short</code> et <code>int</code> au lieu de <code>int</code>.</p>
<p>Je serai curieux de savoir s&rsquo;il existe un manière plus propre en Ruby que je ne connais pas.
Certainement qu&rsquo;en Python ça doit être la cas.</p>
<div class="intro">
<p>màj (2)&nbsp;: après toutes les remarques concernant la portabilité.
J&rsquo;ai fait une nouvelle version qui devrait être plus portable.
Elle fait aussi plus de test pour vérifier le fichier.
Cependant j&rsquo;utilise une assertion spécifique à <code>gcc</code> pour être certain que la structure de donnée n&rsquo;ai pas de &ldquo;trou&rdquo;&nbsp;:</p>
<pre class="twilight">
__attribute__((__packed__))
</pre>
<p>Le nouveau code n&rsquo;utilise pas mmap et devrait être plus compatible.<br />
Voici le dernier résultat&nbsp;:</p>
</div>
<div class="code"><div class="file"><a href="/Scratch/fr/blog/2010-10-14-Fun-with-wav/code/wavsum.c"> &#x27A5; wavsum.c </a></div><div class="withfile">
<pre class="twilight">
<span class="CCCPreprocessorLine">#<span class="CCCPreprocessorDirective">include</span> <span class="String"><span class="String">&lt;</span>stdio.h<span class="String">&gt;</span></span></span>
<span class="CCCPreprocessorLine">#<span class="CCCPreprocessorDirective">include</span> <span class="String"><span class="String">&lt;</span>stdlib.h<span class="String">&gt;</span></span></span>
<span class="CCCPreprocessorLine">#<span class="CCCPreprocessorDirective">include</span> <span class="String"><span class="String">&lt;</span>string.h<span class="String">&gt;</span></span> </span><span class="Comment"><span class="Comment">//</span> for memcmp</span>
<span class="CCCPreprocessorLine">#<span class="CCCPreprocessorDirective">include</span> <span class="String"><span class="String">&lt;</span>stdint.h<span class="String">&gt;</span></span> </span><span class="Comment"><span class="Comment">//</span> for int16_t and int32_t</span>
<span class="Storage">struct</span> wavfile
{
<span class="Storage">char</span> id[<span class="Constant">4</span>]; <span class="Comment"><span class="Comment">//</span> should always contain &quot;RIFF&quot;</span>
<span class="Support">int32_t</span> totallength; <span class="Comment"><span class="Comment">//</span> total file length minus 8</span>
<span class="Storage">char</span> wavefmt[<span class="Constant">8</span>]; <span class="Comment"><span class="Comment">//</span> should be &quot;WAVEfmt &quot;</span>
<span class="Support">int32_t</span> format; <span class="Comment"><span class="Comment">//</span> 16 for PCM format</span>
<span class="Support">int16_t</span> pcm; <span class="Comment"><span class="Comment">//</span> 1 for PCM format</span>
<span class="Support">int16_t</span> channels; <span class="Comment"><span class="Comment">//</span> channels</span>
<span class="Support">int32_t</span> frequency; <span class="Comment"><span class="Comment">//</span> sampling frequency</span>
<span class="Support">int32_t</span> bytes_per_second;
<span class="Support">int16_t</span> bytes_by_capture;
<span class="Support">int16_t</span> bits_per_sample;
<span class="Storage">char</span> data[<span class="Constant">4</span>]; <span class="Comment"><span class="Comment">//</span> should always contain &quot;data&quot;</span>
<span class="Support">int32_t</span> bytes_in_data;
} __attribute__((__packed__));
<span class="Storage">int</span> is_big_endian(<span class="Storage">void</span>) {
<span class="Storage">union</span> {
<span class="Support">uint32_t</span> i;
<span class="Storage">char</span> c[<span class="Constant">4</span>];
} bint = {<span class="Constant">0x01000000</span>};
<span class="Keyword">return</span> bint.c[<span class="Constant">0</span>]==<span class="Constant">1</span>;
}
<span class="Storage">int</span> <span class="Entity">ma<span class="Entity">in</span></span>(<span class="Storage">int</span> argc, <span class="Storage">char</span> *argv[]) {
<span class="Storage">char</span> *filename=argv[<span class="Constant">1</span>];
FILE *wav = <span class="SupportFunction">fopen</span>(filename,<span class="String"><span class="String">&quot;</span>rb<span class="String">&quot;</span></span>);
<span class="Storage">struct</span> wavfile header;
<span class="Keyword">if</span> ( wav == <span class="Constant">NULL</span> ) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>Can't open input file <span class="StringConstant">%s</span><span class="StringConstant">\n</span><span class="String">&quot;</span></span>, filename);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="Comment"><span class="Comment">//</span> read header</span>
<span class="Keyword">if</span> ( <span class="SupportFunction">fread</span>(&amp;header,<span class="Keyword">sizeof</span>(header),<span class="Constant">1</span>,wav) &lt; <span class="Constant">1</span> ) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>Can't read input file header <span class="StringConstant">%s</span><span class="StringConstant">\n</span><span class="String">&quot;</span></span>, filename);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="Comment"><span class="Comment">//</span> if wav file isn't the same endianness than the current environment</span>
<span class="Comment"><span class="Comment">//</span> we quit</span>
<span class="Keyword">if</span> ( is_big_endian() ) {
<span class="Keyword">if</span> ( <span class="SupportFunction">memcmp</span>( header.id,<span class="String"><span class="String">&quot;</span>RIFX<span class="String">&quot;</span></span>, <span class="Constant">4</span>)&nbsp;!= <span class="Constant">0</span> ) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>ERROR: <span class="StringConstant">%s</span> is not a big endian wav file<span class="StringConstant">\n</span><span class="String">&quot;</span></span>, filename);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
} <span class="Keyword">else</span> {
<span class="Keyword">if</span> ( <span class="SupportFunction">memcmp</span>( header.id,<span class="String"><span class="String">&quot;</span>RIFF<span class="String">&quot;</span></span>, <span class="Constant">4</span>)&nbsp;!= <span class="Constant">0</span> ) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>ERROR: <span class="StringConstant">%s</span> is not a little endian wav file<span class="StringConstant">\n</span><span class="String">&quot;</span></span>, filename);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
}
<span class="Keyword">if</span> ( <span class="SupportFunction">memcmp</span>( header.wavefmt, <span class="String"><span class="String">&quot;</span>WAVEfmt <span class="String">&quot;</span></span>, <span class="Constant">8</span>)&nbsp;!= <span class="Constant">0</span>
|| <span class="SupportFunction">memcmp</span>( header.data, <span class="String"><span class="String">&quot;</span>data<span class="String">&quot;</span></span>, <span class="Constant">4</span>)&nbsp;!= <span class="Constant">0</span>
) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>ERROR: Not wav format<span class="StringConstant">\n</span><span class="String">&quot;</span></span>);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="Keyword">if</span> (header.format&nbsp;!= <span class="Constant">16</span>) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span><span class="StringConstant">\n</span>ERROR: not 16 bit wav format.<span class="String">&quot;</span></span>);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>format: <span class="StringConstant">%d</span> bits<span class="String">&quot;</span></span>, header.format);
<span class="Keyword">if</span> (header.format == <span class="Constant">16</span>) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>, PCM<span class="String">&quot;</span></span>);
} <span class="Keyword">else</span> {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>, not PCM (<span class="StringConstant">%d</span>)<span class="String">&quot;</span></span>, header.format);
}
<span class="Keyword">if</span> (header.pcm == <span class="Constant">1</span>) {
<span class="SupportFunction">fprintf</span>(stderr, <span class="String"><span class="String">&quot;</span> uncompressed<span class="String">&quot;</span></span> );
} <span class="Keyword">else</span> {
<span class="SupportFunction">fprintf</span>(stderr, <span class="String"><span class="String">&quot;</span> compressed<span class="String">&quot;</span></span> );
}
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>, channel <span class="StringConstant">%d</span><span class="String">&quot;</span></span>, header.pcm);
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>, freq <span class="StringConstant">%d</span><span class="String">&quot;</span></span>, header.frequency );
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>, <span class="StringConstant">%d</span> bytes per sec<span class="String">&quot;</span></span>, header.bytes_per_second );
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>, <span class="StringConstant">%d</span> bytes by capture<span class="String">&quot;</span></span>, header.bytes_by_capture );
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>, <span class="StringConstant">%d</span> bits per sample<span class="String">&quot;</span></span>, header.bytes_by_capture );
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span><span class="StringConstant">\n</span><span class="String">&quot;</span></span> );
<span class="Keyword">if</span> ( <span class="SupportFunction">memcmp</span>( header.data, <span class="String"><span class="String">&quot;</span>data<span class="String">&quot;</span></span>, <span class="Constant">4</span>)&nbsp;!= <span class="Constant">0</span> ) {
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>ERROR: Prrroblem?<span class="StringConstant">\n</span><span class="String">&quot;</span></span>);
<span class="SupportFunction">exit</span>(<span class="Constant">1</span>);
}
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>wav format<span class="StringConstant">\n</span><span class="String">&quot;</span></span>);
<span class="Comment"><span class="Comment">//</span> read data</span>
<span class="Storage">long</span> <span class="Storage">long</span> sum=<span class="Constant">0</span>;
<span class="Support">int16_t</span> value;
<span class="Storage">int</span> i=<span class="Constant">0</span>;
<span class="SupportFunction">fprintf</span>(stderr,<span class="String"><span class="String">&quot;</span>---<span class="StringConstant">\n</span><span class="String">&quot;</span></span>, value);
<span class="Keyword">while</span>( <span class="SupportFunction">fread</span>(&amp;value,<span class="Keyword">sizeof</span>(value),<span class="Constant">1</span>,wav) ) {
<span class="Keyword">if</span> (value&lt;<span class="Constant">0</span>) { value=-value; }
sum += value;
}
<span class="SupportFunction">printf</span>(<span class="String"><span class="String">&quot;</span><span class="StringConstant">%lld</span><span class="StringConstant">\n</span><span class="String">&quot;</span></span>,sum);
<span class="SupportFunction">exit</span>(<span class="Constant">0</span>);
}
</pre>
</div></div>
</div>
<div id="choixrss">
<a id="rss" href="http://feeds.feedburner.com/yannespositocomfr">
s'abonner
</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#comment').hide();
$('#clickcomment').click(showComments);
});
function showComments() {
$('#comment').show();
$('#clickcomment').fadeOut();
}
document.write('<div id="clickcomment">Commentaires</div>');
</script>
<div class="flush"></div>
<div class="corps" id="comment">
<h2 class="first">commentaires</h2>
<noscript>
</noscript>
<script type="text/javascript">
var idcomments_acct = 'a307f0044511ff1b5cfca573fc0a52e7';
var idcomments_post_id = '/Scratch/fr/blog/2010-10-14-Fun-with-wav/';
var idcomments_post_url = 'http://yannesposito.com/Scratch/fr/blog/2010-10-14-Fun-with-wav/';
</script>
<span id="IDCommentsPostTitle" style="display:none"></span>
<script type='text/javascript' src='/Scratch/js/genericCommentWrapperV2.js'></script>
</div>
<div id="entete" class="corps_spaced">
<div id="liens">
<ul><li><a href="/Scratch/fr/">Accueil</a></li>
<li><a href="/Scratch/fr/blog/">Blog</a></li>
<li><a href="/Scratch/fr/softwares/">Softwares</a></li>
<li><a href="/Scratch/fr/about/">À propos</a></li></ul>
</div>
<div class="flush"></div>
<hr/>
<div id="next_before_articles">
<div id="previous_articles">
articles précédents
<div class="previous_article">
<a href="/Scratch/fr/blog/2010-10-10-Secure-eMail-on-Mac-in-few-steps/"><span class="nicer">«</span>&nbsp;Sécurisez vos emails</a>
</div>
<div class="previous_article">
<a href="/Scratch/fr/blog/2010-10-06-New-Blog-Design-Constraints/"><span class="nicer">«</span>&nbsp;Contraintes du design de ce blog</a>
</div>
<div class="previous_article">
<a href="/Scratch/fr/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/"><span class="nicer">«</span>&nbsp;Utilisation de git pour calculer les mtimes</a>
</div>
</div>
<div id="next_articles">
articles suivants
</div>
<div class="flush"></div>
</div>
</div>
<div id="bottom">
<div>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.fr">Droits de reproduction ©, Yann Esposito</a>
</div>
<div id="lastmod">
Écrit le : 14/10/2010
modifié le : 15/10/2010
</div>
<div>
Site entièrement réalisé avec
<a href="http://www.vim.org">Vim</a>
et
<a href="http://nanoc.stoneship.org">nanoc</a>
</div>
<div>
<a href="/Scratch/fr/validation/">Validation</a>
<a href="http://validator.w3.org/check?uri=referer"> [xhtml] </a>
.
<a href="http://jigsaw.w3.org/css-validator/check/referer?profile=css3"> [css] </a>
.
<a href="http://validator.w3.org/feed/check.cgi?url=http%3A//yannesposito.com/Scratch/fr/blog/feed/feed.xml">[rss]</a>
</div>
</div>
<div class="clear"></div>
</div>
</body>
</html>