--- a/SoundStream.st Sun Jan 05 21:30:40 2020 +0100
+++ b/SoundStream.st Mon Jan 06 14:29:53 2020 +0100
@@ -620,10 +620,10 @@
"
Preliminary (unfinished) interface to an audio device.
Currently works with
- LINUXs
- SUNs (and other) /dev/audio driver
- IRIX (indy).
- PORTAUDIO (osx).
+ LINUXs
+ SUNs (and other) /dev/audio driver
+ IRIX (indy).
+ PORTAUDIO (osx).
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.
@@ -631,7 +631,7 @@
This is an experimental class - its interface & implementation may change in the future.
[author:]
- Claus Gittinger
+ Claus Gittinger
"
! !
@@ -655,11 +655,11 @@
determineConcreteClass
self allSubclassesDo:[:each |
- each isAbstract ifFalse:[
- each isSupported ifTrue:[
- ^ each
- ]
- ]
+ each isAbstract ifFalse:[
+ each isSupported ifTrue:[
+ ^ each
+ ]
+ ]
].
^ nil
@@ -670,13 +670,13 @@
new
self == SoundStream ifTrue:[
- ConcreteClass isNil ifTrue:[
- ConcreteClass := self determineConcreteClass.
- ConcreteClass isNil ifTrue:[
- OpenError raiseErrorString:'missing sound support'.
- ].
- ].
- ^ ConcreteClass new.
+ ConcreteClass isNil ifTrue:[
+ ConcreteClass := self determineConcreteClass.
+ ConcreteClass isNil ifTrue:[
+ OpenError raiseErrorString:'missing sound support'.
+ ].
+ ].
+ ^ ConcreteClass new.
].
^ self basicNew initialize
@@ -736,7 +736,7 @@
newStream := self new.
(newStream supportedAudioFormats includesAny:#(S16 U16)) ifFalse:[
- OpenError raiseRequestErrorString:'sound system does not support 16bit audio'
+ OpenError raiseRequestErrorString:'sound system does not support 16bit audio'
].
newStream bitsPerSample:16.
newStream openForWriting isNil ifTrue:[^nil].
@@ -756,7 +756,7 @@
newStream := self new.
(newStream supportedAudioFormats includesAny:#(S16 U16)) ifFalse:[
- OpenError raiseRequestErrorString:'sound system does not support 16bit audio'
+ OpenError raiseRequestErrorString:'sound system does not support 16bit audio'
].
newStream bitsPerSample:16.
newStream numberOfChannels:2.
@@ -773,7 +773,7 @@
newStream := self new.
(newStream supportedAudioFormats includes:#F32) ifFalse:[
- OpenError raiseRequestErrorString:'sound system does not support float audio'
+ OpenError raiseRequestErrorString:'sound system does not support float audio'
].
newStream setAudioFormat:#F32.
newStream numberOfChannels:1.
@@ -788,7 +788,7 @@
newStream := self new.
(newStream supportedAudioFormats includes:#F32) ifFalse:[
- OpenError raiseRequestErrorString:'sound system does not support float audio'
+ OpenError raiseRequestErrorString:'sound system does not support float audio'
].
newStream setAudioFormat:#F32.
newStream numberOfChannels:2.
@@ -3488,6 +3488,7 @@
#ifdef SUPPORT_JACKAUDIO
jack_options_t options = JackNullOption;
jack_client_t *client;
+ jack_port_t *output_port;
struct jackStreamData* streamData;
int nChannels, sampleRate, bytesPerSample;
# define FRAMES_PER_BUFFER 128
@@ -3495,42 +3496,46 @@
ok = false;
if (__isSmallInteger(__INST(numberOfChannels))) {
- nChannels = __intVal(__INST(numberOfChannels));
+ nChannels = __intVal(__INST(numberOfChannels));
} else {
- nChannels = 1;
+ nChannels = 1;
}
if (__INST(audioFormat) == @symbol(F32)) {
- bytesPerSample = 4;
+ bytesPerSample = 4;
} else {
- fprintf(stderr, "SoundStream [warning]: only f32 supported with jack\n");
- errorStringOrNil = __MKSTRING("audioFormat must be f32 with jack");
- goto out;
- }
-
- if (__isSmallInteger(__INST(sampleRate))) {
- sampleRate = __intVal(__INST(sampleRate));
- } else {
- fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n");
- sampleRate = 8000;
+ fprintf(stderr, "SoundStream [warning]: only f32 supported with jack\n");
+ errorStringOrNil = __MKSTRING("audioFormat must be f32 with jack");
+ goto out;
}
streamData = (struct jackStreamData*)malloc(sizeof(struct jackStreamData));
if (streamData == NULL) {
- fprintf(stderr, "SoundStream [warning]: failed to allocate jackStream\n");
- errorStringOrNil = __MKSTRING("failed to allocate jackStream");
- goto out;
+ fprintf(stderr, "SoundStream [warning]: failed to allocate jackStream\n");
+ errorStringOrNil = __MKSTRING("failed to allocate jackStream");
+ goto out;
}
if ((client = jack_client_open ("stx", JackNullOption, NULL)) == 0) {
- fprintf(stderr, "SoundStream [warning]: client_open\n");
- free(streamData);
- errorStringOrNil = __MKSTRING("client_open");
- goto out;
+ fprintf(stderr, "SoundStream [warning]: JACK server not running?\n");
+ free(streamData);
+ errorStringOrNil = __MKSTRING("JACK server not running");
+ goto out;
}
jack_set_process_callback (client, jack_callback, 0);
+ output_port = jack_port_register (client, "stx_out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
+ sampleRate = jack_get_sample_rate (client);
+ __INST(sampleRate) = __MKSMALLINT(sampleRate);
+ // if (__isSmallInteger(__INST(sampleRate))) {
+ // sampleRate = __intVal(__INST(sampleRate));
+ // } else {
+ // fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n");
+ // sampleRate = 8000;
+ // }
+
streamData->jack_client = client;
+ streamData->jack_output_port = output_port;
INITLOCK(streamData->lock);
streamData->readOffset = 0;
streamData->bytesPerSample = bytesPerSample;
@@ -3542,8 +3547,8 @@
streamData->hasFinished = 0;
{
- OBJ t;
- t = __MKEXTERNALADDRESS(streamData); __INST(handle1) = t; __STORE(self, t);
+ OBJ t;
+ t = __MKEXTERNALADDRESS(streamData); __INST(handle1) = t; __STORE(self, t);
}
__INST(binary) = true;
@@ -3561,11 +3566,11 @@
%}.
ok == false ifTrue:[
- lastErrorString := errorStringOrNil.
- lastErrorNumber := error ? -1.
- self openError:error.
- "normally not reached"
- ^ nil.
+ lastErrorString := errorStringOrNil.
+ lastErrorNumber := error ? -1.
+ self openError:error.
+ "normally not reached"
+ ^ nil.
].
self registerForFinalization.
!
@@ -3581,25 +3586,25 @@
supportedAudioFormats
"return a collection of supported audio formats.
possibly returned symbols are:
- U8 unsigned 8bit samples
- S8 signed 8bit samples
- U16 unsigned 16bit samples in native format
- U16_LE unsigned 16bit big endian samples
- U16_BE unsigned 16bit big endian samples
- S16 signed 16bit little endian samples in native format
- S16_LE signed 16bit little endian samples
- S16_BE signed 16bit big endian samples
- S24 signed 24bit little endian samples in native format
- S24_LE signed 24bit little endian samples
- S24_BE signed 24bit big endian samples
- S32 signed 32bit little endian samples in native format
- S32_LE signed 32bit little endian samples
- S32_BE signed 32bit big endian samples
- F32 float samples
- MPEG audio mpeg encoded
- MU_LAW u-law encoded 8bit samples
- A_LAW a-law encoded 8bit samples
- IMA_ADPCM adpcm encoded
+ U8 unsigned 8bit samples
+ S8 signed 8bit samples
+ U16 unsigned 16bit samples in native format
+ U16_LE unsigned 16bit big endian samples
+ U16_BE unsigned 16bit big endian samples
+ S16 signed 16bit little endian samples in native format
+ S16_LE signed 16bit little endian samples
+ S16_BE signed 16bit big endian samples
+ S24 signed 24bit little endian samples in native format
+ S24_LE signed 24bit little endian samples
+ S24_BE signed 24bit big endian samples
+ S32 signed 32bit little endian samples in native format
+ S32_LE signed 32bit little endian samples
+ S32_BE signed 32bit big endian samples
+ F32 float samples
+ MPEG audio mpeg encoded
+ MU_LAW u-law encoded 8bit samples
+ A_LAW a-law encoded 8bit samples
+ IMA_ADPCM adpcm encoded
the set of returned symbols depends on the underlying sound hardware.
"