Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updates

  • Loading branch information...
commit 64ae4dc331d97c1f768c524a5d20112d3c547468 1 parent 0d8b6e5
@tism authored
Showing with 302 additions and 143 deletions.
  1. +302 −143 native_gems.html
View
445 native_gems.html
@@ -1,133 +1,134 @@
<!DOCTYPE html>
<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <title>RORO September, 29th 2011 - An Introduction To FFI</title>
- <!-- Slippy core file and dependencies -->
- <script type="text/javascript" src="slippy/src/jquery.min.js"></script>
- <script type="text/javascript" src="slippy/src/jquery.history.js"></script>
- <script type="text/javascript" src="slippy/src/slippy.js"></script>
- <!-- Slippy structural styles -->
- <link type="text/css" rel="stylesheet" href="slippy/src/slippy.css"/>
- <!-- Slippy theme -->
- <link type="text/css" rel="stylesheet" href="slippy/src/slippy-pure.css"/>
- <!-- Syntax highlighting core file -->
- <script type="text/javascript" src="slippy/src/highlighter/shCore.js"></script>
- <!-- Syntax highlighting brushes, remove those you don't need -->
- <script type="text/javascript" src="slippy/src/highlighter/shBrushBash.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushCpp.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushCSharp.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushCss.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushDelphi.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushDiff.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushGroovy.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushJava.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushJScript.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushPhp.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushPlain.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushPython.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushRuby.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushScala.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushSql.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushVb.js"></script>
- <script type="text/javascript" src="slippy/src/highlighter/shBrushXml.js"></script>
- <!-- Syntax highlighting styles-->
- <link type="text/css" rel="stylesheet" href="slippy/src/highlighter/shCore.css"/>
- <link type="text/css" rel="stylesheet" href="slippy/src/highlighter/shThemeEclipse.css"/>
- <!-- Slippy init code -->
- <script type="text/javascript">
- $(function() {
- $(".slide").slippy({
- // settings go here
- // possible values are:
- // - animLen, duration for default animations (0 = disabled)
- // - animInForward, receives a slide and animates it
- // - animInRewind, receives a slide and animates it
- // - animOutForward, receives a slide and animates it
- // - animOutRewind, receives a slide and animates it
- // - baseWidth, defines the base for img resizing, if you don't want only
- // full-width images, specify this as the pixel width of a slide so that
- // images are scaled properly (default is 620px wide)
- // - ratio, defines the width/height ratio of the slides, defaults to 1.3 (620x476)
- // - margin, the fraction of screen to use as slide margin, defaults to 0.15
- });
- SyntaxHighlighter.all();
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+ <title>RORO September, 29th 2011 - An Introduction To FFI</title>
+ <!-- Slippy core file and dependencies -->
+ <script type="text/javascript" src="slippy/src/jquery.min.js"></script>
+ <script type="text/javascript" src="slippy/src/jquery.history.js"></script>
+ <script type="text/javascript" src="slippy/src/slippy.js"></script>
+ <!-- Slippy structural styles -->
+ <link type="text/css" rel="stylesheet" href="slippy/src/slippy.css"/>
+ <!-- Slippy theme -->
+ <link type="text/css" rel="stylesheet" href="slippy/src/slippy-pure.css"/>
+ <!-- Syntax highlighting core file -->
+ <script type="text/javascript" src="slippy/src/highlighter/shCore.js"></script>
+ <!-- Syntax highlighting brushes, remove those you don't need -->
+ <script type="text/javascript" src="slippy/src/highlighter/shBrushCpp.js"></script>
+ <script type="text/javascript" src="slippy/src/highlighter/shBrushRuby.js"></script>
+ <!-- Syntax highlighting styles-->
+ <link type="text/css" rel="stylesheet" href="slippy/src/highlighter/shCore.css"/>
+ <link type="text/css" rel="stylesheet" href="slippy/src/highlighter/shThemeEclipse.css"/>
+ <style type="text/css">
+ body > * {
+ font-size: 1.1em;
+ }
+
+ body {
+ background: #fff;
+ }
+ </style>
+ <!-- Slippy init code -->
+ <script type="text/javascript">
+ $(function() {
+ $(".slide").slippy({
+ // settings go here
+ // possible values are:
+ // - animLen, duration for default animations (0 = disabled)
+ // - animInForward, receives a slide and animates it
+ // - animInRewind, receives a slide and animates it
+ // - animOutForward, receives a slide and animates it
+ // - animOutRewind, receives a slide and animates it
+ // - baseWidth, defines the base for img resizing, if you don't want only
+ // full-width images, specify this as the pixel width of a slide so that
+ // images are scaled properly (default is 620px wide)
+ // - ratio, defines the width/height ratio of the slides, defaults to 1.3 (620x476)
+ // - margin, the fraction of screen to use as slide margin, defaults to 0.15
});
- </script>
- </head>
- <body>
- <div class="slide">
- <h1>An Introduction to FFI</h1>
- </div>
-
- <div class="slide">
- <h1>Why?</h1>
- </div>
-
- <div class="slide">
- <h1>How?</h1>
- <ul>
- <li>C Extensions</li>
- <li>FFI (Foreign Function Interface)</li>
- <li>RubyInline/ffi-inliner</li>
- <li>rb++</li>
- </ul>
- </div>
-
- <div class="slide">
- <h1>FFI</h1>
-
- <ul>
- <li>No compilation step</li>
- <li>Multi-platform and multi-implementation (MRI, JRuby, Rubinius, MacRuby)</li>
- <li>Easy to read</li>
- <li>Easy to write</li>
- <li>Impervious to changes in the Ruby internal API</li>
- </ul>
- </div>
-
- <div class="slide">
- <h1>How's it work?</h1>
- <img src="ffi.png"/>
- </div>
-
- <div class="slide">
- <h1>Bits 'n' Pieces</h1>
- <ul>
- <li>FFI::Library</li>
- <li>FFI::Pointer</li>
- <li>FFI::MemoryPointer</li>
- <li>FFI::Struct</li>
- <li>FFI::Union</li>
- <li>FFI::ManagedStruct</li>
- </ul>
- </div>
-
- <div class="slide">
- <h1>Sox</h1>
+ SyntaxHighlighter.all();
+ });
+ </script>
+</head>
+<body>
+
+<div class="slide">
+ <div class="vcenter">
+ <h1>An Introduction to FFI</h1>
+ </div>
+</div>
+
+<div class="slide">
+ <div class="vcenter">
+ <h1>Why?</h1>
+ </div>
+</div>
+
+<div class="slide">
+ <h1>How?</h1>
+ <ul>
+ <li>C Extensions</li>
+ <li>FFI (Foreign Function Interface)</li>
+ <li>RubyInline/ffi-inliner</li>
+ <li>rb++</li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>FFI</h1>
+
+ <ul>
+ <li>No compilation step</li>
+ <li>Multi-platform and multi-implementation (MRI, JRuby, Rubinius, MacRuby)</li>
+ <li>Easy to read</li>
+ <li>Easy to write</li>
+ <li>Impervious to changes in the Ruby internal API</li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>How's it work?</h1>
+ <img src="ffi.png"/>
+</div>
+
+<div class="slide">
+ <h1>Bits 'n' Pieces</h1>
+ <ul>
+ <li>FFI::Library</li>
+ <li>FFI::Pointer</li>
+ <li>FFI::MemoryPointer</li>
+ <li>FFI::Struct</li>
+ <li>FFI::Union</li>
+ <li>FFI::ManagedStruct</li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>Sox</h1>
<pre class="brush: cpp">
int sox_format_init(void);
- sox_format_t sox_open_read(const char *path,
- const sox_signalinfo_t *info,
- const sox_encodinginfo_t *encoding,
- const char *filetype);
+ sox_format_t sox_open_read(
+ const char *path,
+ const sox_signalinfo_t *info,
+ const sox_encodinginfo_t *encoding,
+ const char *filetype);
- sox_size_t sox_read(sox_format_t ft,
- sox_sample_t *buf,
- sox_size_t len);
+ sox_size_t sox_read(
+ sox_format_t ft,
+ sox_sample_t *buf,
+ sox_size_t len);
int sox_close(sox_format_t ft);
void sox_format_quit(void);
</pre>
- </div>
+</div>
- <div class="slide">
- <h1>Starting Simple</h1>
+<div class="slide">
+ <h1>Starting Simple</h1>
- <h2>FFI Module</h2>
+ <h2>FFI Module</h2>
<pre class="brush: ruby">
require 'ffi'
@@ -142,7 +143,7 @@
end
</pre>
- <h2>Usage</h2>
+ <h2>Usage</h2>
<pre class="brush: ruby">
unless Sox.sox_format_init == Sox::SOX_SUCCESS
raise 'Unable to initialise sox'
@@ -152,37 +153,195 @@
Sox.sox_format_quit
</pre>
- </div>
+</div>
- <div class="slide">
- <h1>Not So Simple</h1>
+<div class="slide">
+ <h1>Not So Simple</h1>
<pre class="brush: cpp">
- sox_format_t sox_open_read(const char *path,
- const sox_signalinfo_t *info,
- const sox_encodinginfo_t *encoding,
- const char *filetype);
+ sox_format_t sox_open_read(
+ const char *path,
+ const sox_signalinfo_t *info,
+ const sox_encodinginfo_t *encoding,
+ const char *filetype);
</pre>
<pre class="brush: ruby">
- attach_function :sox_open_read, [ :string, :pointer, :pointer, :string ], :pointer
+ attach_function :sox_open_read,
+ [ :string, :pointer, :pointer, :string ],
+ :pointer
</pre>
- </div>
-
- <div class="slide">
- <h1></h1>
-
- <pre class="brush: cpp"> sox_size_t sox_read(sox_format_t ft,
- sox_sample_t *buf,
- sox_size_t len);
- int sox_close(sox_format_t ft);
- </pre>
- </div>
-
- <div class="layout" data-name="default">
- <div class="vcenter">
- <content></content>
- </div>
- </div>
- </body>
- </html>
+
+ <pre class="brush: cpp">
+ sox_size_t sox_read(
+ sox_format_t ft,
+ sox_sample_t *buf,
+ sox_size_t len);
+ </pre>
+
+ <pre class="brush: ruby">
+ attach_function :sox_read,
+ [ :pointer, :pointer, :uint ],
+ :uint
+ </pre>
+</div>
+
+<div class="slide">
+ <h1>Struct Mapping</h1>
+
+ <pre class="brush: ruby">
+ class SoxSignalinfoT < FFI::Struct
+ layout(
+ :rate, :double,
+ :channels, :uint,
+ :precision, :uint,
+ :length, :uint,
+ :mult, :pointer
+ )
+ end
+
+ class SoxEncodinginfoT < FFI::Struct
+ layout(
+ :encoding, :int,
+ :bits_per_sample, :uint,
+ :compression, :double,
+ :reverse_bytes, :int,
+ :reverse_nibbles, :int,
+ :reverse_bits, :int,
+ :opposite_endian, :int
+ )
+ end
+ </pre>
+</div>
+
+<div class="slide">
+ <h1>Struct Mapping</h1>
+
+ <pre class="brush: ruby">
+ class SoxInstrinfoT < FFI::Struct
+ layout(
+ :MIDInote, :char,
+ :MIDIlow, :char,
+ :MIDIhi, :char,
+ :loopmode, :char,
+ :nloops, :uint
+ )
+ end
+
+ class SoxLoopinfoT < FFI::Struct
+ layout(
+ :start, :uint,
+ :length, :uint,
+ :count, :uint,
+ :type, :uchar
+ )
+ end
+
+ class SoxOobT < FFI::Struct
+ layout(
+ :comments, :pointer,
+ :instr, SoxInstrinfoT,
+ :loops, [SoxLoopinfoT, 8]
+ )
+ end
+ </pre>
+</div>
+
+<div class="slide">
+ <h1>Struct Mapping</h1>
+
+ <pre class="brush: ruby">
+ class SoxFormatHandlerT < FFI::Struct
+ layout(
+ :sox_lib_version_code, :uint,
+ :description, :pointer,
+ :names, :pointer,
+ :flags, :uint,
+ :startread, callback([ :pointer ], :int),
+ :read, callback([ :pointer, :pointer, :uint ],
+ :size_t),
+ :stopread, callback([ :pointer ], :int),
+ :startwrite, callback([ :pointer ], :int),
+ :write, callback([ :pointer, :pointer, :uint ],
+ :size_t),
+ :stopwrite, callback([ :pointer ], :int),
+ :seek, callback([ :pointer, :ulong_long ], :int),
+ :write_formats, :pointer,
+ :write_rates, :pointer,
+ :priv_size, :uint
+ )
+ end
+ </pre>
+</div>
+
+<div class="slide">
+ <h1>Struct Mapping</h1>
+
+ <pre class="brush: ruby">
+ class SoxFormat < FFI::Struct
+ layout(
+ :filename, :pointer,
+ :signal, SoxSignalinfoT,
+ :encoding, SoxEncodinginfoT,
+ :filetype, :pointer,
+ :oob, SoxOobT,
+ :seekable, :int,
+ :mode, :char,
+ :olength, :uint,
+ :clips, :uint,
+ :sox_errno, :int,
+ :sox_errstr, [:char, 256],
+ :fp, :pointer,
+ :io_type, :int,
+ :tell_off, :long,
+ :data_start, :long,
+ :handler, SoxFormatHandlerT,
+ :priv, :pointer
+ )
+ end
+ </pre>
+</div>
+
+<div class="slide">
+ <h1>Using It</h1>
+
+ <pre class="brush: ruby">
+ TEST_FILE = '/path/to/file'
+
+ Sox.sox_format_init
+
+ signal = Sox::SoxSignalinfoT.new
+ encoding = Sox::SoxEncodinginfoT.new
+
+ format_pointer = Sox.sox_open_read(TEST_FILE,
+ signal,
+ encoding,
+ nil)
+ format = Sox::SoxFormat.new(format)
+
+ format[:filename].get_string(0) == TEST_FILE
+ </pre>
+</div>
+
+<div class="slide">
+ <h1>Using It</h1>
+
+ <pre class="brush: ruby">
+ samples_to_read = 8
+
+ sample_buffer = FFI::MemoryPointer.new(:int,
+ samples_to_read)
+
+ Sox.sox_read(format,
+ sample_buffer,
+ samples_to_read) == samples_to_read
+
+ sample_buffer.get_int(0)
+ </pre>
+</div>
+
+<div class="layout" data-name="default">
+ <content></content>
+</div>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.