| View previous topic :: View next topic |
| Author |
Message |
krank
Joined: 04 Aug 2007 Posts: 2
|
Posted: Fri Sep 14, 2007 5:24 am Post subject: PyMedia - multiple sounds simultaneously? |
|
|
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 |
|
 |
jbors Site Admin

Joined: 12 Nov 2004 Posts: 1675
|
Posted: Fri Sep 14, 2007 1:12 pm Post subject: |
|
|
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 |
|
 |
Donny Viszneki Newbie

Joined: 17 Sep 2007 Posts: 21 Location: Pittsburgh, PA,
|
Posted: Mon Sep 17, 2007 7:04 pm Post subject: |
|
|
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 |
|
 |
Donny Viszneki Newbie

Joined: 17 Sep 2007 Posts: 21 Location: Pittsburgh, PA,
|
Posted: Tue Sep 18, 2007 5:16 am Post subject: |
|
|
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 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 |
|
 |
swissdoc
Joined: 25 Nov 2008 Posts: 4
|
Posted: Tue Nov 25, 2008 12:59 am Post subject: parallel sound playback |
|
|
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 |
|
 |
jbors Site Admin

Joined: 12 Nov 2004 Posts: 1675
|
Posted: Tue Nov 25, 2008 9:46 am Post subject: |
|
|
In fact:
snd1= sound.Output(...)
snd2= sound.Output(...)
snd1.play( ... )
snd2.play( ... ) |
|
| Back to top |
|
 |
swissdoc
Joined: 25 Nov 2008 Posts: 4
|
Posted: Thu Nov 27, 2008 12:48 pm Post subject: |
|
|
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 |
|
 |
jbors Site Admin

Joined: 12 Nov 2004 Posts: 1675
|
Posted: Thu Nov 27, 2008 5:11 pm Post subject: |
|
|
| What OS is that ? |
|
| Back to top |
|
 |
swissdoc
Joined: 25 Nov 2008 Posts: 4
|
Posted: Fri Nov 28, 2008 9:49 am Post subject: |
|
|
| workin on windows vista (yea yea i know, i dont like it either)... with version 2.5 of python IDLE. |
|
| Back to top |
|
 |
swissdoc
Joined: 25 Nov 2008 Posts: 4
|
Posted: Wed Dec 03, 2008 11:18 am Post subject: |
|
|
| could you play a tuple of sond objects maybe? |
|
| Back to top |
|
 |
jbors Site Admin

Joined: 12 Nov 2004 Posts: 1675
|
Posted: Wed Dec 03, 2008 3:47 pm Post subject: |
|
|
| Not really. Did you try it on XP ? I never tested on Vista, so cannot speak for it |
|
| Back to top |
|
 |
onionparadise Newbie

Joined: 14 Feb 2008 Posts: 16
|
Posted: Thu Dec 11, 2008 2:57 pm Post subject: |
|
|
| 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 |
|
 |
onionparadise Newbie

Joined: 14 Feb 2008 Posts: 16
|
Posted: Sat Jan 24, 2009 4:17 pm Post subject: |
|
|
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 ), 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 |
|
 |
jbors Site Admin

Joined: 12 Nov 2004 Posts: 1675
|
Posted: Sat Jan 24, 2009 7:33 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
|