©2003 Kåre Sjölander and Jonas Beskow
Introduction Download Documentation Links Forum
WaveSurfer user forum

FAQ  FAQ
Search  Search
Memberlist  Memberlist
Register  Register
Profile  Profile
Login  Login

Chromatic tuner

 
Post new topic   Reply to topic    www.speech.kth.se/wavesurfer Forum Index -> WaveSurfer
View previous topic :: View next topic  
Author Message
Elizabeth
Guest





PostPosted: Wed Sep 03, 2003 4:05 am    Post subject: Chromatic tuner Reply with quote

Hello all,

I've been tinkering with building a chromatic tuner for myself for a while now (I'm a programmer and I play the flute) and I recently discovered this great package.

I have some background in working with C/C++ but none in tcl. Would someone be kind enough to point me in the right direction to getting realtime/microphone input F0 from Snack? At a glance it appears that I don't actually need to get into the tcl but can just compile the C code to dlls. Is that the case?

Thanks for any direction you can provide.

Elizabeth
Back to top
beskow
Site Admin


Joined: 14 Aug 2002
Posts: 39
Location: KTH, Centre for Speech Technology

PostPosted: Wed Sep 03, 2003 1:15 pm    Post subject: Reply with quote

Snack sound objects can be read and modified while they are being recorded to, so basically you just start recording and then read the samples from the sound object on the fly. You can use the cut method to keep the buffer from building up.

Below is a simple tcl-example, that prints the average of the recorded samples every 100 milliseconds:

package require snack
set snd [snack::sound -rate 8000]
$snd record

proc doStuff {snd} {
# schedule proc to be called again in 100 ms
after 100 [list doStuff $snd]

# check how many samples are in the buffer
set len [$snd length]
puts "got $len new samples"

# process samples
set sum 0
for {set i 0} {$i<$len} {incr i} {
set sum [expr {[$snd sample $i]+$sum}]
}
puts "sample average:[expr {1.0*$sum/$i}]"

# remove processed samples
$snd cut 0 [expr $len-1]
}

doStuff $snd


For any serious signal processing, you would most likely want to do that part in C, as a new method (sub-command) for snack sound objects. Check out "Writing extensions to Snack in C/C++" on the snack homepage for info on how to do this. Then just replace the sample processing loop in the above code with a call to your new method!

-Jonas
Back to top
View users profile Send private message Visit posters website
Elizabeth
Guest





PostPosted: Wed Sep 03, 2003 5:43 pm    Post subject: Tcl vs C/C++ Reply with quote

Jonas,

That's beautiful, thanks for the help.

You suggest in your reply that the heavy dsp work be done in C, which leads me back to my original point. Can I get all of the dsp functionality out of Snack from just the C libraries, or do I need to use the Tcl interface? Put another way, could your example program be written entirely in C with no dependency on Tcl?

Thanks again

E
Back to top
beskow
Site Admin


Joined: 14 Aug 2002
Posts: 39
Location: KTH, Centre for Speech Technology

PostPosted: Thu Sep 04, 2003 8:53 am    Post subject: Reply with quote

Snack is a Tcl extension, hence it requires a Tcl interpreter and it also relies on the tcl event loop so no, I don't think it is possible without Tcl, i.e. you have to link your program with Tcl libraries and at least enter the event loop (a call to Tcl_Main()) (right Kåre?). There is however no requirement that you have a tcl-script as the main entry point, although that is the most common scenario (and I strongly recommend you to try it, especially if you are going to have a GUI, you won't regret it!)

see http://tcl.tk for more info on tcl programming

good luck!
-jonas
Back to top
View users profile Send private message Visit posters website
Elizabeth
Guest





PostPosted: Thu Sep 04, 2003 6:09 pm    Post subject: Tcl vs C Reply with quote

Jonas,

Thanks for the link.

It's not that I have anything against using Tcl per se, just that I already know C and this is only a pet project for me. So, if I can get what I need without having to learn a new language that would be ideal.

But in any case, as I look at it more closely ( albeit with a limited understanding of Tcl syntax ) it appears that all of the DSP functionality is implemented in C and only the higher level "wrapper / helper" objects are implemented in Tcl. Is that right?

If that's the case, it ought to be possible to reproduce the effect of the Tcl code that you demonstrated, though obviously the "application level / helper" services that the Tcl layer is providing would need to be replaced with something else.

Am I far off the mark, or am I missing something regarding the relationship of the C code to the Tcl wrapper?

E
Back to top
kare



Joined: 16 Aug 2002
Posts: 371
Location: KTH, Centre for Speech Technology

PostPosted: Fri Sep 05, 2003 9:52 am    Post subject: Reply with quote

Snack and Tcl are strongly linked (for the moment) and should be used together. If you want a C only solution you should look at a C audio library like http://www.portaudio.com/ and start from that.
Naturally you can cut any needed signal processing stuff from the Snack sources.

Kåre
Back to top
View users profile Send private message Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    www.speech.kth.se/wavesurfer Forum Index -> WaveSurfer All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can 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


Powered by phpBB 2.0.1 © 2001, 2002 phpBB Group