| 986 | | jack_port_t * output_port; |
|---|
| 987 | | RemixStream * output_stream = NULL; |
|---|
| 988 | | static jack_nframes_t last_nframes = 0; |
|---|
| 989 | | static RemixPCM * last_pcm = NULL; |
|---|
| 990 | | static RemixPCM * pcm = NULL; |
|---|
| 991 | | |
|---|
| 992 | | int |
|---|
| 993 | | beatfish_process (jack_nframes_t nframes, void * arg) |
|---|
| 994 | | { |
|---|
| 995 | | RemixCount length, offset; |
|---|
| 996 | | |
|---|
| 997 | | pcm = (RemixPCM *) jack_port_get_buffer (output_port, nframes); |
|---|
| 998 | | |
|---|
| 999 | | pthread_mutex_lock (&render_lock); |
|---|
| 1000 | | |
|---|
| 1001 | | length = remix_length (remix, mix_deck); |
|---|
| 1002 | | offset = remix_tell (remix, mix_deck); |
|---|
| 1003 | | |
|---|
| 1004 | | if (offset > length) { |
|---|
| 1005 | | remix_seek (remix, mix_deck, 0, SEEK_SET); |
|---|
| 1006 | | } |
|---|
| 1007 | | |
|---|
| 1008 | | if ((last_nframes != nframes) || (last_pcm != pcm)) { |
|---|
| 1009 | | output_stream = remix_stream_new_from_buffers (remix, nframes, &pcm); |
|---|
| 1010 | | last_nframes = nframes; |
|---|
| 1011 | | last_pcm = pcm; |
|---|
| 1012 | | } else { |
|---|
| 1013 | | remix_seek (remix, output_stream, 0, SEEK_SET); |
|---|
| 1014 | | } |
|---|
| 1015 | | |
|---|
| 1016 | | remix_process (remix, mix_deck, nframes, RemixNone, output_stream); |
|---|
| 1017 | | |
|---|
| 1018 | | pthread_mutex_unlock (&render_lock); |
|---|
| 1019 | | |
|---|
| 1020 | | return 0; |
|---|
| 1021 | | } |
|---|
| 1022 | | |
|---|
| 1023 | | void |
|---|
| 1024 | | beatfish_shutdown (void * arg) |
|---|
| 1025 | | { |
|---|
| 1026 | | printf ("Beatfish JACK client shut down!\n"); |
|---|
| 1027 | | exit (1); |
|---|
| 1028 | | } |
|---|
| 1029 | | |
|---|
| 1030 | | void |
|---|
| 1031 | | setup_jack (char * client_name) |
|---|
| 1032 | | { |
|---|
| 1033 | | jack_client_t * client; |
|---|
| 1034 | | const char ** ports; |
|---|
| 1035 | | |
|---|
| 1036 | | if ((client = jack_client_new (client_name)) == 0) { |
|---|
| 1037 | | fprintf (stderr, "%s: Could not connect to Jack server\n", |
|---|
| 1038 | | progname); |
|---|
| 1039 | | exit (1); |
|---|
| 1040 | | } |
|---|
| 1041 | | |
|---|
| 1042 | | jack_set_process_callback (client, beatfish_process, 0); |
|---|
| 1043 | | |
|---|
| 1044 | | jack_on_shutdown (client, beatfish_shutdown, 0); |
|---|
| 1045 | | |
|---|
| 1046 | | remix_set_samplerate (remix, jack_get_sample_rate(client)); |
|---|
| 1047 | | |
|---|
| 1048 | | output_port = jack_port_register (client, "output", |
|---|
| 1049 | | JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, |
|---|
| 1050 | | 0); |
|---|
| 1051 | | |
|---|
| 1052 | | jack_activate (client); |
|---|
| 1053 | | |
|---|
| 1054 | | if ((ports = jack_get_ports (client, NULL, NULL, |
|---|
| 1055 | | JackPortIsPhysical|JackPortIsInput)) == NULL) { |
|---|
| 1056 | | fprintf (stderr, "Cannot find any physical playback ports\n"); |
|---|
| 1057 | | exit (1); |
|---|
| 1058 | | } |
|---|
| 1059 | | |
|---|
| 1060 | | if (jack_connect (client, jack_port_name (output_port), ports[0])) { |
|---|
| 1061 | | fprintf (stderr, "Cannot connect output ports\n"); |
|---|
| 1062 | | } |
|---|
| 1063 | | |
|---|
| 1064 | | free (ports); |
|---|
| 1065 | | } |
|---|
| 1066 | | |
|---|