InDashPC.org Forum Index InDashPC.org
In Dash Car PC forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PyMedia - multiple sounds simultaneously?

 
Post new topic   Reply to topic    InDashPC.org Forum Index -> Software
View previous topic :: View next topic  
Author Message
krank



Joined: 04 Aug 2007
Posts: 2

PostPosted: Fri Sep 14, 2007 5:24 am    Post subject: PyMedia - multiple sounds simultaneously? Reply with quote

Hm, yes... I'm writing an application which, amonst other things, needs to be able to play several audio streams at the same time - and at different volumes. Also, the volume of each stream needs to be modifiable in real-time.

The only volume related thing I've found is the getVolume/ setVolume of the "sound" object, which clearly sets the system volume rather than some "internal" volume, which renders it unusable for my purposes.

Is there any way to do what I want PyMedia to do? Please help...

(For clarification: Mostly, I want this because I want a "crossfading" function)
Back to top
View user's profile Send private message
jbors
Site Admin


Joined: 12 Nov 2004
Posts: 1675

PostPosted: Fri Sep 14, 2007 1:12 pm    Post subject: Reply with quote

On most systems you can run parallel sound.Output() calls and have many streams playing at the same time.
It will depend on the driver and sound card how many streams you can play.
I would check if setVolume() will work on each stream. If not, then you may need manually adjust volume directly in samples.
Back to top
View user's profile Send private message
Donny Viszneki
Newbie


Joined: 17 Sep 2007
Posts: 21
Location: Pittsburgh, PA,

PostPosted: Mon Sep 17, 2007 7:04 pm    Post subject: Reply with quote

If your sound card doesn't support hardware mixing, you'll need to use a mixer in software. A basic mixer is pretty easy to write, in fact for two sounds you can pretty much just average the samples from each audio stream. If you write your own mixer, you can also control the volume of each stream as you wish.

If at all possible, you should implement the mixer in a lower-level language than Python -- or alternatively, use the Python ctypes module (now included in the standard Python distribution as of version 2.5) and utilize the Psyco specializing Python compiler.

Apparently I can't post URLs, so type "psyco dot sf dot net."

A good reference implementation of a very basic sound mixer:

"libsdl dot org slash projects slash SDL_mixer"

Question for admin: What audio sub system does PyMedia leverage for playback?


Last edited by Donny Viszneki on Tue Sep 18, 2007 5:23 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Donny Viszneki
Newbie


Joined: 17 Sep 2007
Posts: 21
Location: Pittsburgh, PA,

PostPosted: Tue Sep 18, 2007 5:16 am    Post subject: Reply with quote

Oh, look at that, PyCar seems to use PyGame, which includes SDL_mixer.

pygame dot org slash docs slash ref slash mixer dot html

Although it seems like pygame.mixer will only play sounds loaded using pygame.mixer.Sound Sad It's been a while since I played with it though, so it's possible that Pygame exposes the raw sound data to you for Sound objects. Then it would be fairly simple to construct Sound objects which contained your own sound data decoded by Pymedia.

It does, however, seem to support OGG in addition to WAV. I'm surprised it doesn't support MP3 via SMPEG.

_________________
codebad.com gstreamer.org
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
swissdoc



Joined: 25 Nov 2008
Posts: 4

PostPosted: Tue Nov 25, 2008 12:59 am    Post subject: parallel sound playback Reply with quote

hey yall
i'm new to python, studying it actually.
i'm trying to write this little program here that uses pymedia and i have the same problem as above. namely i can't figrue out how to play several sounds at once.
jbors posted "On most systems you can run parallel sound.Output() calls and have many streams playing at the same time. "

--> can anyone explain to me how one would actually do this do this?

THANKS!!
Back to top
View user's profile Send private message
jbors
Site Admin


Joined: 12 Nov 2004
Posts: 1675

PostPosted: Tue Nov 25, 2008 9:46 am    Post subject: Reply with quote

In fact:
snd1= sound.Output(...)
snd2= sound.Output(...)
snd1.play( ... )
snd2.play( ... )
Back to top
View user's profile Send private message
swissdoc



Joined: 25 Nov 2008
Posts: 4

PostPosted: Thu Nov 27, 2008 12:48 pm    Post subject: Reply with quote

snd1= sound.Output(...)
snd2= sound.Output(...)
snd1.play( ... )
snd2.play( ... )

i tried this but i only got it to plqy the sounds one after another...?
Back to top
View user's profile Send private message
jbors
Site Admin


Joined: 12 Nov 2004
Posts: 1675

PostPosted: Thu Nov 27, 2008 5:11 pm    Post subject: Reply with quote

What OS is that ?
Back to top
View user's profile Send private message
swissdoc



Joined: 25 Nov 2008
Posts: 4

PostPosted: Fri Nov 28, 2008 9:49 am    Post subject: Reply with quote

workin on windows vista (yea yea i know, i dont like it either)... with version 2.5 of python IDLE.
Back to top
View user's profile Send private message
swissdoc



Joined: 25 Nov 2008
Posts: 4

PostPosted: Wed Dec 03, 2008 11:18 am    Post subject: Reply with quote

could you play a tuple of sond objects maybe?
Back to top
View user's profile Send private message
jbors
Site Admin


Joined: 12 Nov 2004
Posts: 1675

PostPosted: Wed Dec 03, 2008 3:47 pm    Post subject: Reply with quote

Not really. Did you try it on XP ? I never tested on Vista, so cannot speak for it
Back to top
View user's profile Send private message
onionparadise
Newbie


Joined: 14 Feb 2008
Posts: 16

PostPosted: Thu Dec 11, 2008 2:57 pm    Post subject: Reply with quote

From what I've observed of pymedia on XP, it would seem that when you execute snd.play(...), that happens in the main thread, and the actual production of sound is also an event in the main thread. For this reason, the program does not move on until the sound is finished playing. This is also why if you want any kind of interactive media player using pymedia you have to learn to use threading. If you play each sound object in its own independent thread, in theory the two should run nearly simultaneously. Of course, the emulation of threads in python is shaky as it is, and when you couple that with pymedia, which isn't that stable a package when used in the context of complex programming techniques (i.e. multi-level applications, threads, interobject communication, and heavy GUIs), you enter a realm of programming where you never know if the program will crash, and when it does crash, there's usually no visible reason why, or at least no reason that you can fix.
Back to top
View user's profile Send private message
onionparadise
Newbie


Joined: 14 Feb 2008
Posts: 16

PostPosted: Sat Jan 24, 2009 4:17 pm    Post subject: Reply with quote

Update: There's another sound module, tkSnack, which could be used to play sounds simultaneously. It uses Tcl and Tkinter, but you don't actually need a gui to run it, meaning you can run it alongside a different gui package. It appears to be rock-solid (it's developed by real scientists, so for once the people writing our modules know what they're doing Smile ), so you could probably jump to tkSnack to play your simultaneous sounds and then jump back to pymedia for your more intensive stuff. TkSnack appears to have capabilities for heavier lifting such as sound conversion, waveform analysis, spectrographs, etc, but those appear to only work through the Tcl/Tkinter ui, and I haven't figured out how to pipe the raw data out of Tcl before it gets translated into pixels.
Back to top
View user's profile Send private message
jbors
Site Admin


Joined: 12 Nov 2004
Posts: 1675

PostPosted: Sat Jan 24, 2009 7:33 pm    Post subject: Reply with quote

I'm not sure why you can't play sounds in parallel on Windows. I would suggest take a look at PyCar which use rich GUI, threads, queues and simultanous sounds. All works stable and no issues.
Even on Linux with proper sound drivers all works nice Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    InDashPC.org Forum Index -> Software All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group