Skip to content

Instantly share code, notes, and snippets.

@soutys
Created December 15, 2015 05:47
Show Gist options
  • Save soutys/22b67a5df9ae0a6f1f72 to your computer and use it in GitHub Desktop.
Save soutys/22b67a5df9ae0a6f1f72 to your computer and use it in GitHub Desktop.
module Lame = struct
type encoder
let encode_buffer_float_part enc fbl fbr start len = "le Lame"
end
module Other = struct
type encoder
let encode_buffer_float_part enc fbl fbr start len = "le Other"
end
module Output = struct
class virtual ['a] base enc_fn =
object (self)
method encode (e : 'a) (b : float array array) (start : int) (len : int) : string =
enc_fn e b.(0) b.(0) start len
end
class virtual ['a] encoded source =
object (self)
method virtual encode : 'a -> float array array -> int -> int -> string
method doenc enc_t frame start len =
self#encode enc_t frame start len;
end
end
module Streamer = struct
class prop =
object(self)
end
class virtual ['a] output (p:prop) =
object (self)
inherit ['a] Output.encoded p as super
end
end
module Lamefmt = struct
class prop =
object(self)
inherit Streamer.prop
end
class sout p =
object (self)
inherit [Lame.encoder] Streamer.output (p:>Streamer.prop) as super
inherit [Lame.encoder] Output.base Lame.encode_buffer_float_part
end
end
module Otherfmt = struct
class prop =
object(self)
inherit Streamer.prop
end
class sout p =
object (self)
inherit [Other.encoder] Streamer.output (p:>Streamer.prop) as super
inherit [Other.encoder] Output.base Other.encode_buffer_float_part
end
end
type 'a term = Save of 'a
let main () =
let format_num = int_of_string Sys.argv.(1)
in
begin
let sp =
if format_num = 1 then
new Lamefmt.prop
else
new Otherfmt.prop
in
let fmt =
if format_num = 1 then
new Lamefmt.sout sp
else
new Otherfmt.sout sp
in
let enc_t =
if format_num = 1 then
Save Lame.encoder
else
Save Other.encoder
in
fmt#doenc enc_t [|[|1.|]; [|2.|]|] 0 1
end
let _ = main ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment