# Playing raw PCM files in ruby

**URL:** <https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071>\
**Category:** Ruby\
**Created:** [August 29, 2010, 8:45pm UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071 "2010-08-29T20:45:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![boothy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@boothy](https://www.ruby-forum.com/u/boothy)\
**Post date:** [August 29, 2010, 8:45pm UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071/1 "2010-08-29T20:45:24Z")

</div>

Hello everyone,

I am trying to play the music from the old game “Ascendancy” using  
Ruby, the files are 8-bit unsigned raw PCM files at 22 khz. I thought  
about using SDL for playing them, but I can’t seem to find any way to  
load these files with the ruby bindings. Has anyone done this before  
or has any other idea how to play the sound?

---

<div class="post-metadata">

**Author:** ![boothy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@boothy](https://www.ruby-forum.com/u/boothy)\
**Post date:** [August 29, 2010, 9:02pm UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071/2 "2010-08-29T21:02:23Z")

</div>

On 8/29/2010 2:45 PM, Roger B. wrote:

> Hello everyone,
> 
> I am trying to play the music from the old game “Ascendancy” using  
> Ruby, the files are 8-bit unsigned raw PCM files at 22 khz. I thought  
> about using SDL for playing them, but I can’t seem to find any way to  
> load these files with the ruby bindings. Has anyone done this before  
> or has any other idea how to play the sound?

You might be better off converting these sounds to something that can be  
handled more easily. You could use a command-line tool like Sox to do  
the job, just iterate over the files (in Ruby, perhaps) and convert them  
to wav files. This has the added benefit of possibly encoding them in  
MP3 or Ogg Vorbis for smaller file sizes.

Raw PCM should be able to be handled though. The problem is, raw PCM  
has no header information. If you know the exact format, you could  
theoretically load it into memory and have it played, but it’ll be a  
pain. If you get any of the settings wrong, you might as well be  
pumping random noise through your speakers.

---

<div class="post-metadata">

**Author:** ![boothy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@boothy](https://www.ruby-forum.com/u/boothy)\
**Post date:** [August 29, 2010, 9:18pm UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071/3 "2010-08-29T21:18:47Z")

</div>

On Sun, Aug 29, 2010 at 8:58 PM, Michael M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You might be better off converting these sounds to something that can be  
> handled more easily. You could use a command-line tool like Sox to do the  
> job, just iterate over the files (in Ruby, perhaps) and convert them to wav  
> files. This has the added benefit of possibly encoding them in MP3 or Ogg  
> Vorbis for smaller file sizes.

Thanks for the suggestion, but I would really like to play the files  
directly from the games archive format.

> Raw PCM should be able to be handled though. The problem is, raw PCM has no  
> header information. If you know the exact format, you could theoretically  
> load it into memory and have it played, but it’ll be a pain. If you get any  
> of the settings wrong, you might as well be pumping random noise through  
> your speakers.

That’s exactly what I want to do, but I found no way to actually do  
this. Wrong settings are no problem here, because all the music files  
in the game use the same format and the program is just supposed to  
play these songs.

---

<div class="post-metadata">

**Author:** ![boothy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@boothy](https://www.ruby-forum.com/u/boothy)\
**Post date:** [August 30, 2010, 7:37pm UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071/4 "2010-08-30T19:37:09Z")

</div>

Roger B. wrote:

> Hello everyone,
> 
> I am trying to play the music from the old game “Ascendancy” using  
> Ruby, the files are 8-bit unsigned raw PCM files at 22 khz. I thought  
> about using SDL for playing them, but I can’t seem to find any way to  
> load these files with the ruby bindings. Has anyone done this before  
> or has any other idea how to play the sound?

Linux or windows?  
-r

---

<div class="post-metadata">

**Author:** ![boothy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@boothy](https://www.ruby-forum.com/u/boothy)\
**Post date:** [August 30, 2010, 9:59pm UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071/5 "2010-08-30T21:59:18Z")

</div>

On Mon, Aug 30, 2010 at 7:37 PM, Roger P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Linux or windows?

Possibly both. But mainly Linux.

---

<div class="post-metadata">

**Author:** ![boothy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@boothy](https://www.ruby-forum.com/u/boothy)\
**Post date:** [August 31, 2010, 5:30am UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071/6 "2010-08-31T05:30:43Z")

</div>

On Aug 29, 1:45 pm, Roger B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hello everyone,
> 
> I am trying to play the music from the old game “Ascendancy” using  
> Ruby, the files are 8-bit unsigned raw PCM files at 22 khz. I thought  
> about using SDL for playing them, but I can’t seem to find any way to  
> load these files with the ruby bindings. Has anyone done this before  
> or has any other idea how to play the sound?

Are you unable to load them because of the lack of headers or is there  
another reason?

If it’s the lack of headers, would it be too difficult to create them  
on the fly and then use SDL?

---

<div class="post-metadata">

**Author:** ![boothy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@boothy](https://www.ruby-forum.com/u/boothy)\
**Post date:** [August 31, 2010, 12:56am UTC](https://www.ruby-forum.com/t/playing-raw-pcm-files-in-ruby/194071/7 "2010-08-31T00:56:09Z")

</div>

> I am trying to play the music from the old game “Ascendancy” using  
> Ruby, the files are 8-bit unsigned raw PCM files at 22 khz. I thought  
> about using SDL for playing them, but I can’t seem to find any way to  
> load these files with the ruby bindings. Has anyone done this before  
> or has any other idea how to play the sound?

call out to VLC?
