Help Basic Jack

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Help Basic Jack

Wesly Van Eycken
Hey,
 
I'm a student in my last year and making a Master Paper, for this I have to make a program for testing Hearing Aids.  In this program I want to use JACK to send and recieve audio.  I'm not an expert at this subject and have several problems.
I started programming using the example file simple_client.c I kept the main and adjusted the process method. What I do is first read in a wav file using the sndfile library, then I write the file to a float array. Then in the process method I memcpy it to the output port. Is this a logical approach? Can I copy a float array to the output? I do take in account the frame size and samplerate of the file and my sound card. I've made a sinus wav-file with samplerate 48000 Hz, and my soundcard  uses also 48000 Hz, the frame size is 16 bit (2 byte) and I know a float is 4 byte big.
Another question I have is, what do I do with the buffer?  In the main I added jack_set_buffer_size(client, nframes) but I don't know how much I should give for the  nframes, is this how many frames the program processes during the process method or something else?
When I run my program I think I hear the sinus coming out of my speaker, but in stead of one, there are several, and I made a if statement so that only one would make the memcpy.
 
If someone sees some dumb mistakes, please let me know.
 
Greetz Wes.
 


Express yourself instantly with MSN Messenger! MSN Messenger
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Help Basic Jack

Nicolau Werneck
Hi there. I'm attaching a simple client I made once for mixing
together two input tracks (in stereo).   It might help you... But
actually it's not very different from any other simple clients around
there, so it may not be helpful in the end :)

The reason I'm writing is to ask you: Why don't you make program that
actually synthesizes the sinusoid in real-time? It's much better then
reading them from files!... There are a couple of algorithms to do the
synthesis that are quite fast and reliable... I don't even believe the
standard sin() is bad!...

I am also attaching a nice program I made once (during my masters!)
to generate sinusoids in real-time. It was based on Jack, and GTKmm.
The graphical interface has a slide control for frequency, and another
for amplitude.  You can also change the values and the limits of the
slides by some spinbuttons... It is still in a little rudimentary
state, but it worked fine for the experiments I had to make, forcing a
sinusoidal current in an electric guitar, and some circuits. I always
thought it might be also helpful for acoustic tests, with humans!...
It makes smooth transitions in the sinusoid values.

May I ask you, what exactly is the test you are going to make?...
Because I doubt you are going to play continuous sinusoidal tones, so
my program would have to be extended... :)

see you,
    ++nicolau


(notice that I always call the jack functions file with the same name,
but they have different functions...)

On Feb 19, 2008 12:34 PM, Wesly Van Eycken <[hidden email]> wrote:

>
> Hey,
>
>  I'm a student in my last year and making a Master Paper, for this I have to
> make a program for testing Hearing Aids.  In this program I want to use JACK
> to send and recieve audio.  I'm not an expert at this subject and have
> several problems.
>  I started programming using the example file simple_client.c I kept the
> main and adjusted the process method. What I do is first read in a wav file
> using the sndfile library, then I write the file to a float array. Then in
> the process method I memcpy it to the output port. Is this a logical
> approach? Can I copy a float array to the output? I do take in account the
> frame size and samplerate of the file and my sound card. I've made a sinus
> wav-file with samplerate 48000 Hz, and my soundcard  uses also 48000 Hz, the
> frame size is 16 bit (2 byte) and I know a float is 4 byte big.
>  Another question I have is, what do I do with the buffer?  In the main I
> added jack_set_buffer_size(client, nframes) but I don't know how much I
> should give for the  nframes, is this how many frames the program processes
> during the process method or something else?
>  When I run my program I think I hear the sinus coming out of my speaker,
> but in stead of one, there are several, and I made a if statement so that
> only one would make the memcpy.
>
>  If someone sees some dumb mistakes, please let me know.
>
>  Greetz Wes.
>
>
> ________________________________
> Express yourself instantly with MSN Messenger! MSN Messenger
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Jackit-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jackit-devel
>
>


--
Nicolau Werneck <[hidden email]>         9F99 25AB E47E 8724 2F71
http://www.lti.pcs.usp.br/~nwerneck                   EA40 DC23 42CE 6B76 B07F

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel

theremosc.tar.bz2 (12K) Download Attachment
jack_funcs.c (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Help Basic Jack

Wesly Van Eycken
Thanks very much, the code you attached to the mail helped me to understand it a little more.  I still have a few questions, in the process method I send my sinusoid through the output and I capture it immediately at the input(i have connected my output with my input through a jack cable / I do this just for testing):

for(...){
out[i]=sinus[i]; // sinus is a float array
capture[i]=in[i] // capture is a float array
}
// this is simplified

when I print out all the frame values I notice 2 things:
1. The first 2000 frames have the wrong/very low values

I think this may be has to do with latency: when I use the jack_port_get_latency i have 0 latency, but when i use the jack_port_get_total_latency i get 1024(=buffer size)  for my input and output port.  Do I have to add those 2 latency together and start to read the input when 2048 frames are passed?

2. The values of the sinusoid are much diminished, the original sinus goes between 0.9 and -0.9, and the values I get at the input are between  -0.041 and 0.046, but the values  do represent a sinusoid.

Is this because I save the values  under a wrong type?  But  when I print out[i]  as a float, i see the correct values and when  I print in[i], I see the diminished values.

I want to thank nicolau again for your help, when my program is finished I will let you know, and hopefully I have a working jack component:).

Greetz Wes.



 



> Date: Tue, 19 Feb 2008 13:56:21 -0300

> From: [hidden email]
> To: [hidden email]
> Subject: Re: [Jackit-devel] Help Basic Jack
> CC: [hidden email]
>
> Hi there. I'm attaching a simple client I made once for mixing
> together two input tracks (in stereo). It might help you... But
> actually it's not very different from any other simple clients around
> there, so it may not be helpful in the end :)
>
> The reason I'm writing is to ask you: Why don't you make program that
> actually synthesizes the sinusoid in real-time? It's much better then
> reading them from files!... There are a couple of algorithms to do the
> synthesis that are quite fast and reliable... I don't even believe the
> standard sin() is bad!...
>
> I am also attaching a nice program I made once (during my masters!)
> to generate sinusoids in real-time. It was based on Jack, and GTKmm.
> The graphical interface has a slide control for frequency, and another
> for amplitude. You can also change the values and the limits of the
> slides by some spinbuttons... It is still in a little rudimentary
> state, but it worked fine for the experiments I had to make, forcing a
> sinusoidal current in an electric guitar, and some circuits. I always
> thought it might be also helpful for acoustic tests, with humans!...
> It makes smooth transitions in the sinusoid values.
>
> May I ask you, what exactly is the test you are going to make?...
> Because I doubt you are going to play continuous sinusoidal tones, so
> my program would have to be extended... :)
>
> see you,
> ++nicolau
>
>
> (notice that I always call the jack functions file with the same name,
> but they have different functions...)
>
> On Feb 19, 2008 12:34 PM, Wesly Van Eycken <[hidden email]> wrote:
> >
> > Hey,
> >
> > I'm a student in my last year and making a Master Paper, for this I have to
> > make a program for testing Hearing Aids. In this program I want to use JACK
> > to send and recieve audio. I'm not an expert at this subject and have
> > several problems.
> > I started programming using the example file simple_client.c I kept the
> > main and adjusted the process method. What I do is first read in a wav file
> > using the sndfile library, then I write the file to a float array. Then in
> > the process method I memcpy it to the output port. Is this a logical
> > approach? Can I copy a float array to the output? I do take in account the
> > frame size and samplerate of the file and my sound card. I've made a sinus
> > wav-file with samplerate 48000 Hz, and my soundcard uses also 48000 Hz, the
> > frame size is 16 bit (2 byte) and I know a float is 4 byte big.
> > Another question I have is, what do I do with the buffer? In the main I
> > added jack_set_buffer_size(client, nframes) but I don't know how much I
> > should give for the nframes, is this how many frames the program processes
> > during the process method or something else?
> > When I run my program I think I hear the sinus coming out of my speaker,
> > but in stead of one, there are several, and I made a if statement so that
> > only one would make the memcpy.
> >
> > If someone sees some dumb mistakes, please let me know.
> >
> > Greetz Wes.
> >
> >
> > ________________________________
> > Express yourself instantly with MSN Messenger! MSN Messenger
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Jackit-devel mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/jackit-devel
> >
> >
>
>
>
> --
> Nicolau Werneck <[hidden email]> 9F99 25AB E47E 8724 2F71
> http://www.lti.pcs.usp.br/~nwerneck EA40 DC23 42CE 6B76 B07F


Express yourself instantly with MSN Messenger! MSN Messenger
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel
Reply | Threaded
Open this post in threaded view
|

Re: Help Basic Jack

Nicolau Werneck
Well, you _always_ have a delay, at least that of the buffers... There
is a nice sub-sample delay measurement jack program someone sent here
the other day, you should run it to know yours.

Have you checked your mixer, to see if the volumes are at the
maximum?... And are you sure there is no kind of mixing of sources
going on? (the sum of two sinusoids might create a second with a lower
value.... just an idea of something remotely likely to be happening!
:)   )    I believe this program that measures the delay also measures
the gain, you must check if it is OK.

In fact, you might just play a recorded file with a normal program,
and record it back again using another normal program, and see if the
gain is near 1.0...

Because of the delay (and the buffers), you cannot capture the output
"immediately" after. You could do the two vector assignments in two
separate fors, in any order, it would make no difference...

I believe it's something related to the mixer settings, because you
are having a 20x attenuation... I can't imagine any kind of software
bug causing this... It's not a familiar number!...






On Feb 20, 2008 10:18 AM, Wesly Van Eycken <[hidden email]> wrote:

>
> Thanks very much, the code you attached to the mail helped me to understand
> it a little more.  I still have a few questions, in the process method I
> send my sinusoid through the output and I capture it immediately at the
> input(i have connected my output with my input through a jack cable / I do
> this just for testing):
>
> for(...){
> out[i]=sinus[i]; // sinus is a float array
> capture[i]=in[i] // capture is a float array
> }
> // this is simplified
>
> when I print out all the frame values I notice 2 things:
> 1. The first 2000 frames have the wrong/very low values
>
> I think this may be has to do with latency: when I use the
> jack_port_get_latency i have 0 latency, but when i use the
> jack_port_get_total_latency i get 1024(=buffer size)  for my input and
> output port.  Do I have to add those 2 latency together and start to read
> the input when 2048 frames are passed?
>
> 2. The values of the sinusoid are much diminished, the original sinus goes
> between 0.9 and -0.9, and the values I get at the input are between  -0.041
> and 0.046, but the values  do represent a sinusoid.
>
> Is this because I save the values  under a wrong type?  But  when I print
> out[i]  as a float, i see the correct values and when  I print in[i], I see
> the diminished values.
>
> I want to thank nicolau again for your help, when my program is finished I
> will let you know, and hopefully I have a working jack component:).
>
> Greetz Wes.
>
>
>
>
>
>
> ________________________________
> > Date: Tue, 19 Feb 2008 13:56:21 -0300
> > From: [hidden email]
> > To: [hidden email]
> > Subject: Re: [Jackit-devel] Help Basic Jack
> > CC: [hidden email]
>
>
> >
> > Hi there. I'm attaching a simple client I made once for mixing
> > together two input tracks (in stereo). It might help you... But
> > actually it's not very different from any other simple clients around
> > there, so it may not be helpful in the end :)
> >
> > The reason I'm writing is to ask you: Why don't you make program that
> > actually synthesizes the sinusoid in real-time? It's much better then
> > reading them from files!... There are a couple of algorithms to do the
> > synthesis that are quite fast and reliable... I don't even believe the
> > standard sin() is bad!...
> >
> > I am also attaching a nice program I made once (during my masters!)
> > to generate sinusoids in real-time. It was based on Jack, and GTKmm.
> > The graphical interface has a slide control for frequency, and another
> > for amplitude. You can also change the values and the limits of the
> > slides by some spinbuttons... It is still in a little rudimentary
> > state, but it worked fine for the experiments I had to make, forcing a
> > sinusoidal current in an electric guitar, and some circuits. I always
> > thought it might be also helpful for acoustic tests, with humans!...
> > It makes smooth transitions in the sinusoid values.
> >
> > May I ask you, what exactly is the test you are going to make?...
> > Because I doubt you are going to play continuous sinusoidal tones, so
> > my program would have to be extended... :)
> >
> > see you,
> > ++nicolau
> >
> >
> > (notice that I always call the jack functions file with the same name,
> > but they have different functions...)
> >
> > On Feb 19, 2008 12:34 PM, Wesly Van Eycken <[hidden email]>
> wrote:
> > >
> > > Hey,
> > >
> > > I'm a student in my last year and making a Master Paper, for this I have
> to
> > > make a program for testing Hearing Aids. In this program I want to use
> JACK
> > > to send and recieve audio. I'm not an expert at this subject and have
> > > several problems.
> > > I started programming using the example file simple_client.c I kept the
> > > main and adjusted the process method. What I do is first read in a wav
> file
> > > using the sndfile library, then I write the file to a float array. Then
> in
> > > the process method I memcpy it to the output port. Is this a logical
> > > approach? Can I copy a float array to the output? I do take in account
> the
> > > frame size and samplerate of the file and my sound card. I've made a
> sinus
> > > wav-file with samplerate 48000 Hz, and my soundcard uses also 48000 Hz,
> the
> > > frame size is 16 bit (2 byte) and I know a float is 4 byte big.
> > > Another question I have is, what do I do with the buffer? In the main I
> > > added jack_set_buffer_size(client, nframes) but I don't know how much I
> > > should give for the nframes, is this how many frames the program
> processes
> > > during the process method or something else?
> > > When I run my program I think I hear the sinus coming out of my speaker,
> > > but in stead of one, there are several, and I made a if statement so
> that
> > > only one would make the memcpy.
> > >
> > > If someone sees some dumb mistakes, please let me know.
> > >
> > > Greetz Wes.
> > >
> > >
> > > ________________________________
> > > Express yourself instantly with MSN Messenger! MSN Messenger
> > >
> > >
> -------------------------------------------------------------------------
> > > This SF.net email is sponsored by: Microsoft
> > > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > > _______________________________________________
> > > Jackit-devel mailing list
> > > [hidden email]
> > > https://lists.sourceforge.net/lists/listinfo/jackit-devel
> > >
> > >
> >
> >
> >
> > --
> > Nicolau Werneck <[hidden email]> 9F99 25AB E47E 8724 2F71
> > http://www.lti.pcs.usp.br/~nwerneck EA40 DC23 42CE 6B76 B07F
>
> ________________________________
> Express yourself instantly with MSN Messenger! MSN Messenger



--
Nicolau Werneck <[hidden email]>         9F99 25AB E47E 8724 2F71
http://www.lti.pcs.usp.br/~nwerneck                   EA40 DC23 42CE 6B76 B07F

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Jackit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jackit-devel