Playing raw audio/PCM

At the moment I’m getting interested in writing programs that create sound.
On Linux I’ve been creating a FIFO and writing sample data to it, and using ‘aplay’ to play the data streaming through the FIFO as raw 16bit PCM, which works OK.

Is there any way of doing anything similar in RISC OS? Or maybe I mean to ask, how would you go about playing sound samples in RISC OS?

There’s also PlayIt which is a system resource on most distributions (and is free otherwise). It doesn’t quite do what the original poster asks, as it is more file-based, but it’s a useful way to do background sound streaming of a variety of input source formats.

Historically there was DataVox which has been updated to 32bit by Jeff D. Finally, the distribution for SharedUnixLib includes DigitalRenderer which I believe allows a more linux-y approach to audio which might be applicable in this case.

I haven’t tried RDSP (in my head, it was more of an audio fx tool), but looking at the website, it may well do what’s needed too.

Thanks for the replies.
I just realised that my post might have been unclear. By ‘sound samples’ I didn’t mean a short sound clip like ‘sample’ can often mean, but I meant samples as in the individual points of a waveform, because my program will be generating sounds of indefinite length. So I’m wanting to stream data to the sound output. I think everyone understood me correctly anyway, but I thought I’d mention this for clarity.

I didn’t think of RDSP at first, I had the impression that it was intended as more of a music synth, but it seems like it might do what I want. I’ll look into the other methods too.

RDSP does indeed provide a simple way of loading and playing a sample and/or samples. You can also loop samples if desired. Examples are included that demonstrate this including a simple drum loop example.

I’m planning an update to RDSP soon and I might be able to add a feature in for you if RDSP does not quite do what you require.

If I understand correctly – are you generating a waveform and looking for a way to play the generated sound as a continuous stream?
– If so then you can generate the waveform in parallel with RDSP playback.

I am currently implementing a queuing feature in RDSP. At present you would have to manually re-trigger the next generated sample fragment by watching a clock – which might lead to dropouts. I suspect if you implementing a stream solution, then the queuing feature that I am currently writing would make that much easier.

If I understand correctly – are you generating a waveform and looking for a way to play the generated sound as a continuous stream?
bq. – If so then you can generate the waveform in parallel with RDSP playback.

That’s correct. I’m writing a music player/tracker, and the sound output from it is a stream that could potentially be very long, or even endless if it’s playing a song that loops.
It sounds like the queuing feature you’re working on would make it easy & straightforward to do what I want. If I’m understanding things right, what I would need to do is generate a sample of about 2 seconds long or so, then put it in the queue, and then from then on whenever the length of the queue is less than 2 samples, generate a new sample and put it into the queue.

However – if this is a music tracker, then traditionally this involves samples triggered in step-time over a number of channels. Are you writing something similar?

RDSP has its own internal managed stream (based on Shared Sound) and you can play up to 16 sounds simultaneously on different musical notes (or micro-tones). The sounds played may be samples or can be generated synthesised sounds modulated to different musical notes.

I’m just wondering if you what you are writing would be partly implemented by RDSP and that you may not know that it already implements a stream that may play multiple modulated sounds at once.

I’m working on a music demo at the moment which uses RDSP internally based on a simple tracker structure.

Alternatively, if you just need the audio streaming part – regarding the queuing feature. I hope to have something available later this month or early December.

One possibility is to do like !KinoAmp when playing videos with sound in PCM format: use DiskSample to define a circular buffer in mono/stereo 8-bit/16-bit per sample and push data in it regularly while the module plays the buffer and discards the played part.

Another possibility as you mention “Tracker” could be to use TimPlayer. Assuming that your instruments are composed of samples (i.e. not synthesized sounds) you create a new “song” and define its samples by pointing to yours in memory, then play/alter notes using these samples. ExternSmp is a little example loads a wave file in memory, defines 2 samples (left and right) from it and plays them. !FxTest is another example which load an ImpulseTracker file and let you play sample/instruments and alter the paramters of the played notes (volume, panning, pitch, …).

Thanks for all the information. Sorry for my delayed reply, I’ve been away for a while and had a lot going on.

I’m just wondering if you what you are writing would be partly implemented by RDSP and that you may not know that it already implements a stream that may play multiple modulated sounds at once.

I knew RDSP has features like that – if I were starting from scratch I’d probably use those features, but my situation is that I’m looking for ways to implement specific features of a program I’ve been writing for Linux.

I’ve been writing a game for Linux in C with the Allegro library, and my plan is that once it’s finished, I’ll try to convert it to run on RISC OS. I think Allegro isn’t available for RISC OS so I’ll need to find alternatives for the various features of allegro that I’ve been using (like using OS_SpriteOp instead of the the various Allegro sprite drawing routines, etc)
Currently I have a music player/tracker type thing that uses Allegro’s audio routines for playing audio streams, which is used for the game’s background music.

RDSP’s planned queuing feature sounds like it’d allow me to bring over my music playing code with few modifications. The DiskSample method sounds like it would work well too, but I’m thinking that RDSP would probably be more user friendly overall. And I could use RDSP’s other features for playing sound effects, too.