Skip to content

Commit

Permalink
match grub format
Browse files Browse the repository at this point in the history
  • Loading branch information
fulldecent committed Sep 25, 2024
1 parent 48d6ed5 commit a02d542
Show file tree
Hide file tree
Showing 9 changed files with 421 additions and 423 deletions.
70 changes: 35 additions & 35 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,42 @@ <h1>System Bus Radio</h1>
<section style="display:flex;width:60%;margin:auto">
<textarea style="width:2rem" id="progress" readonly></textarea>
<textarea style="flex:1;height:50rem" id="tune">
400 2673
400 2349
400 2093
400 2349
400 2673
400 0
400 2673
400 0
790 2673
400 2349
400 2349
400 0
790 2349
400 2673
400 3136
400 0
790 3136
400 2673
400 2349
400 2093
400 2349
400 2673
400 0
400 2673
400 0
400 2673
400 0
400 2673
400 2349
400 0
400 2349
400 2673
400 2349
790 2093</textarea>
2673 400
2349 400
2093 400
2349 400
2673 400
0 400
2673 400
0 400
2673 790
2349 400
2349 400
0 400
2349 790
2673 400
3136 400
0 400
3136 790
2673 400
2349 400
2093 400
2349 400
2673 400
0 400
2673 400
0 400
2673 400
0 400
2673 400
2349 400
0 400
2349 400
2673 400
2349 400
2093 790</textarea>
</section>
<p>Edit the above to make any music you like. <a href="https://github.com/fulldecent/system-bus-radio/issues/28">Tune file format</a> is time (ms) and frequency (Hz).</p>
<p>Edit the above to make any music you like. <a href="https://github.com/fulldecent/system-bus-radio/issues/28">Tune file format</a> is frequency (Hz) and time (ms).</p>
<p>Chrome has errors if you open this file locally (<code>file://</code>). Try using <code>php -S localhost:8000</code> or similar for a quick web server.</p>
<p>Ported by <a href="https://github.com/quanyang">Yeo Quan Yang</a> & maintained by <a href="https://github.com/rocketinventor">Elliot Gerchak</a>.</p>
<p>Original machine code by <a href="https://github.com/fulldecent">William Entriken</a>.</p>
Expand Down
10 changes: 5 additions & 5 deletions docs/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function now() {
var NSEC_PER_SEC = 1000000000;
var register = 3.1415;

function square_am_signal(time, freq) { // This funcion generates the radio waves
function square_am_signal(freq, time) { // This function generates the radio waves
postMessage("\nPlaying / " + time + " seconds / " + freq + "Hz");
var period = NSEC_PER_SEC / freq;
var start = now();
Expand All @@ -32,16 +32,16 @@ function square_am_signal(time, freq) { // This funcion generates the radio wave
function play(song) { // Parse song data, and call on required scripts to run it
song = song.split("\n");
var length = song.length;
var line, time, freq;
var line, freq, time;
for (var i = 0; i < length; i++) {
line = song[i].split(" ");
if (+line[1] == 0) {
pause(line[0]);
}
else {
freq = +line[1];
time = (+line[0])*.001;
square_am_signal(time, freq);
time = (+line[1])*.001;
freq = +line[0];
square_am_signal(freq, time);
}
}

Expand Down
6 changes: 3 additions & 3 deletions implementations/c-_mm_stream_si128/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ __m128i reg_one;
mach_port_t clock_port;
mach_timespec_t remain;

static inline void square_am_signal(float time, float frequency) {
static inline void square_am_signal(float frequency, float time) {
printf("Playing / %0.3f seconds / %4.0f Hz\n", time, frequency);
uint64_t period = NSEC_PER_SEC / frequency;

Expand Down Expand Up @@ -94,11 +94,11 @@ int main(int argc, char* argv[])
}

char buffer[20] = {0};
int time_ms;
int freq_hz;
int time_ms;
while (1) {
fgets(buffer, 20 - 1, fp);
if (sscanf(buffer, "%d %d", &time_ms, &freq_hz) == 2) {
if (sscanf(buffer, "%d %d", &freq_hz, &time_ms) == 2) {
square_am_signal(1.0 * time_ms / 1000, freq_hz);
}
if (feof(fp)) {
Expand Down
8 changes: 4 additions & 4 deletions implementations/c-neon-threads/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void perform_high_bus_activity(void) {
}
}

static inline void square_am_signal(uint64_t time_ms, uint64_t freq_hz) {
static inline void square_am_signal(uint64_t freq_hz, uint64_t time_ms) {
uint64_t start = mach_absolute_time();
uint64_t end = start + time_ms * 1000000 * timebase_info.denom / timebase_info.numer;

Expand Down Expand Up @@ -100,7 +100,7 @@ int main(int argc, char* argv[]) {
}

char buffer[64];
int time_ms, freq_hz;
int freq_hz, time_ms;

while (1) {
if (!fgets(buffer, sizeof(buffer), fp)) {
Expand All @@ -113,8 +113,8 @@ int main(int argc, char* argv[]) {
}
}

if (sscanf(buffer, "%d %d", &time_ms, &freq_hz) == 2) {
square_am_signal(time_ms, freq_hz);
if (sscanf(buffer, "%d %d", &freq_hz, &time_ms) == 2) {
square_am_signal(freq_hz, time_ms);
}
}

Expand Down
6 changes: 3 additions & 3 deletions implementations/cpp-counter-threads/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void boost_song() {
}
}

void square_am_signal(float time, float frequency) {
void square_am_signal(float frequency, float time) {
using namespace std::chrono;
std::cout << "Playing / " << time << " seconds / " << frequency << " Hz\n";

Expand Down Expand Up @@ -77,12 +77,12 @@ int main(int argc, char* argv[]) {
}

char buffer[64] = {0}; // Buffer for reading lines from file
int time_ms;
int freq_hz;
int time_ms;

while (true) {
if (fgets(buffer, sizeof(buffer) - 1, fp)) {
if (sscanf(buffer, "%d %d", &time_ms, &freq_hz) == 2) {
if (sscanf(buffer, "%d %d", &freq_hz, &time_ms) == 2) {
square_am_signal(1.0 * time_ms / 1000, freq_hz); // Convert ms to seconds
}
}
Expand Down
28 changes: 13 additions & 15 deletions tunes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ This file defines the `.tune` music file format.
Following is a simple example of the beginning parts of the *Super Mario Brothers* theme song:

```
100 660
150 0
100 660
300 0
100 660
300 0
100 510
660 100
0 150
660 100
0 300
660 100
0 300
510 100
```

## Full specification

1. Simple text file
2. Each line represents a beep or a pause
1. Column one is a positive integer number of milliseconds
2. Column two is a positive integer frequency in Hz, or `0` which represents silence
3. Columns are separated by a space
3. Line ending is unix format
4. File extension is `.tune`
5. Although not necessarily part of the tune, consider adding a silence at the end so that looped playback sounds good :-)
1. Each line in the file is `<frequency> <duration>`
1. `<frequency>` is the frequency of the beep in Hz or `0` for silence
2. `<duration>` is the duration of the beep in milliseconds
2. Line ending is unix format
3. File extension is `.tune`
4. Although not necessarily part of the tune, consider adding a silence at the end so that looped playback sounds good :-)

Note: this is compatible with the [GRUB_INIT_TUNE](https://wiki.archlinux.org/title/GRUB/Tips_and_tricks#Play_a_tune) when using a `TEMPO` of 60,000 (bpm).
54 changes: 27 additions & 27 deletions tunes/mary_had_a_little_lamb.tune
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
400 2673
400 2349
400 2093
400 2349
400 2673
400 2673
790 2673
400 2349
400 2349
790 2349
400 2673
400 3136
790 3136
400 2673
400 2349
400 2093
400 2349
400 2673
400 2673
400 2673
400 2673
400 2349
400 2349
400 2673
400 2349
790 2093
400 0
2673 400
2349 400
2093 400
2349 400
2673 400
2673 400
2673 790
2349 400
2349 400
2349 790
2673 400
3136 400
3136 790
2673 400
2349 400
2093 400
2349 400
2673 400
2673 400
2673 400
2673 400
2349 400
2349 400
2673 400
2349 400
2093 790
0 400
38 changes: 19 additions & 19 deletions tunes/morse_code_sos.tune
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
200 1000
200 0
200 1000
200 0
200 1000
200 0
600 1000
200 0
600 1000
200 0
600 1000
200 0
200 1000
200 0
200 1000
200 0
200 1000
200 0
1400 0
1000 200
0 200
1000 200
0 200
1000 200
0 200
1000 600
0 200
1000 600
0 200
1000 600
0 200
1000 200
0 200
1000 200
0 200
1000 200
0 200
0 1400
Loading

0 comments on commit a02d542

Please sign in to comment.