audite 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "audite"
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
  s.author = "Matthias Georgi"
7
7
  s.email = "matti.georgi@gmail.com"
8
8
  s.homepage = "http://georgi.github.com/audite"
@@ -46,8 +46,8 @@ static int paCallback(const void *inputBuffer,
46
46
  *out++ = portaudio->buffer[i];
47
47
  }
48
48
 
49
+ pthread_cond_broadcast(&portaudio->cond);
49
50
  pthread_mutex_unlock(&portaudio->mutex);
50
- pthread_cond_signal(&portaudio->cond);
51
51
 
52
52
  return 0;
53
53
  }
@@ -115,6 +115,8 @@ VALUE rb_portaudio_start(VALUE self)
115
115
  Data_Get_Struct(self, Portaudio, portaudio);
116
116
  int err = Pa_StartStream(portaudio->stream);
117
117
 
118
+ pthread_cond_broadcast(&portaudio->cond);
119
+
118
120
  if (err != paNoError) {
119
121
  rb_raise(rb_eStandardError, "%s", Pa_GetErrorText(err));
120
122
  }
@@ -128,6 +130,8 @@ VALUE rb_portaudio_stop(VALUE self)
128
130
  Data_Get_Struct(self, Portaudio, portaudio);
129
131
  int err = Pa_StopStream(portaudio->stream);
130
132
 
133
+ pthread_cond_broadcast(&portaudio->cond);
134
+
131
135
  if (err != paNoError) {
132
136
  rb_raise(rb_eStandardError, "%s", Pa_GetErrorText(err));
133
137
  }
@@ -29,19 +29,18 @@ class Audite
29
29
  def start_thread
30
30
  Thread.start do
31
31
  loop do
32
- @stream.write(process(4096))
32
+ @stream.write(process(4096 * 2))
33
33
  end
34
34
  end
35
35
  end
36
36
 
37
37
  def process(samples)
38
38
  if tell >= length
39
- @thread.kill
40
- events.trigger(:complete)
41
39
  stop_stream
40
+ events.trigger(:complete)
42
41
  (0..samples).map { 0 }
43
42
 
44
- elsif slice = read(samples * 2)
43
+ elsif slice = read(samples)
45
44
  events.trigger(:level, level(slice))
46
45
  events.trigger(:position_change, position)
47
46
 
@@ -51,8 +50,8 @@ class Audite
51
50
  end
52
51
 
53
52
  rescue => e
54
- puts e.message
55
- puts e.backtrace
53
+ $stderr.puts e.message
54
+ $stderr.puts e.backtrace
56
55
  end
57
56
 
58
57
  def start_stream
@@ -78,6 +77,7 @@ class Audite
78
77
  end
79
78
 
80
79
  def load(file)
80
+ @file = file
81
81
  @mp3 = Mpg123.new(file)
82
82
  end
83
83
 
@@ -118,11 +118,13 @@ class Audite
118
118
  end
119
119
 
120
120
  def seek(seconds)
121
- samples = seconds_to_samples(seconds)
121
+ if @mp3
122
+ samples = seconds_to_samples(seconds)
122
123
 
123
- if (0..length).include?(samples)
124
- @mp3.seek(samples)
125
- events.trigger(:position_change, position)
124
+ if (0..length).include?(samples)
125
+ @mp3.seek(samples)
126
+ events.trigger(:position_change, position)
127
+ end
126
128
  end
127
129
  end
128
130
 
@@ -138,17 +140,11 @@ class Audite
138
140
  slice.inject(0) {|s, i| s + i.abs } / slice.size
139
141
  end
140
142
 
141
- def rewind(seconds = 1)
142
- if @mp3
143
- start_stream
144
- seek(position - seconds)
145
- end
143
+ def rewind(seconds = 2)
144
+ seek(position - seconds)
146
145
  end
147
146
 
148
- def forward(seconds = 1)
149
- if @mp3
150
- start_stream
151
- seek(position + seconds)
152
- end
147
+ def forward(seconds = 2)
148
+ seek(position + seconds)
153
149
  end
154
150
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-26 00:00:00.000000000 Z
12
+ date: 2013-01-27 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Portable mp3 player built on mpg123 and portaudio
15
15
  email: matti.georgi@gmail.com