[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] How to play a sound from a "file" of infinite size?
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] How to play a sound from a "file" of infinite size?
- From: Rene Dudfield <renesd@xxxxxxxxx>
- Date: Tue, 7 Feb 2006 16:06:59 +1100
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Tue, 07 Feb 2006 00:07:04 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=I0PoKmBMgKznYLa36TrXdtwJrX3S59sBQaItc+yn8EfQQgL3aBg75Gm4cPihRLP42fKegK+5ABVG2UQ0G++QGrO35MjjlSm0EsXtSxx4gU7F85VmukRlATuTw3Ylrp4HffsvzCFQgoI+++tPO9HnC2iuO6o1pjfqOl/7Ao/CPCY=
- In-reply-to: <200602070609.16094.tprimke@interia.pl>
- References: <200602070609.16094.tprimke@interia.pl>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Check out the StringIO and cStringIO modules. They can make a file
like object from a string.
On 2/7/06, Tomasz Primke <tprimke@xxxxxxxxxx> wrote:
> I'd like to write a player, that would be able to play files in some rare
> format. I have a library (written in C), that can be used to play such a
> files, but I'm not sure about the way that I should use PyGame to code my
> player.
>
> On a GNU/Linux system, soundcard (a device) is a file /dev/dsp. When someone
> wants to play a wav file, all that must be done is write this wav file to
> this device:
>
> $ dd if=file.wav of=/dev/dsp
>
> when "if" means the input file, and "of" means the output file (the dd
> command reads the input file and write its content to the output file).
>
> In the program written in C all the playing is done as follows:
>
> char buffer[size]; // size = 20-40 kB
> while (1)
> {
> render_buffer( buffer, size );
> play_buffer( buffer );
> }
>
> On GNU/Linux all the play_buffer function does is write the buffer to the
> /dev/dsp file (so the result is the same as with the dd command shown
> before).
>
>
> I could implement playing by wrapping all the code (written in C) in Python,
> but I'm afraid, that it would work on GNU/Linux only (because of this
> writting to the /dev/dsp file). Although I want to write a player for that
> system, I don't like the idea of giving up the portability of this
> application so easily.
>
> In PyGame documentation I have found the function pygame.mixer.Sound, that
> "loads a new sound object from a WAV file. File can be a filename or a
> file-like object. (...)". So I thought, that this file-like object idea
> sounds interesting. The problem is that I have never implemented such an
> object yet and I'm not sure how to do it.
>
> As I suppose, a file-like object is an object, that implements all the
> methods described in Python's documentation (point 2.3.9, "File Objects").
> I think I could implement such a class, but the problem is that the buffer
> from the example shown above can be "rendered" forever - so this
> file-object would be of infinite size. The question is: would the
> pygame.mixer.Sound function load such a file-like object?
>