~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to synti/stklib/StrmWvOut.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************/
2
 
/*
3
 
  StrmWvOut Audio Output Class,
4
 
  by Gary P. Scavone, 2000
5
 
 
6
 
  This object inherits from WvOut and is used
7
 
  to send 16-bit data (signed integer) via
8
 
  a socket connection (streamed audio).
9
 
  Streamed data must be in big-endian format,
10
 
  which conforms to network byte ordering.
11
 
 
12
 
  This class connects to a socket server, the
13
 
  port and IP address of which must be specified
14
 
  as constructor arguments.  No data buffering
15
 
  is currently implemented.  The class simply
16
 
  fires off a buffer of data over the socket
17
 
  connection as soon as it is filled.
18
 
*/
19
 
/******************************************/
20
 
 
21
 
#include "StrmWvOut.h"
22
 
 
23
 
#if defined(__STK_REALTIME_)
24
 
 
25
 
#ifdef __LITTLE_ENDIAN__
26
 
  #include "ByteSwap.h"
27
 
#endif
28
 
 
29
 
#if (defined(__OS_IRIX_) || defined(__OS_Linux_))
30
 
#include <sys/socket.h>
31
 
#include <arpa/inet.h>
32
 
#include <netdb.h>
33
 
#include <unistd.h>
34
 
 
35
 
#elif defined(__OS_Win_)
36
 
#include <winsock.h>
37
 
 
38
 
#endif
39
 
 
40
 
StrmWvOut :: StrmWvOut(int port, const char *hostname, int chans)
41
 
{
42
 
  char msg[256];
43
 
  struct sockaddr_in server_address;
44
 
 
45
 
  if (chans < 1) {
46
 
    sprintf(msg, "StrmWvOut: number of channels (%d) must be one or greater.\n", chans);
47
 
    throw StkError(msg, StkError::FUNCTION_SYNTAX);
48
 
  }
49
 
 
50
 
  channels = chans;
51
 
 
52
 
#if defined(__OS_Win_)  // Windoze-only stuff
53
 
  WSADATA wsaData;
54
 
  WORD wVersionRequested = MAKEWORD(1,1);
55
 
 
56
 
  WSAStartup(wVersionRequested, &wsaData);
57
 
  if (wsaData.wVersion != wVersionRequested) {
58
 
    sprintf(msg, "StrmWvOut: Wrong Windoze socket library version!\n");
59
 
    throw StkError(msg, StkError::PROCESS_SOCKET);
60
 
  }
61
 
#endif
62
 
 
63
 
  // Create the client-side socket
64
 
  local_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
65
 
  if (local_socket < 0) {
66
 
    sprintf(msg, "StrmWvOut: Couldn't create socket!\n");
67
 
    throw StkError(msg, StkError::PROCESS_SOCKET);
68
 
  }
69
 
 
70
 
  struct hostent *hostp;
71
 
 
72
 
  if ((hostp = gethostbyname(hostname)) == 0) {
73
 
    sprintf(msg, "StrmWvOut: unknown host (%s)!\n", hostname);
74
 
    throw StkError(msg, StkError::PROCESS_SOCKET_IPADDR);
75
 
  }
76
 
 
77
 
  // Fill in the address structure
78
 
  server_address.sin_family = AF_INET;
79
 
  memcpy((void *)&server_address.sin_addr, hostp->h_addr, hostp->h_length);
80
 
  server_address.sin_port = htons(port);
81
 
 
82
 
  // Connect to the server
83
 
  if (connect(local_socket, (struct sockaddr *)&server_address,
84
 
              sizeof(server_address) ) < 0) {
85
 
#if defined(__OS_Win_)
86
 
    closesocket(local_socket);
87
 
    WSACleanup();
88
 
#else
89
 
    close(local_socket);
90
 
#endif
91
 
    sprintf(msg, "StrmWvOut: Couldn't connect to socket server!\n");
92
 
    throw StkError(msg, StkError::PROCESS_SOCKET);
93
 
  }
94
 
 
95
 
  data_length = RT_BUFFER_SIZE*channels;  // samples
96
 
  // Add a few extra samples for good measure
97
 
  data = (INT16 *) new INT16[data_length+10];
98
 
}
99
 
 
100
 
StrmWvOut :: ~StrmWvOut()
101
 
{
102
 
  while (counter<data_length)   {
103
 
    data[counter++] = 0;
104
 
  }
105
 
  send(local_socket, (const char *)data, data_length*2, 0);
106
 
 
107
 
#if defined(__OS_Win_)
108
 
  closesocket(local_socket);
109
 
  WSACleanup();
110
 
#else
111
 
  close(local_socket);
112
 
#endif
113
 
}
114
 
 
115
 
void StrmWvOut :: tick(MY_FLOAT sample)
116
 
{
117
 
  static INT16 isample;
118
 
 
119
 
  isample = (INT16) (sample * 32000.0);
120
 
#ifdef __LITTLE_ENDIAN__
121
 
  swap16 ((unsigned char *)&isample);
122
 
#endif
123
 
  for (int i=0;i<channels;i++)
124
 
    data[counter++] = isample;
125
 
 
126
 
  if (counter >= data_length) {
127
 
    if (send(local_socket, (const char *)data, data_length*2, 0) < 0) {
128
 
      char msg[256];
129
 
#if defined(__OS_Win_)
130
 
      closesocket(local_socket);
131
 
      WSACleanup();
132
 
#else
133
 
      close(local_socket);
134
 
#endif
135
 
      sprintf(msg, "StrmWvOut: connection to socket server failed!\n");
136
 
      throw StkError(msg, StkError::PROCESS_SOCKET);
137
 
    }
138
 
    counter = 0;
139
 
  }
140
 
}
141
 
 
142
 
void StrmWvOut :: mtick(MY_MULTI samples)
143
 
{
144
 
  for (int i=0;i<channels;i++) {
145
 
    data[counter] = (INT16) (*samples++ * 32000.0);
146
 
#ifdef __LITTLE_ENDIAN__
147
 
    swap16((unsigned char *)&data[counter]);
148
 
#endif
149
 
    counter++;
150
 
  }
151
 
 
152
 
  if (counter >= data_length) {
153
 
    if (send(local_socket, (const char *)data, data_length*2, 0) < 0) {
154
 
      char msg[256];
155
 
#if defined(__OS_Win_)
156
 
      closesocket(local_socket);
157
 
      WSACleanup();
158
 
#else
159
 
      close(local_socket);
160
 
#endif
161
 
      sprintf(msg, "StrmWvOut: connection to socket server failed!\n");
162
 
      throw StkError(msg, StkError::PROCESS_SOCKET);
163
 
    }
164
 
    counter = 0;
165
 
  }
166
 
}
167
 
 
168
 
#endif