Inside a sine file
Disclaimer: This page is not made for phones
If you look at a sine file inside an editor like, for example, VScode and bypass the encoding warnings.
You'll see a jumbled mess of random characters. However, these "random" characters actually have
a meaning
So... how can you read it ?
In the project's official repo (see the sidebar), inside "tests/examples" you'll see a bunch of sine files. We will look at "repeatsignal.sine". The file should look like this in VScode.
␁SINEFILE␟10␟8000␟sine␂Ƹ␟Ǵ␝␀␟Ǵ␃SINEFILE␄
Please note that ␁ and other characters represent control characters (from U+0000 to U+001F). If you copy, for example, ␁, it will copy U+2401 and not U+0001
Let's break it down:
The header:
The file's "header" starts at ␁ and ends at
␂.
The file's different properties are split by the ␟ character.
So in that case, the file's header contains:
SINEFILE␟10␟8000␟sine
The header is always structured like this:
[file signature: "SINEFILE"], [repetition], [sample rate], [waveform]
The repetition property is where you can specify how many times the audio will repeat.
In that case, the audio will repeat 10 times at a sample rate of 8000 hz, using sine waves.
The Content:
The content of the file is an array of frequency-duration pairs. The pairs are seperated by ␝ and the pair's properties are seperated by ␟. Starting and ending by ␂ and ␃ respectively, the content of the current sine file is:
Ƹ␟Ǵ␝␀␟Ǵ
Now we need to understand that gibberish. First, we split the content into the 2 groups:
Ƹ␟Ǵ
and
␀␟Ǵ
Next, we seperate these groups' properties, giving us:
Ƹ, Ǵ
and
␀, Ǵ
Finally, we take the characters of these pairs and we get their numerical values, finally giving us:
440, 500
and 0, 500
However, these numbers mean nothing yet, that's beacause there are no units. Luckily,
all that we have to know is that the pairs' properties' units are respectively hertz and miliseconds.
So, to recap, we went from this:
Ƹ␟Ǵ␝␀␟Ǵ
to this:
440 hz, 500 ms
0 hz, 500 ms
The Footer:
The footer/end of the file, beggining with
␃ and ending
with ␄, is just the file signature ( SINEFILE
)
To conclude:
␁SINEFILE␟10␟8000␟sine␂Ƹ␟Ǵ␝␀␟Ǵ␃SINEFILE␄
translates to:
"Reapeat 10 times at a sample rate of 8000 hz, using sine waves, the waves: 440 hz for 500 ms and 0 hz for 500 ms"