File: wave_save_parts_alaw.diff

package info (click to toggle)
speech-tools 1%3A2.5.0-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,040 kB
  • sloc: cpp: 67,350; ansic: 12,174; sh: 4,055; java: 3,748; makefile: 1,106; lisp: 711; perl: 396; awk: 85; xml: 9
file content (117 lines) | stat: -rw-r--r-- 3,912 bytes parent folder | download | duplicates (3)
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
This patch complements wave_save_parts and the alaw support.
It allows one to save raw data in alaw format using the same interface
than the one provided in wave_save_parts.

This patch depends on wave_save_parts.diff and the alaw patches to 
provide asterisk support.

No copyright subsists in this patch as it is too trivial.

Author: Sergio Oller <sergioller@gmail.com>
Applied-Upstream: https://github.com/festvox/speech_tools/pull/24

--- a/speech_class/EST_WaveFile.cc
+++ b/speech_class/EST_WaveFile.cc
@@ -477,6 +477,24 @@ EST_read_status EST_WaveFile::load_alaw(
     offset, length);
 }
 
+EST_write_status EST_WaveFile::save_alaw_header(FILE *fp,
+					 const EST_Wave &wv,
+					 EST_sample_type_t stype, int bo)
+{
+    EST_Wave localwv = wv;
+    localwv.resample(8000);
+    return save_header_using(save_wave_alaw_header, fp, localwv, stype, bo);
+}
+
+EST_write_status EST_WaveFile::save_alaw_data(FILE *fp,
+					 const EST_Wave &wv,
+					 EST_sample_type_t stype, int bo)
+{
+    EST_Wave localwv = wv;
+    localwv.resample(8000);
+    return save_using(save_wave_alaw_data, fp, localwv, stype, bo);
+}
+
 EST_write_status EST_WaveFile::save_alaw(FILE *fp,
  const EST_Wave &wv,
  EST_sample_type_t stype, int bo)
--- a/speech_class/EST_WaveFile.h
+++ b/speech_class/EST_WaveFile.h
@@ -147,6 +147,8 @@ public:
   static EST_read_status load_ulaw(LoadWave_TokenStreamArgs);
 
   static EST_write_status save_alaw(SaveWave_TokenStreamArgs);
+  static EST_write_status save_alaw_header(SaveWave_TokenStreamArgs);
+  static EST_write_status save_alaw_data(SaveWave_TokenStreamArgs);
   static EST_read_status load_alaw(LoadWave_TokenStreamArgs);
 
   static EST_TNamedEnumI<EST_WaveFileType, Info> map;
--- a/speech_class/EST_wave_io.cc
+++ b/speech_class/EST_wave_io.cc
@@ -1071,17 +1071,44 @@ enum EST_read_status load_wave_alaw(EST_
     return format_ok;
 }
 
-enum EST_write_status save_wave_alaw(FILE *fp, const short *data, int offset,
+enum EST_write_status save_wave_alaw_header(FILE *fp,
+				     int num_samples, int num_channels,
+				     int sample_rate,
+				     enum EST_sample_type_t sample_type, int bo)
+{
+    (void) sample_rate;
+    (void) sample_type;
+    (void) fp;
+    (void) num_samples;
+    (void) num_channels;
+    (void) bo;
+    return write_ok;
+}
+
+enum EST_write_status save_wave_alaw_data(FILE *fp, const short *data, int offset,
 				     int num_samples, int num_channels,
 				     int sample_rate,
 				     enum EST_sample_type_t sample_type, int bo)
 {
     (void)sample_rate;
     (void)sample_type;
+    if (data == NULL)
+       return write_ok;
     return save_wave_raw(fp,data,offset,num_samples,num_channels,
 			 8000,st_alaw,bo);
+}
 
+enum EST_write_status save_wave_alaw(FILE *fp, const short *data, int offset,
+				     int num_samples, int num_channels,
+				     int sample_rate,
+				     enum EST_sample_type_t sample_type, int bo)
+{
+    save_wave_alaw_header(fp, num_samples, num_channels,
+                          sample_rate, sample_type, bo);
 
+    return save_wave_alaw_data(fp, data, offset,
+				     num_samples, num_channels,
+				     sample_rate, sample_type, bo);
 }
 
 
--- a/speech_class/waveP.h
+++ b/speech_class/waveP.h
@@ -91,6 +91,16 @@ enum EST_write_status save_wave_alaw(FIL
 				int sample_rate,
 				enum EST_sample_type_t, int bo);
 
+enum EST_write_status save_wave_alaw_header(FILE *fp,
+				int num_samples, int num_channels,
+				int sample_rate,
+				enum EST_sample_type_t sample_type, int bo);
+
+enum EST_write_status save_wave_alaw_data(FILE *fp, const short *data, int offset,
+				int num_samples, int num_channels,
+				int sample_rate,
+				enum EST_sample_type_t sample_type, int bo);
+
 enum EST_read_status load_wave_nist(EST_TokenStream &ts, short **data, int
 	 *num_samples, int *num_channels, int *word_size, int
 	 *sample_rate,  enum EST_sample_type_t *sample_type, int *bo, int