5 // Created by Stéphane LETZ on 16/02/09.
6 // Copyright Grame 2009. All rights reserved.
9 #import <UIKit/UIKit.h>
12 #include "TiPhoneCoreAudioRenderer.h"
17 jack_net_slave_t* net = NULL;
18 jack_adapter_t* adapter = NULL;
23 static int net_process(jack_nframes_t buffer_size,
25 float** audio_input_buffer,
27 void** midi_input_buffer,
29 float** audio_output_buffer,
31 void** midi_output_buffer,
34 jack_adapter_pull_and_push(adapter, audio_output_buffer, audio_input_buffer, buffer_size);
36 // Process input, produce output
37 if (audio_input == audio_output) {
38 // Copy net input to net output
39 for (int i = 0; i < audio_input; i++) {
40 memcpy(audio_output_buffer[i], audio_input_buffer[i], buffer_size * sizeof(float));
46 static void net_shutdown(void *arg)
49 jack_flush_adapter(adapter);
52 static void SlaveAudioCallback(int frames, float** inputs, float** outputs, void* arg)
54 jack_adapter_push_and_pull(adapter, inputs, outputs, frames);
57 //http://www.securityfocus.com/infocus/1884
61 int main(int argc, char *argv[]) {
63 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
65 jack_slave_t request = { NUM_OUTPUT, NUM_INPUT, 0, 0, WIFI_MTU, -1, JackCeltEncoder, 128, 2 };
68 //if ((net = jack_net_slave_open("169.254.112.119", DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
69 if ((net = jack_net_slave_open(DEFAULT_MULTICAST_IP, DEFAULT_PORT, "iPod", &request, &result)) == 0) {
70 printf("jack_net_slave_open error...\n");
74 if ((adapter = jack_create_adapter(NUM_INPUT,
79 result.sample_rate)) == 0) {
83 TiPhoneCoreAudioRenderer audio_device(NUM_INPUT, NUM_OUTPUT);
85 jack_set_net_slave_process_callback(net, net_process, NULL);
86 jack_set_net_slave_shutdown_callback(net, net_shutdown, NULL);
88 if (jack_net_slave_activate(net) != 0) {
89 printf("Cannot activate slave client\n");
93 if (audio_device.Open(result.buffer_size, result.sample_rate) < 0) {
97 audio_device.SetAudioCallback(SlaveAudioCallback, NULL);
99 if (audio_device.Start() < 0) {
103 int retVal = UIApplicationMain(argc, argv, nil, nil);
107 audio_device.Close();
109 // Wait for application end
110 jack_net_slave_deactivate(net);
111 jack_net_slave_close(net);
112 jack_destroy_adapter(adapter);