Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

housecleaning

  • Loading branch information...
commit 16dfb7efedee4c57958e527765bf2b072ad887f7 1 parent cddf486
@tenderlove authored
View
19 Rakefile
@@ -11,19 +11,24 @@ Hoe.new('icanhasaudio', '0.1.1') do |p|
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.spec_extras = { :extensions => ['ext/extconf.rb'] }
- p.clean_globs = ["ext/Makefile", "ext/*.{o,so,bundle,log}"]
+ p.spec_extras = {
+ :extensions => ['ext/icanhasaudio/extconf.rb']
+ }
+ p.clean_globs = [
+ "ext/icanhasaudio/Makefile",
+ "ext/icanhasaudio/*.{o,so,bundle,log}"
+ ]
end
Rake::Task[:test].prerequisites << :extension
desc "I can haz binary"
-task :extension => ["ext/icanhasaudio.#{kind}"]
+task :extension => ["ext/icanhasaudio/native.#{kind}"]
-file "ext/Makefile" => "ext/extconf.rb" do
- Dir.chdir("ext") { ruby "extconf.rb" }
+file "ext/icanhasaudio/Makefile" => "ext/icanhasaudio/extconf.rb" do
+ Dir.chdir("ext/icanhasaudio") { ruby "extconf.rb" }
end
-file "ext/icanhasaudio.#{kind}" => FileList["ext/Makefile", "ext/*.{c,h}"] do
- Dir.chdir("ext") { sh "make" }
+file "ext/icanhasaudio/native.#{kind}" => FileList["ext/icanhasaudio/Makefile", "ext/icanhasaudio/*.{c,h}"] do
+ Dir.chdir("ext/icanhasaudio") { sh "make" }
end
View
35 ext/icanhasaudio.c → ext/icanhasaudio/audio_mpeg_decoder.c
@@ -6,13 +6,7 @@
*
* Released under the GPL
*/
-#include <icanhasaudio.h>
-
-static VALUE rb_mAudio;
-static VALUE rb_mMpeg;
-static VALUE rb_cDecoder;
-static VALUE rb_mOgg;
-static VALUE rb_cOggDecoder;
+#include <native.h>
static void reader_mark(lame_global_flags * lgf) {}
static void reader_free(lame_global_flags * gfp) {
@@ -21,14 +15,6 @@ static void reader_free(lame_global_flags * gfp) {
/*
* call-seq:
- * decoder.decode(input_io, output_io)
- *
- * Decode the input IO and write it to the output IO.
- */
-VALUE method_ogg_decode(VALUE self, VALUE infile, VALUE outf);
-
-/*
- * call-seq:
* Audio::MPEG::Decoder.new
*
* Returns a new MPEG Decoder object.
@@ -151,16 +137,11 @@ static VALUE method_lame_decode(VALUE self, VALUE file, VALUE outf) {
return Qnil;
}
-void Init_icanhasaudio() {
- rb_mAudio = rb_define_module("Audio");
- rb_mMpeg = rb_define_module_under(rb_mAudio, "MPEG");
- rb_cDecoder = rb_define_class_under(rb_mMpeg, "Decoder", rb_cObject);
-
- rb_mOgg = rb_define_module_under(rb_mAudio, "OGG");
- rb_cOggDecoder = rb_define_class_under(rb_mOgg, "Decoder", rb_cObject);
+void init_audio_mpeg_decoder() {
+ VALUE rb_mAudio = rb_define_module("Audio");
+ VALUE rb_mMpeg = rb_define_module_under(rb_mAudio, "MPEG");
+ VALUE rb_cDecoder = rb_define_class_under(rb_mMpeg, "Decoder", rb_cObject);
- /* VERSION = '0.1.1' */
- rb_define_const(rb_cDecoder, "VERSION", rb_str_new2("0.1.1"));
rb_define_singleton_method(
rb_cDecoder,
"lame_version",
@@ -170,10 +151,4 @@ void Init_icanhasaudio() {
rb_define_alloc_func(rb_cDecoder, reader_allocate);
rb_define_method(rb_cDecoder, "decode", method_lame_decode, 2);
- rb_define_method(rb_cOggDecoder, "decode", method_ogg_decode, 2);
-
- init_MpegEncoder(rb_mMpeg);
- rb_require("icanhasaudio/mpeg");
- rb_require("icanhasaudio/ogg");
}
-
View
8 ext/icanhasaudio/audio_mpeg_decoder.h
@@ -0,0 +1,8 @@
+#ifndef AUDIO_MPEG_DECODER_H
+#define AUDIO_MPEG_DECODER_H
+
+#include <native.h>
+
+void init_audio_mpeg_decoder();
+
+#endif
View
33 ext/mpeg_encoder.c → ext/icanhasaudio/audio_mpeg_encoder.c
@@ -1,8 +1,7 @@
-#include <icanhasaudio.h>
+#include <native.h>
-static VALUE cMpegEncoder;
-
-static void encoder_free(lame_global_flags * gfp) {
+static void encoder_free(lame_global_flags * gfp)
+{
lame_close(gfp);
}
@@ -12,8 +11,8 @@ static void encoder_free(lame_global_flags * gfp) {
*
* Returns a new MPEG Encoder object.
*/
-static VALUE
-encoder_allocate(VALUE klass) {
+static VALUE encoder_allocate(VALUE klass)
+{
lame_global_flags * gfp = lame_init();
id3tag_init(gfp);
@@ -29,7 +28,8 @@ encoder_allocate(VALUE klass) {
* Strictly enforce the vbr min bitrate. Normally it will be violated for
* analog silence.
*/
-static VALUE MpegEncoder_set_vbr_hard_min(VALUE self, VALUE boolean) {
+static VALUE MpegEncoder_set_vbr_hard_min(VALUE self, VALUE boolean)
+{
lame_global_flags * gfp;
Data_Get_Struct(self, lame_global_flags, gfp);
@@ -43,7 +43,8 @@ static VALUE MpegEncoder_set_vbr_hard_min(VALUE self, VALUE boolean) {
*
* Get the hard minimum flag.
*/
-static VALUE MpegEncoder_get_vbr_hard_min(VALUE self) {
+static VALUE MpegEncoder_get_vbr_hard_min(VALUE self)
+{
lame_global_flags * gfp;
Data_Get_Struct(self, lame_global_flags, gfp);
@@ -56,7 +57,8 @@ static VALUE MpegEncoder_get_vbr_hard_min(VALUE self) {
*
* Set the maximum vbr bitrate.
*/
-static VALUE MpegEncoder_set_vbr_max_bitrate(VALUE self, VALUE brate) {
+static VALUE MpegEncoder_set_vbr_max_bitrate(VALUE self, VALUE brate)
+{
lame_global_flags * gfp;
Data_Get_Struct(self, lame_global_flags, gfp);
@@ -580,19 +582,16 @@ static VALUE MpegEncoder_init_params(VALUE self) {
return Qnil;
}
-void init_MpegEncoder(VALUE rb_mMpeg) {
- /*
- rb_mAudio = rb_define_module("Audio");
- rb_mMpeg = rb_define_module_under(rb_mAudio, "MPEG");
- */
+void init_audio_mpeg_encoder()
+{
+ VALUE rb_mAudio = rb_define_module("Audio");
+ VALUE rb_mMpeg = rb_define_module_under(rb_mAudio, "MPEG");
/*
* Encode mp3s
*/
- cMpegEncoder = rb_define_class_under(rb_mMpeg, "Encoder", rb_cObject);
+ VALUE cMpegEncoder = rb_define_class_under(rb_mMpeg, "Encoder", rb_cObject);
rb_define_alloc_func(cMpegEncoder, encoder_allocate);
- /* Public Methods */
-
rb_define_method(cMpegEncoder, "vbr_quality=",MpegEncoder_set_vbr_quality, 1);
rb_define_method(cMpegEncoder, "vbr_quality", MpegEncoder_get_vbr_quality, 0);
rb_define_method(cMpegEncoder, "vbr_type=", MpegEncoder_set_vbr_type, 1);
View
3  ext/mpeg_encoder.h → ext/icanhasaudio/audio_mpeg_encoder.h
@@ -2,6 +2,7 @@
#define MPEG_ENCODER_H
#define LAME_MAXMP3BUFFER 16384
-void init_MpegEncoder(VALUE mMpeg);
+
+void init_audio_mpeg_encoder();
#endif
View
24 ext/rb_ogg.c → ext/icanhasaudio/audio_ogg_decoder.c
@@ -1,6 +1,10 @@
-#include <icanhasaudio.h>
+#include <native.h>
-size_t rb_ogg_read(void *ptr, size_t size, size_t nmemb, void *datasource) {
+static size_t rb_ogg_read( void *ptr,
+ size_t size,
+ size_t nmemb,
+ void *datasource)
+{
VALUE file = (VALUE)datasource;
VALUE str;
size_t length;
@@ -26,24 +30,24 @@ int rb_ogg_seek(void *datasource, ogg_int64_t offset, int whence) {
return -1;
}
-int rb_ogg_close(void *datasource) {
+static int rb_ogg_close(void *datasource) {
VALUE file = (VALUE)datasource;
rb_funcall(file, rb_intern("close"), 0);
return 0;
}
-long rb_ogg_tell(void *datasource) {
+static long rb_ogg_tell(void *datasource) {
VALUE file = (VALUE)datasource;
return NUM2LONG(rb_funcall(file, rb_intern("tell"), 0));
}
/*
* call-seq:
- * decoder.decode(input_io, output_io)
+ * decode(input_io, output_io)
*
* Decode the input IO and write it to the output IO.
*/
-VALUE method_ogg_decode(VALUE self, VALUE infile, VALUE outf) {
+VALUE decode(VALUE self, VALUE infile, VALUE outf) {
OggVorbis_File vf;
ov_callbacks callbacks;
int bs = 0;
@@ -134,3 +138,11 @@ VALUE method_ogg_decode(VALUE self, VALUE infile, VALUE outf) {
return Qnil;
}
+void init_audio_ogg_decoder()
+{
+ VALUE rb_mAudio = rb_define_module("Audio");
+ VALUE rb_mOgg = rb_define_module_under(rb_mAudio, "OGG");
+ VALUE klass = rb_define_class_under(rb_mOgg, "Decoder", rb_cObject);
+
+ rb_define_method(klass, "decode", decode, 2);
+}
View
8 ext/icanhasaudio/audio_ogg_decoder.h
@@ -0,0 +1,8 @@
+#ifndef AUDIO_OGG_DECODER
+#define AUDIO_OGG_DECODER
+
+#include <native.h>
+
+void init_audio_ogg_decoder();
+
+#endif
View
2  ext/decoder.c → ext/icanhasaudio/decoder.c
@@ -1,4 +1,4 @@
-#include <icanhasaudio.h>
+#include <native.h>
int
lame_decoder(VALUE self, VALUE infile, VALUE outf, mp3data_struct * mp3data)
View
2  ext/decoder.h → ext/icanhasaudio/decoder.h
@@ -1,6 +1,8 @@
#ifndef ICANHASAUDIO_LAME_DECODER_H
#define ICANHASAUDIO_LAME_DECODER_H
+#include <native.h>
+
int
lame_decoder(VALUE self, VALUE infile, VALUE outf, mp3data_struct * mp3data);
View
4 ext/extconf.rb → ext/icanhasaudio/extconf.rb
@@ -50,5 +50,5 @@ def find_header(header, *paths)
end
end
-dir_config('icanhasaudio')
-create_makefile('icanhasaudio')
+dir_config('icanhasaudio/native')
+create_makefile('icanhasaudio/native')
View
2  ext/get_audio.c → ext/icanhasaudio/get_audio.c
@@ -1,4 +1,4 @@
-#include <icanhasaudio.h>
+#include <native.h>
#define MAX_U_32_NUM 0xFFFFFFFF
View
2  ext/get_audio.h → ext/icanhasaudio/get_audio.h
@@ -1,6 +1,8 @@
#ifndef GET_AUDIO_H
#define GET_AUDIO_H
+#include <native.h>
+
#define MAX_U_32_NUM 0xFFFFFFFF
int
get_audio16(VALUE self, VALUE musicin, short buffer[2][1152],
View
8 ext/icanhasaudio/native.c
@@ -0,0 +1,8 @@
+#include <native.h>
+
+void Init_native()
+{
+ init_audio_mpeg_decoder();
+ init_audio_mpeg_encoder();
+ init_audio_ogg_decoder();
+}
View
11 ext/icanhasaudio.h → ext/icanhasaudio/native.h
@@ -6,12 +6,17 @@
#include <lame/lame.h>
#include <dlfcn.h>
#include <assert.h>
+#include <ogg/ogg.h>
+#include <vorbis/vorbisfile.h>
+
#include <syncword.h>
#include <decoder.h>
-#include <mpeg_encoder.h>
#include <get_audio.h>
-#include <ogg/ogg.h>
-#include <vorbis/vorbisfile.h>
#include <rb_wav.h>
+#include <audio_mpeg_decoder.h>
+#include <audio_mpeg_encoder.h>
+#include <audio_ogg_decoder.h>
+
+void Init_native();
#endif
View
2  ext/rb_wav.c → ext/icanhasaudio/rb_wav.c
@@ -1,4 +1,4 @@
-#include <icanhasaudio.h>
+#include <native.h>
#define WRITE_U32(buf, x) *(buf) = (unsigned char)((x)&0xff);\
*((buf)+1) = (unsigned char)(((x)>>8)&0xff);\
View
2  ext/rb_wav.h → ext/icanhasaudio/rb_wav.h
@@ -1,4 +1,4 @@
-#include <icanhasaudio.h>
+#include <native.h>
void prelim_header( VALUE self,
char *headbuf,
View
2  ext/syncword.c → ext/icanhasaudio/syncword.c
@@ -1,4 +1,4 @@
-#include <icanhasaudio.h>
+#include <native.h>
/*
* Taken from lame, get_audio.c
View
2  ext/syncword.h → ext/icanhasaudio/syncword.h
@@ -1,6 +1,8 @@
#ifndef ICANHASAUDIO_SYNCWORD
#define ICANHASAUDIO_SYNCWORD
+#include <native.h>
+
int is_syncword_mp123(const void *const headerptr);
#endif
View
11 lib/icanhasaudio.rb
@@ -0,0 +1,11 @@
+require 'icanhasaudio/mpeg'
+require 'icanhasaudio/ogg'
+require 'icanhasaudio/native'
+
+module Audio
+ module MPEG
+ class Decoder
+ VERSION = '0.1.1'
+ end
+ end
+end
View
34 lib/icanhasaudio/ogg.rb
@@ -1,21 +1,25 @@
-class Audio::OGG::Decoder
- # Set to true for no WAV header
- attr_accessor :raw
+module Audio
+ module OGG
+ class Decoder
+ # Set to true for no WAV header
+ attr_accessor :raw
- # Number of bits, 8 or 16
- attr_accessor :bits
+ # Number of bits, 8 or 16
+ attr_accessor :bits
- # Endianness
- attr_accessor :endian
+ # Endianness
+ attr_accessor :endian
- # Signedness
- attr_accessor :sign
+ # Signedness
+ attr_accessor :sign
- def initialize
- @raw = false
- @bits = 16
- @endian = 0
- @sign = 1
- yield self if block_given?
+ def initialize
+ @raw = false
+ @bits = 16
+ @endian = 0
+ @sign = 1
+ yield self if block_given?
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.