Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up

  • Loading branch information...
commit 52f40985b0dd339cbb824f22ffd11c20987f67b9 1 parent 64ae4dc
@tism authored
Showing with 60 additions and 446 deletions.
  1. BIN  ffi.png
  2. +0 −139 frame_extract.rb
  3. +60 −307 native_gems.html
View
BIN  ffi.png
Deleted file not rendered
View
139 frame_extract.rb
@@ -1,139 +0,0 @@
-require 'ffi'
-require 'alsa'
-
-module Sox
- extend FFI::Library
- ffi_lib 'libsox'
-
- 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
-
- 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
-
- 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
-
- 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
-
- attach_function :sox_format_init, [ ], :int
- attach_function :sox_format_quit, [ ], :void
- attach_function :sox_open_read, [ :string, :pointer, :pointer, :string ], :pointer
- attach_function :sox_read, [ :pointer, :pointer, :uint ], :uint
- attach_function :sox_write, [ :pointer, :pointer, :uint ], :uint
- attach_function :sox_close, [ :pointer ], :int
-end
-
-TEST_FILE = '/home/lucas/Desktop/03. 19 - Adele - Chasing Pavements.flac'
-
-signal = Sox::SoxSignalinfoT.new
-encoding = Sox::SoxEncodinginfoT.new
-unless Sox.sox_format_init == 0
- raise 'omg'
-end
-
-format = Sox.sox_open_read(TEST_FILE, signal, encoding, nil)
-f = Sox::SoxFormat.new(format)
-puts f[:filename].get_string(0)
-# seconds
-channels = f[:signal][:channels]
-puts (f[:signal][:length]/channels)/f[:signal][:rate]
-
-sample_count = 4
-
-read_sample = FFI::MemoryPointer.new(:int, channels*sample_count)
-puts Sox.sox_read(format, read_sample, channels*sample_count)
-
-puts read_sample.size
-puts channels*sample_count
-(0..channels*sample_count).step(4) do |a|
- puts read_sample.get_int(a)
-end
-
-#ALSA::PCM::Playback.open do |playback|
-# playback.write do |length|
-# wavedata.read(length)
-# end
-#end
-
-Sox.sox_close(format)
-Sox.sox_format_quit
View
367 native_gems.html
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
-<head>
+ <head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <title>RORO September, 29th 2011 - An Introduction To FFI</title>
+ <title>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>
@@ -20,328 +20,81 @@
<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 > * {
+ font-size: 1.5em;
+ }
- body {
- background: #fff;
- }
+ 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
+ $(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();
- });
- </script>
+ SyntaxHighlighter.all();
+ });
+</script>
</head>
<body>
-<div class="slide">
- <div class="vcenter">
- <h1>An Introduction to FFI</h1>
- </div>
-</div>
+ <div class="slide">
+ <h1>Putting on SoX<br/>with FFI</h1>
+ </div>
-<div class="slide">
- <div class="vcenter">
- <h1>Why?</h1>
- </div>
-</div>
-
-<div class="slide">
- <h1>How?</h1>
+ <div class="slide">
<ul>
- <li>C Extensions</li>
- <li>FFI (Foreign Function Interface)</li>
- <li>RubyInline/ffi-inliner</li>
- <li>rb++</li>
+ <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>
+ </div>
+ <div class="slide">
<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>
+ <li>No compilation step</li>
+ <li>Multi-platform and multi-implementation</li>
+ <ul>
+ <li>MRI</li>
+ <li>JRuby</li>
+ <li>Rubinius</li>
+ <li>MacRuby</li>
+ </ul>
+ <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>
-<div class="slide">
- <h1>Bits 'n' Pieces</h1>
+ <div class="slide">
<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>
+ <li>FFI::Library</li>
+ <li>FFI::Pointer</li>
+ <li>FFI::MemoryPointer</li>
+ <li>FFI::Struct</li>
+ <li>FFI::ManagedStruct</li>
+ <li>FFI::Union</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_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 class="slide">
- <h1>Starting Simple</h1>
-
- <h2>FFI Module</h2>
- <pre class="brush: ruby">
- require 'ffi'
-
- module Sox
- extend FFI::Library
- ffi_lib 'libsox'
-
- SOX_SUCCESS = 0
-
- attach_function :sox_format_init, [], :int
- attach_function :sox_format_quit, [], :void
- end
- </pre>
-
- <h2>Usage</h2>
- <pre class="brush: ruby">
- unless Sox.sox_format_init == Sox::SOX_SUCCESS
- raise 'Unable to initialise sox'
- end
-
- // do something
-
- Sox.sox_format_quit
- </pre>
-</div>
-
-<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);
- </pre>
-
- <pre class="brush: ruby">
- attach_function :sox_open_read,
- [ :string, :pointer, :pointer, :string ],
- :pointer
- </pre>
-
- <pre class="brush: cpp">
- sox_size_t sox_read(
- sox_format_t ft,
- sox_sample_t *buf,
- sox_size_t len);
- </pre>
+ </div>
- <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>
+ <div class="layout" data-name="default">
+ <div class="vcenter">
+ <content></content>
+ </div>
+ </div>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.