eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SoundStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: SoundStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--PositionableStream
            |
            +--WriteStream
               |
               +--ReadWriteStream
                  |
                  +--ExternalStream
                     |
                     +--FileStream
                        |
                        +--SoundStream

Package:
stx:libbasic2
Category:
Streams-External
Version:
rev: 1.88 date: 2019/03/17 14:09:14
user: cg
file: SoundStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


Preliminary (unfinished) interface to audio device.
Currently works with LINUXs or SUNs /dev/audio driver and
IRIX (indy).
On iris, the default setup is for 8 bit mono
so I can play the standard sound files I have here.
It needs much more work, for stereo, different sampling rates etc.

This is an experimental class - its interface & implementation
may change in the future.


Class protocol:

Signal constants
o  unsupportedOperationSignal

conversion helpers
o  linear16ToUlaw: a16bitSignedValue
given a 16it signed value, encode into uLaw byte

usage example(s):

     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:0)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32256)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32256)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32767)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32767)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:100)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-100)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:104)
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-104)

o  uLawToLinear16: uLawValue
given a uLaw byte, return the decoded signed 16bit value.
Currently unused - but will be

default values
o  defaultAudioFormat

o  defaultBitsPerSample
minimum, supported by all audio systems

o  defaultNumberOfChannels
minimum, supported by all audio systems

o  defaultSampleRate
minimum, supported by all audio systems

initialization
o  initialize

instance creation
o  readWrite
create and return a new soundStream for readWrite (i.e. filtering)

usage example(s):

SoundStream readWrite

o  reading
create and return a new soundStream for reading (i.e. recording)

usage example(s):

SoundStream reading

o  writing
create and return a new soundStream for writing (i.e. playback)

usage example(s):

     SoundStream writing

o  writing16Bit
just an example, has never been tried (I also
have no samples for this ... leave it as an exercise)

usage example(s):

SoundStream writing16Bit

o  writing16BitStereo
just an example, has never been tried (I also
have no samples for this ... leave it as an exercise)

usage example(s):

SoundStream writing16BitStereo

playing
o  playSoundFile: aFilename
play a soundFile

usage example(s):

     SoundStream playSoundFile:'/usr/local/lib/sounds/laugh.snd'
     SoundStream playSoundFile:'/usr/local/lib/sounds/spacemusic.snd'


Instance protocol:

catching invalid methods
o  pathName: filename
catch pathname access - its fixed here

o  pathName: filename in: aDirectory
catch pathname access - its fixed here

mode setting
o  bitsPerSample
return the number of bits per sample - usually 8

o  bitsPerSample: aNumber
set the number of bits per sample

o  numberOfChannels
return the number of channels (1 or 2; usually 1)

o  numberOfChannels: aNumber
set the number of channels

o  sampleRate
return the sample rate

o  sampleRate: aNumber
set the sample rate in hertz - on some
devices, this is a nop

private
o  dumpSettings
debugging interface - dump the current settings

usage example(s):

     self writing dumpSettings; close

o  initialize
initialize for least common mode

o  resetSoundCard
debugging interface - reset the soundCard

usage example(s):

     self writing resetSoundCard; dumpSettings; close

o  setAudioFormat: aSymbol
set the format of the audio data as specified by aSymbol.
Returns true if sucessful - may fail with some formats on many sound devices.

usage example(s):

     self writing dumpSettings; close
     self writing setAudioFormat:#'MU_LAW'; close
     self writing setAudioFormat:#'U8'; dumpSettings; close
     self writing setAudioFormat:#'MPEG'; dumpSettings; close

o  setChannels: nChannels
set the number of channels (1 -> mono; 2 -> stereo).
Returns true if sucessful - may fail with many sound devices.

usage example(s):

     self writing setChannels:2; dumpSettings; close
     self writing setChannels:2; setSampleRate:10000; dumpSettings; close
     self writing setChannels:2; setSampleRate:40000; dumpSettings; close

o  setFragmentSize: blockSize
set the soundDrivers fragmentSize.
Returns true if sucessful - may fail with many sound devices.

o  setSampleRate: hz
set the sample rate.
Returns true if sucessful - may fail with many sound devices.

usage example(s):

     self writing setSampleRate:10000; dumpSettings; close
     self writing setSampleRate:1000; dumpSettings; close
     self writing setSampleRate:8000; dumpSettings; close

o  supportedAudioFormats
return a collection of supported audio formats.
returned symbols are:
U8 unsigned 8bit samples
S8 signed 8bit samples
MU_LAW u-law encoded 8bit samples
A_LAW a-law encoded 8bit samples
IMA_ADPCM adpcm encoded
U16 unsigned 16bit samples
U16_LE unsigned 16bit big endian samples
U16_BE unsigned 16bit big endian samples
S16 signed 16bit little endian samples
S16_LE signed 16bit little endian samples
S16_BE signed 16bit big endian samples
MPEG audio mpeg encoded

redefined
o  protected closeFile
a stream has been collected - close the file

o  flush
wait until all sound has been played

o  isOpen
(comment from inherited method)
return true, if this stream is open

o  nextBytes: count into: anObject startingAt: start
read the next count bytes into an object and return the number of
bytes read or nil on error.
Use with ByteArrays only.

o  nextPutBytes: count from: anObject startingAt: start
write count bytes from an object starting at index start.
return the number of bytes written or nil on error.
Redefined, since IRIS audio library cannot be used with stdio.
(at least I don't know). Use with ByteArrays only.

o  openWithMode: aMode attributes: attributeSpec
normally not reached

sine wave generation
o  playSine16: freq forSeconds: seconds
output some tone for some time
in S16 audioFormat - a test method

o  testMelody
self writing testMelody; close

o  tuneTone
SoundStream writing tuneTone; close
SoundStream writing setSampleRate:4000; tuneTone; close
SoundStream writing setSampleRate:8000; tuneTone; close
SoundStream writing setSampleRate:10000; tuneTone; close
SoundStream writing setSampleRate:20000; tuneTone; close
SoundStream writing setSampleRate:40000; tuneTone; close

SoundStream writing setSampleRate:40000; dumpSettings; close
SoundStream writing setSampleRate:20000; dumpSettings; close

o  tuneTone16: freq
output some tone for 3 seconds in S16 audioFormat - a test method

usage example(s):

of course, the frequency should be below half the
     sampleRate - hear below ...

     SoundStream writing setSampleRate:4000; tuneTone16:440; close
     SoundStream writing setSampleRate:8000; tuneTone16:440; close
     SoundStream writing setSampleRate:10000; tuneTone16:440; close
     SoundStream writing setSampleRate:20000; tuneTone16:440; close
     SoundStream writing setSampleRate:40000; tuneTone16:440; close

o  tuneTone8: freq
output some tone for 3 seconds in U8 audioFormat - a test method

o  tuneTone: freq
SoundStream writing tuneTone:880; close
SoundStream writing setSampleRate:4000; tuneTone:440; close
SoundStream writing setSampleRate:4000; tuneTone:880; close
SoundStream writing setSampleRate:8000; tuneTone:440; close
SoundStream writing setSampleRate:8000; tuneTone:880; close
SoundStream writing setSampleRate:10000; tuneTone:440; close
SoundStream writing setSampleRate:10000; tuneTone:880; close

SoundStream writing setSampleRate:20000; tuneTone:440; close
SoundStream writing setSampleRate:20000; tuneTone:880; close

SoundStream writing setSampleRate:40000; tuneTone:440; close
SoundStream writing setSampleRate:40000; tuneTone:880; close
SoundStream writing setSampleRate:40000; tuneTone:1760; close
SoundStream writing setSampleRate:40000; tuneTone:3520; close
SoundStream writing setSampleRate:40000; tuneTone:7020; close
SoundStream writing setSampleRate:40000; tuneTone:14040; close

SoundStream writing setSampleRate:44100; tuneTone:440; close
SoundStream writing setSampleRate:44100; tuneTone:880; close
SoundStream writing setSampleRate:44100; tuneTone:1760; close
SoundStream writing setSampleRate:44100; tuneTone:3520; close
SoundStream writing setSampleRate:44100; tuneTone:7020; close
SoundStream writing setSampleRate:44100; tuneTone:14040; close

SoundStream writing setSampleRate:20000; dumpSettings; close

o  tuneToneMU: freq
output some tone for 3 seconds in MU_LAW audioFormat - a test method

usage example(s):

of course, the frequency should be below half the
     sampleRate - hear below ...

     SoundStream writing setSampleRate:8000; tuneToneMU:440; close
     SoundStream writing setSampleRate:10000; tuneToneMU:440; close
     SoundStream writing setSampleRate:20000; tuneToneMU:440; close
     SoundStream writing setSampleRate:40000; tuneToneMU:440; close



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Sun, 04 Jun 2023 18:23:29 GMT