jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
3.2KB

  1. //
  2. // main.m
  3. // iPhoneNet
  4. //
  5. // Created by Stéphane LETZ on 16/02/09.
  6. // Copyright Grame 2009. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #include <jack/net.h>
  10. #include "TiPhoneCoreAudioRenderer.h"
  11. #define NUM_INPUT 0
  12. #define NUM_OUTPUT 2
  13. jack_net_slave_t* net = NULL;
  14. jack_adapter_t* adapter = NULL;
  15. int buffer_size;
  16. int sample_rate;
  17. static int net_process(jack_nframes_t buffer_size,
  18. int audio_input,
  19. float** audio_input_buffer,
  20. int midi_input,
  21. void** midi_input_buffer,
  22. int audio_output,
  23. float** audio_output_buffer,
  24. int midi_output,
  25. void** midi_output_buffer,
  26. void* data)
  27. {
  28. jack_adapter_pull_and_push(adapter, audio_output_buffer, audio_input_buffer, buffer_size);
  29. // Process input, produce output
  30. if (audio_input == audio_output) {
  31. // Copy net input to net output
  32. for (int i = 0; i < audio_input; i++) {
  33. memcpy(audio_output_buffer[i], audio_input_buffer[i], buffer_size * sizeof(float));
  34. }
  35. }
  36. return 0;
  37. }
  38. static void net_shutdown(void *arg)
  39. {
  40. if (adapter)
  41. jack_flush_adapter(adapter);
  42. }
  43. static void SlaveAudioCallback(int frames, float** inputs, float** outputs, void* arg)
  44. {
  45. jack_adapter_push_and_pull(adapter, inputs, outputs, frames);
  46. }
  47. //http://www.securityfocus.com/infocus/1884
  48. #define WIFI_MTU 1500
  49. int main(int argc, char *argv[]) {
  50. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  51. jack_slave_t request = { NUM_OUTPUT, NUM_INPUT, 0, 0, WIFI_MTU, -1, JackCeltEncoder, 128, 2 };
  52. jack_master_t result;
  53. //if ((net = jack_net_slave_open("169.254.112.119", DEFAULT_PORT, "iPhone", &request, &result)) == 0) {
  54. if ((net = jack_net_slave_open(DEFAULT_MULTICAST_IP, DEFAULT_PORT, "iPod", &request, &result)) == 0) {
  55. printf("jack_net_slave_open error...\n");
  56. return -1;
  57. }
  58. if ((adapter = jack_create_adapter(NUM_INPUT,
  59. NUM_OUTPUT,
  60. result.buffer_size,
  61. result.sample_rate,
  62. result.buffer_size,
  63. result.sample_rate)) == 0) {
  64. return -1;
  65. }
  66. TiPhoneCoreAudioRenderer audio_device(NUM_INPUT, NUM_OUTPUT);
  67. jack_set_net_slave_process_callback(net, net_process, NULL);
  68. jack_set_net_slave_shutdown_callback(net, net_shutdown, NULL);
  69. if (jack_net_slave_activate(net) != 0) {
  70. printf("Cannot activate slave client\n");
  71. return -1;
  72. }
  73. if (audio_device.Open(result.buffer_size, result.sample_rate) < 0) {
  74. return -1;
  75. }
  76. audio_device.SetAudioCallback(SlaveAudioCallback, NULL);
  77. if (audio_device.Start() < 0) {
  78. return -1;
  79. }
  80. int retVal = UIApplicationMain(argc, argv, nil, nil);
  81. [pool release];
  82. audio_device.Stop();
  83. audio_device.Close();
  84. // Wait for application end
  85. jack_net_slave_deactivate(net);
  86. jack_net_slave_close(net);
  87. jack_destroy_adapter(adapter);
  88. return retVal;
  89. }