EXAMPLES.md 2.46 KB
Newer Older
Arnaud Blanchard's avatar
Arnaud Blanchard committed
1
You can copy past each example in your terminal. Press 'q' to quit the test. For each function you can see the list of options with `-h`
Arnaud Blanchard's avatar
Arnaud Blanchard committed
2

Arnaud Blanchard's avatar
Arnaud Blanchard committed
3 4
Sound
=====
Arnaud Blanchard's avatar
Arnaud Blanchard committed
5

Arnaud Blanchard's avatar
Arnaud Blanchard committed
6 7
Raw signal
----------
Arnaud Blanchard's avatar
Arnaud Blanchard committed
8

Arnaud Blanchard's avatar
Arnaud Blanchard committed
9
**Display the graph of the microphone**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
10

Arnaud Blanchard's avatar
Arnaud Blanchard committed
11
    e_graph_sound.sh
Arnaud Blanchard's avatar
Arnaud Blanchard committed
12

13 14
![image](http://blaar.org/images/examples/graph_microphone.png)

Arnaud Blanchard's avatar
Arnaud Blanchard committed
15 16
The time is 92ms because it is size/samplerate i.e. 4096/44100

Arnaud Blanchard's avatar
Arnaud Blanchard committed
17
**Record the microphone in a sound file**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
18

Arnaud Blanchard's avatar
Arnaud Blanchard committed
19
    i_sound.sh | o_sound.sh -f toto.wav
Arnaud Blanchard's avatar
Arnaud Blanchard committed
20

Arnaud Blanchard's avatar
Arnaud Blanchard committed
21
**Replay the sound on the speakers**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
22

Arnaud Blanchard's avatar
Arnaud Blanchard committed
23
    i_sound.sh -f toto.wav | o_sound.sh
Arnaud Blanchard's avatar
Arnaud Blanchard committed
24

Arnaud Blanchard's avatar
Arnaud Blanchard committed
25
**Show the graph of the file**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
26

Arnaud Blanchard's avatar
Arnaud Blanchard committed
27
    e_graph_sound.sh -f record.wav
Arnaud Blanchard's avatar
Arnaud Blanchard committed
28

Arnaud Blanchard's avatar
Arnaud Blanchard committed
29
**Graph a pure sinusoĩd at 440Hz (La)**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
30

Arnaud Blanchard's avatar
Arnaud Blanchard committed
31
    e_graph_sound.sh -F 440
Arnaud Blanchard's avatar
Arnaud Blanchard committed
32

33 34
![image](http://blaar.org/images/examples/graph_440Hz.png)

Arnaud Blanchard's avatar
Arnaud Blanchard committed
35 36
* -F is the frequency used to generate the sinusoïd

Arnaud Blanchard's avatar
Arnaud Blanchard committed
37
**Record the sound in a .tsv (tab separated values) file.**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
38
 
Arnaud Blanchard's avatar
Arnaud Blanchard committed
39
    i_sound.sh -o toto.tsv
Arnaud Blanchard's avatar
Arnaud Blanchard committed
40
    
Arnaud Blanchard's avatar
Arnaud Blanchard committed
41
**Play the 'La' in the speaker**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
42

Arnaud Blanchard's avatar
Arnaud Blanchard committed
43
    i_sound.sh -F 440 | o_sound.sh 
Arnaud Blanchard's avatar
Arnaud Blanchard committed
44

Arnaud Blanchard's avatar
Arnaud Blanchard committed
45 46
Spectrum (fft)
--------------
Arnaud Blanchard's avatar
Arnaud Blanchard committed
47

Arnaud Blanchard's avatar
Arnaud Blanchard committed
48
**Apply a fft on sound to get the spectrum and display the result in a graph**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
49

Arnaud Blanchard's avatar
Arnaud Blanchard committed
50
    e_graph_spectrum.sh
Arnaud Blanchard's avatar
Arnaud Blanchard committed
51

Arnaud Blanchard's avatar
Arnaud Blanchard committed
52
**Record the spectrum (fft) in a .tsv file ( tab separated values reading by excel, gnuplot , ...)**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
53

Arnaud Blanchard's avatar
Arnaud Blanchard committed
54 55
    i_spectrum.sh -o toto.tsv

Arnaud Blanchard's avatar
Arnaud Blanchard committed
56
**Apply a fft on a pure sinusoĩd signal of 440 and graph it**
Arnaud Blanchard's avatar
Arnaud Blanchard committed
57

Arnaud Blanchard's avatar
Arnaud Blanchard committed
58
    e_graph_spectrum.sh -F440 -X4000
Arnaud Blanchard's avatar
Arnaud Blanchard committed
59 60
    
![image](http://blaar.org/images/examples/spectrum_440Hz.png)
Arnaud Blanchard's avatar
Arnaud Blanchard committed
61

Arnaud Blanchard's avatar
Arnaud Blanchard committed
62
* -X represents the maximum frequency we want on the graph
Arnaud Blanchard's avatar
Arnaud Blanchard committed
63

Arnaud Blanchard's avatar
Arnaud Blanchard committed
64 65
Give the max of the frequency from the microphone
-------------------------------------------------
Arnaud Blanchard's avatar
Arnaud Blanchard committed
66

Arnaud Blanchard's avatar
Arnaud Blanchard committed
67
    i_spectrum.sh | f_max --find_arg=10.77 --output=-
Arnaud Blanchard's avatar
Arnaud Blanchard committed
68

Arnaud Blanchard's avatar
Arnaud Blanchard committed
69
* --find_arg means we do not want the value of max but the index of the max. 10.77 means we scale the index by 44100/4096 to convert index in Hz.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
70
* --output select where we want to put the output. '-' means it is not a channel but the terminal.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
71

Arnaud Blanchard's avatar
Arnaud Blanchard committed
72 73
Give the max of the 440Hz sinusoĩd
----------------------------------
Arnaud Blanchard's avatar
Arnaud Blanchard committed
74

Arnaud Blanchard's avatar
Arnaud Blanchard committed
75
    i_spectrum.sh -F440 | f_max --find_arg=10.77 --output=-
Arnaud Blanchard's avatar
Arnaud Blanchard committed
76

Arnaud Blanchard's avatar
Arnaud Blanchard committed
77
This return: 446.955017 on the terminal
Arnaud Blanchard's avatar
Arnaud Blanchard committed
78

Arnaud Blanchard's avatar
Arnaud Blanchard committed
79
The imprecision come from the discretisation of the fourier transform. If you take more items per buffer the precision is much better. i.e.:
Arnaud Blanchard's avatar
Arnaud Blanchard committed
80

Arnaud Blanchard's avatar
Arnaud Blanchard committed
81
    i_spectrum.sh -F440 -s32000 | f_max --find_arg=1.378 --output=-
Arnaud Blanchard's avatar
Arnaud Blanchard committed
82

Arnaud Blanchard's avatar
Arnaud Blanchard committed
83 84
* -s32000 means that we take a buffer of 32000 floats instead of the default 4096
* --find_arg=1.378 because 44100/32000 = 1.378
Arnaud Blanchard's avatar
Arnaud Blanchard committed
85

Arnaud Blanchard's avatar
Arnaud Blanchard committed
86
This return a value of 440.270996
Arnaud Blanchard's avatar
Arnaud Blanchard committed
87
The refresh rate is now only of 0.7s (32000/44100) before it was 93ms. We can play with the samplerate (-S) to improve it.
Arnaud Blanchard's avatar
Arnaud Blanchard committed
88 89 90