Tuesday, January 5, 2010

Communicate with aliens on F# (continued)

Previously, we are talking with aliens in C#, Nemerle and Boo. Now let's try to do the same on F#.
See code below.

#light

 

open System

open Alvas.Audio

 

 

let rex = new RecorderEx(true);

let play = new PlayerEx(true);

let pcmFormat = AudioCompressionManager.GetPcmFormat(int16 1, int16 16, 44100);

 

let rex_Data (_) (e : DataEventArgs) : unit =

    let data = AudioCompressionManager.Reverse(pcmFormat, e.Data);

    ignore(play.AddData(data));

let rex_DataHandler = new RecorderEx.DataEventHandler(rex_Data)

rex.Data.AddHandler(rex_DataHandler)

 

let rex_Open _ _ = play.OpenPlayer(pcmFormat);

                   play.StartPlay();

let rex_OpenHandler = new EventHandler(rex_Open)

rex.Open.AddHandler(rex_OpenHandler)

 

let rex_Close _ _ = play.ClosePlayer();

let rex_CloseHandler = new EventHandler(rex_Close)

rex.Close.AddHandler(rex_CloseHandler)

 

rex.Format <- pcmFormat;

rex.StartRecord();

Console.WriteLine("Please press enter to exit!");

ignore(Console.ReadLine());

rex.StopRecord();


Enjoy:)
The source code and precompiled examples are here. (AudioConsFs.zip)

kick it on DotNetKicks.com

Shout it

2 comments:

  1. I am completely new to this world, just found you today while posting. Its funny to me and I want to make sure we are on the same page. I am communicating with aliens as well although I use the Relay Relay Relay method. I am unfamiliar with writing code but would love to learn.

    ReplyDelete
  2. Thank you for your message. Please propose topics and I'll write about them.

    ReplyDelete