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

« back to all changes in this revision

Viewing changes to synti/stklib/SndWvOut.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
 
  NeXT (.snd) and Sun (.au) Soundfile Output Class
4
 
  by Perry R. Cook, 1996
5
 
  Revised by Gary P. Scavone, 1999-2000
6
 
 
7
 
  This one opens a NeXT .snd file, and
8
 
  even knows how to byte-swap!
9
 
*/
10
 
/***********************************************/
11
 
 
12
 
#include "SndWvOut.h"
13
 
#ifdef __LITTLE_ENDIAN__
14
 
  #include "ByteSwap.h"
15
 
#endif
16
 
 
17
 
/********  NeXT Soundfile Header Struct   *******/
18
 
struct headerform {
19
 
  char pref[4];
20
 
  INT32 hdr_length;
21
 
  INT32 file_length;
22
 
  INT32 mode;
23
 
  INT32 samp_rate;
24
 
  INT32 num_channels;
25
 
  char comment[16];
26
 
};
27
 
 
28
 
FILE *openNeXTFile(int chans, char *fileName)   {
29
 
  struct headerform hdr = {".sn",40,0,3,(INT32) SRATE,1,"Created by STK"};
30
 
  char tempName[128];
31
 
  FILE *fd;
32
 
  char msg[256];
33
 
    
34
 
  hdr.pref[3] = 'd';
35
 
 
36
 
  strcpy(tempName,fileName);
37
 
  if (strstr(tempName,".snd") == NULL) strcat(tempName,".snd");
38
 
  hdr.num_channels = chans;
39
 
  fd = fopen(tempName,"wb");
40
 
  if (!fd) {
41
 
    sprintf(msg, "SndWvOut: Could not create soundfile: %s\n", tempName);
42
 
    throw StkError(msg, StkError::FILE_ERROR);
43
 
  }
44
 
 
45
 
#ifdef __LITTLE_ENDIAN__
46
 
  swap32 ((unsigned char *)&hdr.hdr_length);
47
 
  swap32 ((unsigned char *)&hdr.file_length);
48
 
  swap32 ((unsigned char *)&hdr.mode);
49
 
  swap32 ((unsigned char *)&hdr.samp_rate);
50
 
  swap32 ((unsigned char *)&hdr.num_channels);
51
 
#endif
52
 
 
53
 
  printf("\nCreating soundfile: %s\n", tempName);
54
 
  fwrite(&hdr,4,10,fd);
55
 
  return fd;
56
 
}
57
 
 
58
 
SndWvOut :: SndWvOut(char *fileName, int chans)
59
 
{
60
 
  char msg[256];
61
 
  if (chans < 1) {
62
 
    sprintf(msg, "SndWvOut: number of channels = %d not supported!\n", chans);
63
 
    throw StkError(msg, StkError::FUNCTION_SYNTAX);
64
 
  }
65
 
  channels = chans;
66
 
  fd = openNeXTFile(channels,fileName);
67
 
  data_length = FILE_BUFFER_SIZE*channels;
68
 
  data = (INT16 *) new INT16[data_length];
69
 
}
70
 
 
71
 
SndWvOut :: ~SndWvOut()
72
 
{
73
 
  double temp;
74
 
 
75
 
  fwrite(data,2,counter,fd);
76
 
  temp = (double) totalCount * ONE_OVER_SRATE;
77
 
  printf("%f Seconds Computed\n\n", temp);
78
 
 
79
 
  totalCount *= 2*channels;
80
 
#ifdef __LITTLE_ENDIAN__
81
 
  swap32 ((unsigned char *)&totalCount);
82
 
#endif
83
 
  fseek(fd,8,SEEK_SET); // jump to data size
84
 
  fwrite(&totalCount,4,1,fd);
85
 
  fclose(fd);
86
 
}
87
 
 
88
 
void SndWvOut :: tick(MY_FLOAT sample)
89
 
{
90
 
  INT16 isample;
91
 
    
92
 
  isample = (INT16) (sample * 32000.0);
93
 
#ifdef __LITTLE_ENDIAN__
94
 
  swap16 ((unsigned char *)&isample);
95
 
#endif
96
 
  for (int i=0;i<channels;i++)
97
 
    data[counter++] = isample;
98
 
 
99
 
  totalCount++;
100
 
  if (counter == data_length) {
101
 
    fwrite(data,2,data_length,fd);
102
 
    counter = 0;
103
 
  }
104
 
}
105
 
 
106
 
void SndWvOut :: mtick(MY_MULTI samples)
107
 
{
108
 
  for (int i=0;i<channels;i++) {
109
 
    data[counter] = (INT16) (*samples++ * 32000.0);
110
 
#ifdef __LITTLE_ENDIAN__
111
 
    swap16 ((unsigned char *)&data[counter]);
112
 
#endif
113
 
    counter++;
114
 
  }
115
 
  
116
 
  totalCount++;
117
 
  if (counter == data_length) {
118
 
    fwrite(data,2,data_length,fd);
119
 
    counter = 0;
120
 
  }
121
 
}