forked from well-typed-lightbulbs/rpi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ml
More file actions
22 lines (20 loc) · 649 Bytes
/
Copy pathmain.ml
File metadata and controls
22 lines (20 loc) · 649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Pwm = Rpi.Pwm.Make (struct
let mode = Rpi.Pwm.Analog
let pins = [Rpi.Pwm.Pin40; Rpi.Pwm.Pin41]
let freq = 54 * 1000000 / 2
let range = 0x264
let is_stereo = true
end)
let play_music () =
print_endline "loading music file";
(* we can create binary music files with [ffmpeg]:
ffmpeg -i audio.wav -f u8 -ar 44.1k -ac 2 audio.bin
we can load it into memory with [ocaml-crunch]:
ocaml-crunch music/ -e bin -o music.ml -m plain
*)
match Music.read "/audio.bin" with
| None -> failwith "no music"
| Some bytes -> String.iter (fun c -> Pwm.write (Char.code c)) bytes
let () =
Pwm.init ();
play_music ()