fmod_audioplayer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/ext/fmod_audioplayer/extconf.rb +18 -0
- data/ext/fmod_audioplayer/fmod_handle.c +110 -0
- data/ext/fmod_audioplayer/fmod_handle.h +29 -0
- data/ext/fmod_audioplayer/soundplayer.c +72 -0
- data/fmod_audioplayer.gemspec +24 -0
- data/lib/fmod_audioplayer/version.rb +3 -0
- data/lib/fmod_audioplayer.rb +2 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 94691a05e1652e4d769528e981df2313618ce1f1
|
4
|
+
data.tar.gz: b025eb0aad96bc71fb5399c3c40f454eec76c9ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fab18021e9eda8a3cca97297bcc46a48f6925a6d7af224a559c688358fdc1068f0a8030b3052aacc720c3ea2ec77ff387a942a7981cbfe0e08f2ef02150f35e5
|
7
|
+
data.tar.gz: 1b634c84e2da60cae9137f17ffc749e186d694f7f43b5418de0297f8aaed68f6b87d174ab1f0732530ff06c6d0b8af545059490ce4bf72d286275ab96d51767f
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Edgar Wang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# FMODAudioPlayer
|
2
|
+
|
3
|
+
FMODAudioPlayer is a simple audio player based on FMOD.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'fmod_audioplayer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fmod_audioplayer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/fmod_audioplayer/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
unless have_header('fmodex/fmod.h')
|
4
|
+
puts 'Please install fmodex headers'
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
unless have_header('fmodex/fmod_errors.h')
|
9
|
+
puts 'Please install fmodex headers'
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
unless have_library('fmodex')
|
14
|
+
puts 'please install fmodex library'
|
15
|
+
exit
|
16
|
+
end
|
17
|
+
|
18
|
+
create_makefile('fmod_audioplayer/fmod_audioplayer')
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#include "fmod_handle.h"
|
2
|
+
|
3
|
+
void ERRCHECK(FMOD_RESULT result)
|
4
|
+
{
|
5
|
+
if (result == FMOD_OK) {
|
6
|
+
return;
|
7
|
+
}
|
8
|
+
|
9
|
+
rb_raise(rb_eStandardError,
|
10
|
+
"FMOD error: (%d) %s",
|
11
|
+
result, FMOD_ErrorString(result));
|
12
|
+
}
|
13
|
+
|
14
|
+
fmod_handle* fmod_handle_new()
|
15
|
+
{
|
16
|
+
fmod_handle* handle = (fmod_handle*)malloc(sizeof(fmod_handle));
|
17
|
+
handle->system = NULL;
|
18
|
+
handle->channel = NULL;
|
19
|
+
handle->sound = NULL;
|
20
|
+
return handle;
|
21
|
+
}
|
22
|
+
|
23
|
+
void fmod_handle_init(fmod_handle* handle)
|
24
|
+
{
|
25
|
+
unsigned version;
|
26
|
+
|
27
|
+
ERRCHECK(FMOD_System_Create(&(handle->system)));
|
28
|
+
ERRCHECK(FMOD_System_GetVersion(handle->system, &version));
|
29
|
+
if (version < FMOD_VERSION) {
|
30
|
+
rb_raise(rb_eStandardError,
|
31
|
+
"Error: You are using an old version of FMOD. Please update it");
|
32
|
+
}
|
33
|
+
|
34
|
+
ERRCHECK(FMOD_System_Init(handle->system, 32, FMOD_INIT_NORMAL, NULL));
|
35
|
+
}
|
36
|
+
|
37
|
+
void fmod_handle_cleanup(fmod_handle* handle)
|
38
|
+
{
|
39
|
+
fmod_handle_sound_release(handle);
|
40
|
+
|
41
|
+
if (handle->system != NULL) {
|
42
|
+
ERRCHECK(FMOD_System_Close(handle->system));
|
43
|
+
ERRCHECK(FMOD_System_Release(handle->system));
|
44
|
+
handle->system = NULL;
|
45
|
+
}
|
46
|
+
|
47
|
+
free(handle);
|
48
|
+
}
|
49
|
+
|
50
|
+
void fmod_handle_system_update(fmod_handle* handle)
|
51
|
+
{
|
52
|
+
ERRCHECK(FMOD_System_Update(handle->system));
|
53
|
+
}
|
54
|
+
|
55
|
+
void fmod_handle_sound_create(fmod_handle* handle, const char* name_or_data)
|
56
|
+
{
|
57
|
+
ERRCHECK(FMOD_System_CreateSound(handle->system,
|
58
|
+
name_or_data, FMOD_SOFTWARE, 0, &(handle->sound)));
|
59
|
+
ERRCHECK(FMOD_Sound_SetMode(handle->sound, FMOD_LOOP_OFF));
|
60
|
+
}
|
61
|
+
|
62
|
+
void fmod_handle_sound_release(fmod_handle* handle)
|
63
|
+
{
|
64
|
+
if (handle->sound != NULL) {
|
65
|
+
ERRCHECK(FMOD_Sound_Release(handle->sound));
|
66
|
+
handle->sound = NULL;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
FMOD_RESULT F_CALLBACK mycallback(FMOD_CHANNEL *channel,
|
71
|
+
FMOD_CHANNEL_CALLBACKTYPE type, void *commanddata1, void *commanddata2)
|
72
|
+
{
|
73
|
+
if (type == FMOD_CHANNEL_CALLBACKTYPE_END) {
|
74
|
+
printf("DONE\n");
|
75
|
+
}
|
76
|
+
return FMOD_OK;
|
77
|
+
}
|
78
|
+
|
79
|
+
void fmod_handle_sound_play(fmod_handle* handle)
|
80
|
+
{
|
81
|
+
ERRCHECK(FMOD_System_PlaySound(handle->system,
|
82
|
+
FMOD_CHANNEL_FREE, handle->sound, 0, &(handle->channel)));
|
83
|
+
FMOD_Channel_SetCallback(handle->channel, mycallback);
|
84
|
+
}
|
85
|
+
|
86
|
+
void fmod_handle_sound_stop(fmod_handle* handle)
|
87
|
+
{
|
88
|
+
fmod_handle_sound_release(handle);
|
89
|
+
}
|
90
|
+
|
91
|
+
void fmod_handle_sound_toggle(fmod_handle* handle)
|
92
|
+
{
|
93
|
+
int paused;
|
94
|
+
ERRCHECK(FMOD_Channel_GetPaused(handle->channel, &paused));
|
95
|
+
ERRCHECK(FMOD_Channel_SetPaused(handle->channel, !paused));
|
96
|
+
}
|
97
|
+
|
98
|
+
unsigned int fmod_handle_sound_length(fmod_handle* handle)
|
99
|
+
{
|
100
|
+
unsigned int lenms;
|
101
|
+
ERRCHECK(FMOD_Sound_GetLength(handle->sound, &lenms, FMOD_TIMEUNIT_MS));
|
102
|
+
return lenms;
|
103
|
+
}
|
104
|
+
|
105
|
+
unsigned int fmod_handle_sound_position(fmod_handle* handle)
|
106
|
+
{
|
107
|
+
unsigned int ms;
|
108
|
+
ERRCHECK(FMOD_Channel_GetPosition(handle->channel, &ms, FMOD_TIMEUNIT_MS));
|
109
|
+
return ms;
|
110
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#ifndef __FMOD_HANDLE_H__
|
2
|
+
#define __FMOD_HANDLE_H__
|
3
|
+
|
4
|
+
#include <ruby-2.1.0/ruby.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <fmodex/fmod.h>
|
7
|
+
#include <fmodex/fmod_errors.h>
|
8
|
+
|
9
|
+
typedef struct {
|
10
|
+
FMOD_SYSTEM* system;
|
11
|
+
FMOD_CHANNEL* channel;
|
12
|
+
FMOD_SOUND* sound;
|
13
|
+
} fmod_handle;
|
14
|
+
|
15
|
+
void ERRCHECK(FMOD_RESULT result);
|
16
|
+
|
17
|
+
fmod_handle* fmod_handle_new();
|
18
|
+
void fmod_handle_init(fmod_handle* handle);
|
19
|
+
void fmod_handle_cleanup(fmod_handle* handle);
|
20
|
+
void fmod_handle_system_update(fmod_handle* handle);
|
21
|
+
void fmod_handle_sound_create(fmod_handle* handle, const char* name_or_data);
|
22
|
+
void fmod_handle_sound_release(fmod_handle* handle);
|
23
|
+
void fmod_handle_sound_play(fmod_handle* handle);
|
24
|
+
void fmod_handle_sound_stop(fmod_handle* handle);
|
25
|
+
void fmod_handle_sound_toggle(fmod_handle* handle);
|
26
|
+
unsigned int fmod_handle_sound_length(fmod_handle* handle);
|
27
|
+
unsigned int fmod_handle_sound_position(fmod_handle* handle);
|
28
|
+
|
29
|
+
#endif // __FMOD_HANDLE_H__
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#include <ruby-2.1.0/ruby.h>
|
2
|
+
#include <ruby-2.1.0/ruby/intern.h>
|
3
|
+
#include "fmod_handle.h"
|
4
|
+
|
5
|
+
VALUE rb_mFMODAudioPlayer;
|
6
|
+
VALUE rb_cSoundPlayer;
|
7
|
+
|
8
|
+
static VALUE rb_soundplayer_new(VALUE klass)
|
9
|
+
{
|
10
|
+
fmod_handle* handle = fmod_handle_new();
|
11
|
+
fmod_handle_init(handle);
|
12
|
+
|
13
|
+
return Data_Wrap_Struct(rb_cSoundPlayer, 0,
|
14
|
+
fmod_handle_cleanup, handle);
|
15
|
+
}
|
16
|
+
|
17
|
+
static VALUE rb_soundplayer_system_update(VALUE self)
|
18
|
+
{
|
19
|
+
fmod_handle_system_update(DATA_PTR(self));
|
20
|
+
return self;
|
21
|
+
}
|
22
|
+
|
23
|
+
static VALUE rb_soundplayer_play(VALUE self, const VALUE name_or_data)
|
24
|
+
{
|
25
|
+
Check_Type(name_or_data, T_STRING);
|
26
|
+
fmod_handle_sound_create(DATA_PTR(self), RSTRING_PTR(name_or_data));
|
27
|
+
fmod_handle_sound_play(DATA_PTR(self));
|
28
|
+
return self;
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE rb_soundplayer_stop(VALUE self)
|
32
|
+
{
|
33
|
+
fmod_handle_sound_stop(DATA_PTR(self));
|
34
|
+
return self;
|
35
|
+
}
|
36
|
+
|
37
|
+
static VALUE rb_soundplayer_toggle(VALUE self)
|
38
|
+
{
|
39
|
+
fmod_handle_sound_toggle(DATA_PTR(self));
|
40
|
+
return self;
|
41
|
+
}
|
42
|
+
|
43
|
+
static VALUE rb_soundplayer_length(VALUE self)
|
44
|
+
{
|
45
|
+
return INT2FIX(fmod_handle_sound_length(DATA_PTR(self)));
|
46
|
+
}
|
47
|
+
|
48
|
+
static VALUE rb_soundplayer_position(VALUE self)
|
49
|
+
{
|
50
|
+
return INT2FIX(fmod_handle_sound_position(DATA_PTR(self)));
|
51
|
+
}
|
52
|
+
|
53
|
+
void init_soundplayer(void)
|
54
|
+
{
|
55
|
+
rb_mFMODAudioPlayer = rb_define_module("FMODAudioPlayer");
|
56
|
+
rb_cSoundPlayer = rb_define_class_under(rb_mFMODAudioPlayer, "SoundPlayer", rb_cObject);
|
57
|
+
|
58
|
+
rb_define_singleton_method(rb_cSoundPlayer, "new", rb_soundplayer_new, 0);
|
59
|
+
rb_define_method(rb_cSoundPlayer, "system_update", rb_soundplayer_system_update, 0);
|
60
|
+
rb_define_method(rb_cSoundPlayer, "play", rb_soundplayer_play, 1);
|
61
|
+
rb_define_method(rb_cSoundPlayer, "stop", rb_soundplayer_stop, 0);
|
62
|
+
rb_define_method(rb_cSoundPlayer, "toggle", rb_soundplayer_toggle, 0);
|
63
|
+
rb_define_method(rb_cSoundPlayer, "song_length", rb_soundplayer_length, 0);
|
64
|
+
rb_define_method(rb_cSoundPlayer, "position", rb_soundplayer_position, 0);
|
65
|
+
}
|
66
|
+
|
67
|
+
void Init_fmod_audioplayer(void)
|
68
|
+
{
|
69
|
+
rb_mFMODAudioPlayer = rb_define_module("FMODAudioPlayer");
|
70
|
+
|
71
|
+
init_soundplayer();
|
72
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fmod_audioplayer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fmod_audioplayer"
|
8
|
+
spec.version = FMODAudioPlayer::VERSION
|
9
|
+
spec.authors = ["Edgar Wang"]
|
10
|
+
spec.email = ["edgar.xiaoxiangyu@gmail.com"]
|
11
|
+
spec.summary = %q{Simple audion player based on FMOD.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.extensions << 'ext/fmod_audioplayer/extconf.rb'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fmod_audioplayer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edgar Wang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- edgar.xiaoxiangyu@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions:
|
46
|
+
- ext/fmod_audioplayer/extconf.rb
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- ext/fmod_audioplayer/extconf.rb
|
55
|
+
- ext/fmod_audioplayer/fmod_handle.c
|
56
|
+
- ext/fmod_audioplayer/fmod_handle.h
|
57
|
+
- ext/fmod_audioplayer/soundplayer.c
|
58
|
+
- fmod_audioplayer.gemspec
|
59
|
+
- lib/fmod_audioplayer.rb
|
60
|
+
- lib/fmod_audioplayer/version.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.2.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Simple audion player based on FMOD.
|
85
|
+
test_files: []
|