Class: Hornetseye::AlsaOutput
- Defined in:
- docs/hornetseye-alsa/lib/hornetseye-alsa/alsaoutput.rb,
 docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb
Overview
Class for playing sounds using the ALSA library
Instance Attribute Summary collapse
- 
  
    
      #channels  ⇒ Integer 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Number of audio channels. 
- 
  
    
      #rate  ⇒ Integer 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Get the sampling rate of the sound device. 
Class Method Summary collapse
- 
  
    
      .new(pcm_name = 'default', rate = 48000, channels = 2)  ⇒ AlsaOutput 
    
    
  
  
  
  
  
  
  
  
  
    Open a sound device for output. 
Instance Method Summary collapse
- 
  
    
      #avail  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    Space available for writing to the audio buffer. 
- 
  
    
      #close  ⇒ AlsaOutput 
    
    
  
  
  
  
  
  
  
  
  
    Close the audio device. 
- 
  
    
      #delay  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    Number of audio samples in the audio buffer. 
- 
  
    
      #drain  ⇒ AlsaOutput 
    
    
  
  
  
  
  
  
  
  
  
    Wait until audio buffer underflows. 
- 
  
    
      #drop  ⇒ AlsaOutput 
    
    
  
  
  
  
  
  
  
  
  
    Drop content of audio output buffer. 
- 
  
    
      #prepare  ⇒ AlsaOutput 
    
    
  
  
  
  
  
  
  
  
  
    Reset the sound device. 
- 
  
    
      #write(frame)  ⇒ Node 
    
    
  
  
  
  
  
  
  
  
  
    Write an audio frame to the sound device. 
Instance Attribute Details
#channels ⇒ Integer (readonly)
Number of audio channels
| 75 76 77 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 75 def channels @channels end | 
#rate ⇒ Integer (readonly)
Get the sampling rate of the sound device
The sampling rate may be different to the desired sampling rate specified in the constructor.
| 70 71 72 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 70 def rate @rate end | 
Class Method Details
.new(pcm_name = 'default', rate = 48000, channels = 2) ⇒ AlsaOutput
Open a sound device for output
Open the specified sound device for writing. Note that the desired sample rate may not be supported. In that case the sound library will select a sampling rate near the desired one.
| 51 52 53 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/alsaoutput.rb', line 51 def new(pcm_name = 'default', rate = 48000, channels = 2) orig_new pcm_name, rate, channels end | 
Instance Method Details
#avail ⇒ Integer
Space available for writing to the audio buffer
| 99 100 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 99 def avail end | 
#close ⇒ AlsaOutput
Close the audio device
| 80 81 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 80 def close end | 
#delay ⇒ Integer
Number of audio samples in the audio buffer
Returns the number of audio samples left in the audio buffer. This can be used to properly synchronise video display with audio output.
| 108 109 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 108 def delay end | 
#drain ⇒ AlsaOutput
Wait until audio buffer underflows
| 92 93 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 92 def drain end | 
#drop ⇒ AlsaOutput
Drop content of audio output buffer
| 86 87 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 86 def drop end | 
#prepare ⇒ AlsaOutput
Reset the sound device
One needs to call this method if one wants to resume playing audio samples after calling #drop.
| 117 118 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/docs.rb', line 117 def prepare end | 
#write(frame) ⇒ Node
Write an audio frame to the sound device
The audio data is written to the output buffer of the sound device. Playback is resumed if a buffer underflow occurred earlier. The first dimension of the array with the audio data must match the number of channels of the audio device. The second dimension is the number of audio samples.
A blocking write operation is used. I.e. the program is blocked until there is sufficient space in the audio output buffer.
| 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # File 'docs/hornetseye-alsa/lib/hornetseye-alsa/alsaoutput.rb', line 83 def write( frame ) if frame.typecode != SINT raise "Audio data must be of type SINT (but was #{frame.typecode})" end if frame.dimension != 2 raise "Audio frame must have two dimensions (but had #{frame.dimension})" end if frame.shape.first != channels raise "Audio frame must have #{channels} channel(s) but had " + "#{frame.shape.first}" end orig_write Hornetseye::Sequence(UBYTE).new 2 * frame.size, :memory => frame.memory frame end |