File: 06_wavsample-endian.patch

package info (click to toggle)
quelcom 0.4.0-15
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 1,528 kB
  • sloc: cpp: 4,148; makefile: 184; sh: 15
file content (122 lines) | stat: -rw-r--r-- 4,469 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
diff -aruN quelcom-0.4.0.orig/lib/qwavsample.cc quelcom-0.4.0/lib/qwavsample.cc
--- quelcom-0.4.0.orig/lib/qwavsample.cc	2005-10-09 03:23:24.000000000 -0700
+++ quelcom-0.4.0/lib/qwavsample.cc	2005-10-09 03:28:37.000000000 -0700
@@ -2,9 +2,10 @@
  * implementation functions for class qsample
  */
 
+# include <stdint.h>
 # include "qwavsample.hh"
 # include "qexception.hh"
-
+# include "endian.hh"
 
 #ifdef NLS
   # include <locale.h>
@@ -26,6 +27,9 @@
   sample = (union sample*) (wav->getMap()+wav->getOffset(s));
 
   if (wav->getBitsPerSample()==16) {
+	if ((uintptr_t)sample % sizeof(int16_t) != 0)
+	  throw qexception(__PRETTY_FUNCTION__, _("misaligned 16-bit sample"));
+
     if (wav->getChannels()==2) {
       type = STEREO16;
     }
@@ -60,6 +64,8 @@
   sample = (union sample*) pointer;
   
   if (bitspersample==16) {
+	if ((uintptr_t)sample % sizeof(int16_t) != 0)
+	  throw qexception(__PRETTY_FUNCTION__, _("misaligned 16-bit sample"));
     if (channels==2) {
       type = STEREO16;
       return;
@@ -99,9 +105,9 @@
   
   switch (type) {
     case MONO8: return sample->mono8;
-    case MONO16: return sample->mono16;
+    case MONO16: return letohs_s(sample->mono16);
     case STEREO8: return sample->stereo8.left;
-    case STEREO16: return sample->stereo16.left;
+    case STEREO16: return letohs_s(sample->stereo16.left);
   }
 
   throw qexception(__PRETTY_FUNCTION__,_("quelcom internal error"));
@@ -112,9 +118,9 @@
   
   switch (type) {
     case MONO8: return sample->mono8;
-    case MONO16: return sample->mono16;
+    case MONO16: return letohs_s(sample->mono16);
     case STEREO8: return sample->stereo8.right;
-    case STEREO16: return sample->stereo16.right;
+    case STEREO16: return letohs_s(sample->stereo16.right);
   }
   throw qexception(__PRETTY_FUNCTION__,_("quelcom internal error"));
 }
@@ -123,9 +129,9 @@
   
   switch (type) {
     case MONO8: sample->mono8=left; break;
-    case MONO16: sample->mono16=left; break;
+    case MONO16: sample->mono16=htoles_s(left); break;
     case STEREO8: sample->stereo8.left=left;sample->stereo8.right=right; break;
-    case STEREO16: sample->stereo16.left=left;sample->stereo16.right=right; break;
+    case STEREO16: sample->stereo16.left=htoles_s(left);sample->stereo16.right=htoles_s(right); break;
     default:
       throw qexception(__PRETTY_FUNCTION__,_("quelcom internal error"));
   }
@@ -135,13 +141,13 @@
 
   switch (type) {
     case MONO8: return (u_int32_t)abs(sample->mono8)<=threshold;
-    case MONO16: return (u_int32_t)abs(sample->mono16)<=threshold;
+    case MONO16: return (u_int32_t)abs(letohs_s(sample->mono16))<=threshold;
     case STEREO8: 
       return ((u_int32_t)abs(sample->stereo8.left)<=threshold) && 
              ((u_int32_t)abs(sample->stereo8.right)<=threshold);
     case STEREO16:
-      return ((u_int32_t)abs(sample->stereo16.left)<=threshold) && 
-             ((u_int32_t)abs(sample->stereo16.right)<=threshold);
+      return ((u_int32_t)abs(letohs_s(sample->stereo16.left))<=threshold) && 
+             ((u_int32_t)abs(letohs_s(sample->stereo16.right))<=threshold);
   }
   throw qexception(__PRETTY_FUNCTION__,_("quelcom internal error"));
 }
@@ -174,12 +180,12 @@
 
   switch (type) {
     case MONO8: os << '(' << sample->mono8 << ')'; break;
-    case MONO16: os << '(' << sample->mono16 << ')'; break;
+    case MONO16: os << '(' << letohs_s(sample->mono16) << ')'; break;
     case STEREO8:
     	os << '(' << sample->stereo8.left << ',' << sample->stereo8.right << ')';
 	break;
     case STEREO16:
-    	os << '(' << sample->stereo16.left << ',' << sample->stereo16.right << ')';
+    	os << '(' << letohs_s(sample->stereo16.left) << ',' << letohs_s(sample->stereo16.right) << ')';
 	break;
 
     default:
@@ -189,12 +195,16 @@
 
 
 void qwavsample::prod(double d) {
-
   switch (type) {
     case MONO8: sample->mono8*=d; break;
-    case MONO16: sample->mono16*=d; break;
+    case MONO16:
+	  sample->mono16 = htoles_s(short(letohs_s(sample->mono16)*d));
+	  break;
     case STEREO8: sample->stereo8.left*=d; sample->stereo8.right*=d; break;
-    case STEREO16: sample->stereo16.left*=d; sample->stereo16.right*=d; break;
+    case STEREO16:
+	  sample->stereo16.left = htoles_s(short(letohs_s(sample->stereo16.left)*d));
+	  sample->stereo16.right = htoles_s(short(letohs_s(sample->stereo16.right)*d));
+	  break;
     default:
       throw qexception(__PRETTY_FUNCTION__,_("quelcom internal error"));
   }