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 

the SpectrAnalizer

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



Joined: 12 Apr 2006
Posts: 4

PostPosted: Wed Apr 12, 2006 9:38 pm    Post subject: the SpectrAnalizer Reply with quote

Hi I'm making a car pc project for my car and I'm using the pymedia library i can get just fine with mp3 playing and stuff but as I'm not using a graphic screen but a text lcd I'm writing everything else from scratch and I would like to put a Spectrum Analizer into my project but the documentation is not as understandable, also the examples in cvs don't work could you please help me as I dont get the theory behind it, as soon as I finish this project i will be glad to share it with all of you.
Thanks in advance
Ricardo Manriquez
Back to top
View user's profile Send private message
CT



Joined: 22 Oct 2006
Posts: 2

PostPosted: Sun Oct 22, 2006 2:28 am    Post subject: Reply with quote

The code comments and documentation don't help me either, but the sound_viz.py example can be fixed using this line:

Code:
  dec= acodec.Decoder({'id':acodec.getCodecID(str.split(name, '.')[-1].lower())})


I also made a line.png with Paint Shop Pro. (32x64 red-green gradient)

_________________
“Simplicity, clarity, singleness: These are the attributes that give our lives power and vividness and joy as they are also the marks of great art. They seem to be the purpose of God for his whole creation.”
Richard Holloway
Back to top
View user's profile Send private message
gregglind
Newbie


Joined: 13 Dec 2006
Posts: 5

PostPosted: Wed Dec 13, 2006 10:07 am    Post subject: Further corrections Reply with quote

There are some other corrections that help the example work better.

Following CT's advice I made a 32x64 png, but this isn't large enough, so my bars weren't showing up. Either reset the window height to 64, draw a 32x200 png, or change loadBar to:

Code:
def loadBar():
  global bar
  line= pygame.image.load( 'line.png' )
  w,h= pygame.display.get_surface().get_size()
  l= w/ BANDS- FREQ_GAP
  bar= pygame.Surface( (l,h) )
  line = pygame.transform.scale(line,(l,h))  # Expand the image
  for i in xrange( l ):
    bar.blit( line, (i,0) )




Also, my amplitudes were too small, so I changed this:

Code:
sc= float(h)/ 30 # make the amplitudes more pronounced





Now, does anyone have advice for how to map the frequencies back onto the 12 musical pitches? I'm working on a Karaoke Revolution clone.


Gregg
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:33 pm    Post subject: Re: the SpectrAnalizer Reply with quote

mankeke wrote:
I'm not using a graphic screen but a text lcd


Could you be more specific about your display hardware?

If it's not "graphic" I assume you mean it's some kind of simple board with an I2C/SPI/RS232 or similar serial bus that only accepts characters of a certain limited character set.

If that's the case, how do you plan to display a spectrum analyzer? I suppose you could use digits or letters which represent each level, or maybe use an aalib / slang approach and order a list of characters from lightest to darkest.

If you do the latter, I recommend using the entire character range, and do a cheap dithering effect with a bit of randomness thrown in. (In essence, each character space on the display would represent a different slice of the spectrum, and those spaces would be flashing different characters too quickly for a viewer to easily make out which characters are being displayed, thus keeping your attention on the aggregate sum of those characters, which may be perceived as a lightness/darkness level. On the one hand, you have persistence of vision working for you, on the other hand, you probably have LCD refresh time working-- hey you know, actually, slow LCD refresh time would probably totally work in your favor! I should try this some time...)

_________________
codebad.com gstreamer.org
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 9:08 am    Post subject: Re: Further corrections Reply with quote

gregglind wrote:
Now, does anyone have advice for how to map the frequencies back onto the 12 musical pitches? I'm working on a Karaoke Revolution clone.


In terms of vibrational frequency, the period of one octave is a binary logarithm. Here's a reference implementation:

I still can't post URLs, so...

webphysics dot davidson dot edu slash faculty slash dmb slash JavaSounddemos slash scales dot htm

Remember when pitch-correcting your singer (to implement leniency, since you're never going to get an exact match) not to correct linearly, you must correct logarithmically.

You may also want to implement auto-transposition to accommodate players who simply can't sing within the expected range. The game wouldn't be any fun if you lost before you even began Sad

WARNING: Unless you are coding for a very limited music set, accurate detection of actual musical notes is not a simple task. There is much more to consider than a simple logarithmic scale. I used to know of a good reference on temperaments, but it's not in my (wow, your spam filter caught my del dot icio dot us) delicious bookmarks so I guess it's lost, sorry.

You are probably better off simply ignoring notes altogether and simply compare the logarithm of the player's frequencies with either the song being played, or better yet, an internal reference track containing only the vocals. This way your program is agnostic of many of the musical qualities of the song being sung, but can still be a good judge of how accurate the player's singing is.

It would probably also be worthwhile to spend some time thinking about how to ignore (or accurately capture, ugh) all the other sounds that are made when speaking words. If you have perfect pitch, or know someone who does, they could work with you to create a good reference track to compare the player to, by first simplifying the vocals track into discrete sinus waveforms, and then sitting down and pitch-correcting that track by hand.

Keep the forum up to date on your project, I'd like to see how it turns out!

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


Joined: 14 Feb 2008
Posts: 16

PostPosted: Sat Nov 01, 2008 2:42 pm    Post subject: Reply with quote

If you want to factor in intonation errors, I would suggest rounding. For example, the following code would take a frequency and return a number corresponding to the steps the note is from middle C, where a chromatic scale from C to C has 12 steps, regardless of intonation. Of course, if you're too far off intonation-wise, then it would register as a half-step sharp or flat.

Code:
def tone(frequency):
     """The number of musical steps frequency is from middle C, or 261.6 Hz"""
     tone=math.log(frequency/261.6,1.059463094)
     return round(tone)
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 -> PyMedia Tutorials 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