Waveform analysis/Top and tail: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring, marked p2js incompatible)
m (syntax highlighting fixup automation)
Line 14: Line 14:


Setting the squelch level to 2 or 3 per cent of the maximum sample value worked reasonably well in my tests.
Setting the squelch level to 2 or 3 per cent of the maximum sample value worked reasonably well in my tests.
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 92: Line 92:
err = os.Remove(tmp2)
err = os.Remove(tmp2)
check(err)
check(err)
}</lang>
}</syntaxhighlight>




=={{header|Julia}}==
=={{header|Julia}}==
Implemented as a Gtk GUI app.
Implemented as a Gtk GUI app.
<lang julia>using FileIO, Gtk, LibSndFile, Printf
<syntaxhighlight lang="julia">using FileIO, Gtk, LibSndFile, Printf


function dB(buf, i, channels, cutoff=0.001)
function dB(buf, i, channels, cutoff=0.001)
Line 246: Line 246:


silencecropperapp()
silencecropperapp()
</syntaxhighlight>
</lang>


=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Go}}
{{trans|Go}}
<lang Nim>import os, osproc, strutils
<syntaxhighlight lang="nim">import os, osproc, strutils


const Sec = "00:00:01"
const Sec = "00:00:01"
Line 305: Line 305:
# Remove the temporary files.
# Remove the temporary files.
removeFile(tmp1)
removeFile(tmp1)
removeFile(tmp2)</lang>
removeFile(tmp2)</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
Line 312: Line 312:
You may want to check for average volume over some period, rather than just all-0.<br>
You may want to check for average volume over some period, rather than just all-0.<br>
This is clearly just a starting point and not a practical/useful/finished product!
This is clearly just a starting point and not a practical/useful/finished product!
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">sample_rate</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">44100</span><span style="color: #0000FF;">,</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">sample_rate</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">44100</span><span style="color: #0000FF;">,</span>
Line 395: Line 395:
<span style="color: #000000;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"aplay notes.wav"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">system</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"aplay notes.wav"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Go}}
{{trans|Go}}
The ability to call external processes such as ''SoX'' is expected to be added to Wren-cli in the next release. In the meantime, we embed the following Wren script in a C host to complete this task.
The ability to call external processes such as ''SoX'' is expected to be added to Wren-cli in the next release. In the meantime, we embed the following Wren script in a C host to complete this task.
<lang ecmascript>/* waveform_analysis_top_and_tail.wren */
<syntaxhighlight lang="ecmascript">/* waveform_analysis_top_and_tail.wren */


class C {
class C {
Line 452: Line 452:
// Remove the temporary files.
// Remove the temporary files.
C.removeFile(tmp1)
C.removeFile(tmp1)
C.removeFile(tmp2)</lang>
C.removeFile(tmp2)</syntaxhighlight>
<br>
<br>
We now embed this in the following C program, compile and run it.
We now embed this in the following C program, compile and run it.
<lang c>#include <stdio.h>
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdio_ext.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <stdlib.h>
Line 553: Line 553:
free(script);
free(script);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


{{omit from|AWK}}
{{omit from|AWK}}