Permalink
Browse files

moving to svn

git-svn-id: svn://rubyforge.org/var/svn/daapclient/icha@129 d404eec9-990f-0410-b7b9-e628b63c8aec
  • Loading branch information...
aaronp
aaronp committed Feb 16, 2008
1 parent 43f7e58 commit 26218ec3b3296606a78251a23e3c61dc95df1f7e
View
@@ -0,0 +1,18 @@
+== 0.1.0
+
+* 1 major enhancement
+ * Added MPEG Encoder
+
+== 0.0.3
+* 1 minor enhancement
+ * Fixed extconf to be a little more smart.
+
+== 0.0.2
+* 1 major enhancement
+ * I can has ogg decoder!
+
+== 0.0.1 / 2007-07-10
+
+* 1 major enhancement
+ * I can has birfday!
+
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,26 @@
+History.txt
+LICENSE.txt
+Manifest.txt
+README.txt
+Rakefile
+examples/decoder.rb
+examples/kexp.rb
+ext/decoder.c
+ext/decoder.h
+ext/extconf.rb
+ext/get_audio.c
+ext/get_audio.h
+ext/icanhasaudio.c
+ext/icanhasaudio.h
+ext/mpeg_encoder.c
+ext/mpeg_encoder.h
+ext/rb_ogg.c
+ext/rb_wav.c
+ext/rb_wav.h
+ext/syncword.c
+ext/syncword.h
+lib/icanhasaudio/mpeg.rb
+lib/icanhasaudio/mpeg/encoder.rb
+lib/icanhasaudio/ogg.rb
+test/assets/testcase.wav
+test/test_mpeg_encoder.rb
View
@@ -0,0 +1,44 @@
+= Audio::MPEG
+
+ http://seattlerb.rubyforge.org/
+
+== DESCRIPTION. LULZ
+
+Hai! icanhasaudio? is an interface to lame for decoding ur MP3s. I iz in ur
+computer. Decodin ur mp3s. Whatevs! I also decodin ur OGGz!
+
+== SYNOPSYS ROFLOL
+
+ require 'icanhasaudio'
+
+ reader = Audio::MPEG::Decoder.new
+ File.open(ARGV[0], 'rb') { |input_lol|
+ File.open(ARGV[1], 'wb') { |output_lol|
+ reader.decode(input_lol, output_lol)
+ }
+ }
+
+Or even smaller:
+
+ reader = Audio::OGG::Decoder.new
+ reader.decode(File.open(ARGV[0], 'rb'), File.open(ARGV[1], 'wb'))
+
+== PROBLEMS
+
+Currently only decodes MP3/OGG data. Plus many other problems.... YMMV. LOL.
+Not laugh plz!
+
+== DEPENDENSEEZ
+
+Make sure lame is installed on ur 'puter. Also ogg and vorbisfile!
+
+== CREDITZ
+
+Thanx Ryan for mah name! Also, most of this code was taken from the lame
+front end. So thank you to the lame team! THX VORBIS!
+
+== LICENSE
+
+GPL. See LICENSE.txt
+
+KTHX BAI!
View
@@ -0,0 +1,30 @@
+require 'hoe'
+
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "lib")
+
+kind = Config::CONFIG["DLEXT"]
+
+Hoe.new('icanhasaudio', '0.1.0') do |p|
+ p.rubyforge_name = 'seattlerb'
+ p.author = 'Aaron Patterson'
+ p.email = 'aaronp@rubyforge.org'
+ p.summary = "icanhasaudio is a lame/vorbis wrapper for decoding ur mp3s and ur oggs."
+ p.description = p.paragraphs_of('README.txt', 3..6).join("\n\n")
+ p.url = p.paragraphs_of('README.txt', 1).first.strip
+ p.changes = p.paragraphs_of('History.txt', 0..2).join("\n\n")
+ p.spec_extras = { :extensions => ['ext/extconf.rb'] }
+ p.clean_globs = ["ext/Makefile", "ext/*.{o,so,bundle,log}"]
+end
+
+Rake::Task[:test].prerequisites << :extension
+
+desc "I can haz binary"
+task :extension => ["ext/icanhasaudio.#{kind}"]
+
+file "ext/Makefile" => "ext/extconf.rb" do
+ Dir.chdir("ext") { ruby "extconf.rb" }
+end
+
+file "ext/icanhasaudio.#{kind}" => FileList["ext/Makefile", "ext/*.{c,h}"] do
+ Dir.chdir("ext") { sh "make" }
+end
View
@@ -0,0 +1,8 @@
+require 'icanhasaudio'
+
+reader = Audio::MPEG::Decoder.new
+File.open(ARGV[0], 'rb') { |mp3|
+ File.open(ARGV[1], 'wb') { |out|
+ reader.decode(mp3, out);
+ }
+}
View
@@ -0,0 +1,27 @@
+require 'rubygems'
+require 'raop'
+require 'icanhasaudio'
+require 'socket'
+
+rd, wr = IO.pipe
+puts Audio::MPEG::Decoder.lame_version
+
+decoder = Thread.new(rd, wr) { |read, write|
+ reader = Audio::MPEG::Decoder.new
+ socket = TCPSocket.new('kexp-mp3-128k.cac.washington.edu', '8000')
+ socket.puts("GET / HTTP/1.0\r\n\r\n")
+ until(socket.readline == "\r\n"); end
+ reader.decode(socket, write);
+ write.close
+}
+
+sleep 2
+
+raop = Net::RAOP::Client.new('192.168.1.173')
+raop.connect
+raop.play rd
+raop.disconnect
+rd.close
+
+decoder.join
+
View
@@ -0,0 +1,101 @@
+#include <ruby.h>
+#include <lame/lame.h>
+#include <assert.h>
+#include <decoder.h>
+#include <get_audio.h>
+#include <rb_wav.h>
+
+int
+lame_decoder(VALUE self, VALUE infile, VALUE outf, mp3data_struct * mp3data)
+{
+ lame_global_flags * gfp;
+ short int Buffer[2][1152];
+ int iread;
+ double wavsize;
+ int i;
+ int tmp_num_channels;
+ int skip;
+ char headbuf[44];
+ VALUE raw;
+
+ raw = rb_iv_get(self, "@raw");
+ if(raw == Qnil) {
+ raw = Qfalse;
+ rb_iv_set(self, "@raw", Qfalse);
+ }
+
+ Data_Get_Struct(self, lame_global_flags, gfp);
+ tmp_num_channels = lame_get_num_channels( gfp );
+
+ skip = lame_get_encoder_delay(gfp)+528+1;
+
+ if(!raw) {
+ rb_iv_set(self, "@bits", INT2NUM(16));
+ prelim_header( self,
+ headbuf,
+ 0x7FFFFFFF,
+ 0,
+ tmp_num_channels,
+ lame_get_in_samplerate( gfp )
+ );
+ rb_funcall(outf, rb_intern("write"), 1, rb_str_new(headbuf, 44));
+ }
+
+ wavsize = -skip;
+ mp3data->totalframes = mp3data->nsamp / mp3data->framesize;
+
+ assert(tmp_num_channels >= 1 && tmp_num_channels <= 2);
+
+ do {
+ char BitBuffer16[1152 * 4];
+ int bit_16_i = 0;
+ int total = 0;
+ iread = get_audio16(self, infile, Buffer, mp3data);
+ mp3data->framenum += iread / mp3data->framesize;
+ wavsize += iread;
+
+ memset(&BitBuffer16, 0, 1152 * 4);
+
+ skip -= (i = skip < iread ? skip : iread); /* 'i' samples are to skip in this frame */
+
+ for (; i < iread; i++) {
+ /* Write the 0 channel */
+ BitBuffer16[bit_16_i] = Buffer[0][i] & 0xFF;
+ BitBuffer16[bit_16_i + 1] = ((Buffer[0][i] >> 8) & 0xFF);
+
+ if (tmp_num_channels == 2) {
+ BitBuffer16[bit_16_i + 2] = Buffer[1][i] & 0xFF;
+ BitBuffer16[bit_16_i + 3] = ((Buffer[1][i] >> 8) & 0xFF);
+ bit_16_i += 4;
+ } else {
+ bit_16_i += 2;
+ }
+ }
+ rb_funcall(outf, rb_intern("write"), 1, rb_str_new(BitBuffer16, bit_16_i));
+ } while (iread);
+
+ i = (16 / 8) * tmp_num_channels;
+ assert(i > 0);
+ if (wavsize <= 0) {
+ wavsize = 0;
+ }
+ else if (wavsize > 0xFFFFFFD0 / i) {
+ wavsize = 0xFFFFFFD0;
+ }
+ else {
+ wavsize *= i;
+ }
+
+ if(!raw && rb_respond_to(outf, rb_intern("seek")) == Qtrue) {
+ rb_funcall( outf,
+ rb_intern("seek"),
+ 2,
+ INT2NUM(0),
+ rb_const_get(rb_cIO, rb_intern("SEEK_SET")) );
+
+ rewrite_header(headbuf, (int)wavsize);
+ rb_funcall(outf, rb_intern("write"), 1, rb_str_new(headbuf, 44));
+ }
+ return 0;
+}
+
View
@@ -0,0 +1,3 @@
+int
+lame_decoder(VALUE self, VALUE infile, VALUE outf, mp3data_struct * mp3data);
+
View
@@ -0,0 +1,54 @@
+ENV["ARCHFLAGS"] = "-arch #{`uname -p` =~ /powerpc/ ? 'ppc' : 'i386'}"
+
+require 'mkmf'
+
+def exit_failure(msg)
+ Logging::message msg
+ message msg + "\n"
+ exit(1)
+end
+
+unless respond_to?(:find_header)
+ def find_header(header, *paths)
+ header = cpp_include(header)
+ checking_for header do
+ if try_cpp(header)
+ true
+ else
+ found = false
+ paths.each do |dir|
+ opt = "-I#{dir}".quote
+ if try_cpp(header, opt)
+ $CPPFLAGS << " " << opt
+ found = true
+ break
+ end
+ end
+ found
+ end
+ end
+ end
+end
+
+['lame/lame.h', 'ogg/ogg.h', 'vorbis/vorbisfile.h'].each do |hf|
+ unless find_header(hf,
+ '/opt/local/include',
+ '/usr/local/include',
+ '/usr/include'
+ )
+ exit_failure "Can't find #{hf}"
+ end
+end
+
+['mp3lame', 'vorbis', 'vorbisfile'].each do |library|
+ unless find_library(library, nil,
+ '/opt/local/lib',
+ '/usr/local/lib',
+ '/usr/lib'
+ )
+ exit_failure "Can't find #{library}"
+ end
+end
+
+dir_config('icanhasaudio')
+create_makefile('icanhasaudio')
Oops, something went wrong.

0 comments on commit 26218ec

Please sign in to comment.