1 (* Rudimentary testing of the Ocaml libsndfile wrapper. *)
3 let write_test filename =
4 let fmt = Sndfile.format Sndfile.MAJOR_WAV Sndfile.MINOR_PCM_16 in
5 let file = Sndfile.openfile ~info:(Sndfile.WRITE, fmt, 2, 44100) filename in
6 let writecount = Sndfile.write file [| 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.0 ; 0.5 |] in
7 Printf.printf "Wrote %d items.\n" writecount ;
10 let read_test filename =
11 let file = Sndfile.openfile filename in
12 Printf.printf "File contains %Ld frames.\n" (Sndfile.frames file) ;
13 let data = Array.create 100 0.0 in
14 let readcount = Sndfile.read file data in
15 Printf.printf "Read %d items.\n" readcount ;
18 let finalize_test filename =
20 let file = Sndfile.openfile filename in
23 (* Compact the heap. *)
25 let pre_stat = Gc.stat () in
27 (* Compact the heap again. *)
29 (* Compare before and after. *)
30 let post_stat = Gc.stat () in
31 if pre_stat.Gc.heap_words != post_stat.Gc.heap_words then
32 ( Printf.printf "\nFinalize not working : before %d -> after %d\n\n" pre_stat.Gc.heap_words post_stat.Gc.heap_words ;
37 let bad_read_test filename =
39 let file = Sndfile.openfile filename in
41 print_endline "Ooops, this should have failed." ;
44 Sndfile.Error (e, s) ->
45 if s = "System error." then () else
46 ( Printf.printf "Bad error '%s'\n" s ;
52 print_endline "------------------------" ;
53 let filename = "a.wav" in
56 finalize_test filename ;
57 bad_read_test "this_file_does_not_exist.wav" ;
58 print_endline "Done : All passed."