Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Programmer: Shane B.
- Date: 12/12/12
- Purpose: Learn how to minipulate sound packets before looping into the headphone
- */
- /*
- === Load Libraries===
- */
- #include <stdio.h>
- //#include <errno.h>
- //#include <unistd.h>
- //#include <stdlib.h>
- //#include <string.h>
- #include <jack/jack.h>
- /*
- ===Define Globally set variables/pointers===
- */
- jack_port_t *input_port;
- jack_port_t *output_port;
- /*
- ===Begin Other Helpful Functions===
- */
- int
- process (jack_nframes_t nframes, void *arg)
- {
- jack_default_audio_sample_t *out = (jack_default_audio_sample_t *)
- jack_port_get_buffer (output_port, nframes);
- jack_default_audio_sample_t *in = (jack_default_audio_sample_t *)
- fprintf("%lu", in);
- jack_port_get_buffer (input_port, nframes);
- memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
- return 0;
- }
- int
- srate (jack_nframes_t nframes, void *arg)
- {
- printf ("the sample rate is now %lu/sec\n", nframes);
- return 0;
- }
- void
- jack_shutdown (void *arg)
- {
- exit (1);
- }
- /*
- ===Begin Logic Run-time===
- */
- int
- main (int argc, char *argv[])
- {
- /*
- ---------------------------------------------------------------------------------------------------------------
- Here we are attempting to open up a client connectiong with the JACK server
- */
- //Define pointer variable for connecting to the JACK server
- jack_client_t *client;
- //Check if the client can connect to the local jack server
- if ((client = jack_client_new("crypt")) == 0) {
- fprintf (stderr, "jack server not running?\n");
- return 1;
- }
- //Assuming we have connected to the JACK server, estiablish input/output connection ports to open up
- input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
- output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
- //Lets define some Call back functions that can be triggered during audio runtime
- //When there is work (audio) to be proccessed call the function proccess()
- jack_set_process_callback (client, process, 0);
- //When the sample rate of the audio stream changes call the function srate()
- jack_set_sample_rate_callback (client, srate, 0);
- //When the JACK server stops talking or shuts down, tell the application(local) to close
- jack_on_shutdown (client, jack_shutdown, 0);
- //If we can activate the JACK client then we have a connection, continue running...
- if (jack_activate (client)) {
- fprintf (stderr, "cannot activate client");
- return 1;
- }
- //Define port pointer variable
- const char **ports;
- //Check if physical output ports exist...
- if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsOutput)) == NULL) {
- fprintf(stderr, "Cannot find any physical capture ports\n");
- exit(1);
- }
- //Check if we can connect to physical input ports with the client....
- if (jack_connect (client, ports[0], jack_port_name (input_port))) {
- fprintf (stderr, "cannot connect input ports\n");
- }
- //Free port pointer
- free (ports);
- //
- if ((ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical|JackPortIsInput)) == NULL) {
- fprintf(stderr, "Cannot find any physical playback ports\n");
- exit(1);
- }
- //Connect all known ports....
- int i=0;
- while(ports[i]!=NULL){
- if (jack_connect (client, jack_port_name (output_port), ports[i])) {
- fprintf (stderr, "cannot connect output ports\n");
- }
- i++;
- }
- free (ports);
- for(;;)
- /*KIRBY: Close the client*/
- jack_client_close (client);
- exit (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement