Class: Wiretap::Audio

Inherits:
Node
  • Object
show all
Defined in:
lib/wiretap.rb,
ext/node.cpp

Instance Attribute Summary

Attributes inherited from Node

#parent, #server

Instance Method Summary collapse

Methods inherited from Node

#[], #children, #create_library, #create_project, #create_reel, #destroy, #destroy!, #find, #find_child, #host?, #id, #id=, #import_image, #import_video, #library?, #ls, #metadata, #name, #project?, #reel?, #reload, #type, #uri, #volume?

Instance Method Details

#audio?Boolean

#clip?Boolean

#dump(file) ⇒ Object

This is called on node. Not on NodeFrames



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'ext/audio_format.cpp', line 186

static VALUE wiretap_audio_dump(VALUE self, VALUE file) {
  WireTapNodeHandle* node;
  Data_Get_Struct(self, WireTapNodeHandle, node);
  
  WireTapAudioFormat format;
  RUN(node->getClipFormat(format));

  int num;
  NODERUN_E(node, node->getNumFrames(num));
  if(num <= 0) {
    rb_warn("No frames in the audio stream");
    return Qnil;
  }

  std::auto_ptr<unsigned char> frame(new unsigned char[format.frameBufferSize() * num]);
  for(int i = 0; i < num; i++) {
    if(!node->readFrame(i, frame.get() + i*format.frameBufferSize(), format.frameBufferSize())) {
      frame.release();
      NODERUN_E(node, false);
    }
  }

  wiretap_write_audio_frame(format.numSamples(), int(format.sampleRate()), 
    format.bitsPerSample(), rb_intern(format.formatTag()), frame.get(), CSTR(file));
  return self;
}

#formatObject



312
313
314
315
316
317
318
319
320
321
322
# File 'ext/node.cpp', line 312

static VALUE wiretap_audio_format(VALUE self) {
  Check_Node_Alive(self);
  
  WireTapNodeHandle* node;
  Data_Get_Struct(self, WireTapNodeHandle, node);
  WireTapAudioFormat audio_format;
  NODERUN_E(node, node->getClipFormat(audio_format));
  VALUE audioformat = Data_Wrap_Struct(cAudioFormat, 0, wiretap_format_free, new WireTapAudioFormat(audio_format));
  rb_iv_set(audioformat, "@node", self);
  return audioformat;
}

#framesObject



336
337
338
339
340
341
342
343
344
# File 'ext/node.cpp', line 336

static VALUE wiretap_audio_frames(VALUE self) {
  Check_Node_Alive(self);
  
  WireTapNodeHandle* node;
  Data_Get_Struct(self, WireTapNodeHandle, node);
  VALUE audioframes = Data_Wrap_Struct(cAudioFrames, 0, node_leave, node);
  rb_iv_set(audioframes, "@node", self);
  return audioframes;
}

#import_music(filename) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'ext/audio_format.cpp', line 161

static VALUE wiretap_audio_import_music(VALUE self, VALUE filename) {
  Check_Type(filename, T_STRING);
  
  SF_INFO sfinfo;
  SNDFILE* snd = sf_open(CSTR(filename), SFM_READ, &sfinfo);


  std::auto_ptr<short> frame(new short[sfinfo.frames]);
  sf_count_t read_frames = sf_read_short(snd, frame.get(), sfinfo.frames);
  if(read_frames != sfinfo.frames) {
    rb_warn("Waited to read %lld audio frames, got only %lld", sfinfo.frames, read_frames);
    sf_close(snd);
    return Qnil;
  }
  sf_close(snd);
  
  WireTapNodeHandle* node;
  Data_Get_Struct(self, WireTapNodeHandle, node);
  NODERUN_E(node, node->setNumFrames(1));
  NODERUN_E(node, node->writeFrame(0, frame.get(), sfinfo.frames*2));
  return self;
}

#to_sObject



208
209
210
# File 'lib/wiretap.rb', line 208

def to_s
  "#<#{self.class.to_s} '#{self.name}'>"
end