|
Class: SoundStream
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
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.
Signal constants
-
unsupportedOperationSignal
-
conversion helpers
-
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)
|
-
uLawToLinear16: uLawValue
-
given a uLaw byte, return the decoded signed 16bit value.
Currently unused - but will be
default values
-
defaultAudioFormat
-
-
defaultBitsPerSample
-
minimum, supported by all audio systems
-
defaultNumberOfChannels
-
minimum, supported by all audio systems
-
defaultSampleRate
-
minimum, supported by all audio systems
initialization
-
initialize
-
instance creation
-
readWrite
-
create and return a new soundStream for readWrite (i.e. filtering)
usage example(s):
-
reading
-
create and return a new soundStream for reading (i.e. recording)
usage example(s):
-
writing
-
create and return a new soundStream for writing (i.e. playback)
usage example(s):
-
writing16Bit
-
just an example, has never been tried (I also
have no samples for this ... leave it as an exercise)
usage example(s):
-
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
-
playSoundFile: aFilename
-
play a soundFile
usage example(s):
SoundStream playSoundFile:'/usr/local/lib/sounds/laugh.snd'
SoundStream playSoundFile:'/usr/local/lib/sounds/spacemusic.snd'
|
catching invalid methods
-
pathName: filename
-
catch pathname access - its fixed here
-
pathName: filename in: aDirectory
-
catch pathname access - its fixed here
mode setting
-
bitsPerSample
-
return the number of bits per sample - usually 8
-
bitsPerSample: aNumber
-
set the number of bits per sample
-
numberOfChannels
-
return the number of channels (1 or 2; usually 1)
-
numberOfChannels: aNumber
-
set the number of channels
-
sampleRate
-
return the sample rate
-
sampleRate: aNumber
-
set the sample rate in hertz - on some
devices, this is a nop
private
-
dumpSettings
-
debugging interface - dump the current settings
usage example(s):
self writing dumpSettings; close
|
-
initialize
-
initialize for least common mode
-
resetSoundCard
-
debugging interface - reset the soundCard
usage example(s):
self writing resetSoundCard; dumpSettings; close
|
-
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
|
-
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
|
-
setFragmentSize: blockSize
-
set the soundDrivers fragmentSize.
Returns true if sucessful - may fail with many sound devices.
-
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
|
-
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
-
protected closeFile
-
a stream has been collected - close the file
-
flush
-
wait until all sound has been played
-
isOpen
-
(comment from inherited method)
return true, if this stream is open
-
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.
-
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.
-
openWithMode: aMode attributes: attributeSpec
-
normally not reached
sine wave generation
-
playSine16: freq forSeconds: seconds
-
output some tone for some time
in S16 audioFormat - a test method
-
testMelody
-
self writing testMelody; close
-
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
-
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
|
-
tuneTone8: freq
-
output some tone for 3 seconds in U8 audioFormat - a test method
-
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
-
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
|
|