Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Playing solid sine wave
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
DtY




PostPosted: Fri Jul 24, 2009 9:37 pm   Post subject: Playing solid sine wave

Is there a standard library in python (or using pygame) a way to play a solid sine wave, needs to work on both windows and linux. (If there are ways to do it on both that only work on the one, that works too, I can write a module to wrap it)

If not, is there a library I can download to do that?

And not too necessary, but if the above exists, is there a way to make it play a few frequencies on top of each other?

Thank you Smile
Sponsor
Sponsor
Sponsor
sponsor
The_Bean




PostPosted: Sat Jul 25, 2009 9:38 am   Post subject: Re: Playing solid sine wave

If you are talking about drawing multiple sine waves that are 'rolling' with different amplitudes on top of each other, pyGame should be able to do it.
Use the built in draw methods, 0 line thickness makes it filled in.

PyGame works on both unix and windows systems, so your fine there.
DtY




PostPosted: Sat Jul 25, 2009 11:38 am   Post subject: RE:Playing solid sine wave

No, I mean playing a sine wave. "on top of each other" I mean mixed
apomb




PostPosted: Sat Jul 25, 2009 3:43 pm   Post subject: RE:Playing solid sine wave

you'd have to know the math to do that, and just draw them accordingly.
DtY




PostPosted: Sat Jul 25, 2009 4:22 pm   Post subject: Re: RE:Playing solid sine wave

apomb @ Sat Jul 25, 2009 3:43 pm wrote:
you'd have to know the math to do that, and just draw them accordingly.

I'm not trying to draw anything.

If it helps, I'm looking for a way in python to do exactly what Turing's Music.Sound() does. (Except possibly mixing multiple frequencies.
apomb




PostPosted: Sat Jul 25, 2009 5:32 pm   Post subject: RE:Playing solid sine wave

ooh actually play the sounds. sorry, i misunderstood. I'm unaware of how to do that.
Zeroth




PostPosted: Wed Jul 29, 2009 10:21 am   Post subject: Re: Playing solid sine wave

Have you looked at Pygame's mixer module? You can actually create a Sound object from a readable buffer object. So you just fill your buffer with the sine wave values, then play the sound. You can actually play different sounds on different channels even(max 2 channels). Just remember, its looking for 22k samples per second(with the default frequency for the mixer)... so it can be quite a big buffer.

http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound
DtY




PostPosted: Wed Jul 29, 2009 11:35 am   Post subject: Re: Playing solid sine wave

Zeroth @ Wed Jul 29, 2009 10:21 am wrote:
Have you looked at Pygame's mixer module? You can actually create a Sound object from a readable buffer object. So you just fill your buffer with the sine wave values, then play the sound. You can actually play different sounds on different channels even(max 2 channels). Just remember, its looking for 22k samples per second(with the default frequency for the mixer)... so it can be quite a big buffer.

http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound

That could help! Thank you.
I can't imagine it going very fast in python, but I'll see how easy the C API is to use, and see if I can use that.
I'll post the code if I do get it to work Smile

Thanks again

[edit] Is there any way to change the sampling rate? I don't need to play very high frequencies, and they don't need to sound the greatest, so a lower sampling frequency is probably best.
Sponsor
Sponsor
Sponsor
sponsor
Zeroth




PostPosted: Mon Aug 10, 2009 8:51 am   Post subject: Re: Playing solid sine wave

Sorry for the length of time, but yes there is a way to change the sampling rate, by changing the frequency: http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.init
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: