~ubuntu-branches/ubuntu/saucy/sphinxtrain/saucy

« back to all changes in this revision

Viewing changes to src/libs/libio/s3ts2cb_io.c

  • Committer: Package Import Robot
  • Author(s): Samuel Thibault
  • Date: 2013-01-02 04:10:21 UTC
  • Revision ID: package-import@ubuntu.com-20130102041021-ynsizmz33fx02hea
Tags: upstream-1.0.8
ImportĀ upstreamĀ versionĀ 1.0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ====================================================================
 
2
 * Copyright (c) 2004 Carnegie Mellon University.  All rights 
 
3
 * reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
9
 * 1. Redistributions of source code must retain the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer. 
 
11
 *
 
12
 * 2. Redistributions in binary form must reproduce the above copyright
 
13
 *    notice, this list of conditions and the following disclaimer in
 
14
 *    the documentation and/or other materials provided with the
 
15
 *    distribution.
 
16
 *
 
17
 * This work was supported in part by funding from the Defense Advanced 
 
18
 * Research Projects Agency and the National Science Foundation of the 
 
19
 * United States of America, and the CMU Sphinx Speech Consortium.
 
20
 *
 
21
 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
 
22
 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 
23
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
24
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
 
25
 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 
27
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 
28
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 
29
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 
30
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 
31
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
32
 *
 
33
 * ====================================================================
 
34
 *
 
35
 */
 
36
/*********************************************************************
 
37
 *
 
38
 * File: s3ts2cb_io.c
 
39
 * 
 
40
 * Description: 
 
41
 * 
 
42
 * Author: 
 
43
 * 
 
44
 *********************************************************************/
 
45
 
 
46
#include <sphinxbase/ckd_alloc.h>
 
47
#include <sphinxbase/err.h>
 
48
 
 
49
#include <s3/s3ts2cb_io.h>
 
50
#include <s3/s3map_io.h>
 
51
#include <s3/s3.h>
 
52
 
 
53
int
 
54
s3ts2cb_read(const char *fn,
 
55
             uint32 **out_ts2cb,
 
56
             uint32 *out_n_ts,
 
57
             uint32 *out_n_cb)
 
58
{
 
59
    int ret, i, n_d, n_r;
 
60
    int *did_map, incomplete;
 
61
    uint32 *ts2cb;
 
62
    
 
63
    ret = s3map_read(fn,
 
64
                     (void **)out_ts2cb,
 
65
                     out_n_ts,
 
66
                     out_n_cb,
 
67
                     sizeof(uint32));
 
68
 
 
69
    if (ret == S3_SUCCESS) {
 
70
        n_d = *out_n_ts;
 
71
        n_r = *out_n_cb;
 
72
        ts2cb = *out_ts2cb;
 
73
 
 
74
        did_map = ckd_calloc(n_r, sizeof(int));
 
75
 
 
76
        for (i = 0; i < n_d; i++) {
 
77
            did_map[ts2cb[i]] = TRUE;
 
78
        }
 
79
        
 
80
        for (i = 0, incomplete = FALSE; i < n_r; i++) {
 
81
            if (!did_map[i])
 
82
                incomplete = TRUE;
 
83
        }
 
84
        if (incomplete) {
 
85
            E_WARN("%s maps into [0..%u] rather than onto it\n",
 
86
                   fn, n_r-1);
 
87
        }
 
88
 
 
89
        ckd_free(did_map);
 
90
    }
 
91
 
 
92
    return ret;
 
93
}
 
94
 
 
95
int
 
96
s3ts2cb_write(const char *fn,
 
97
              uint32 *ts2cb,
 
98
              uint32 n_ts,
 
99
              uint32 n_cb)
 
100
{
 
101
    return s3map_write(fn,
 
102
                      ts2cb,
 
103
                      n_ts,
 
104
                      n_cb,
 
105
                      sizeof(uint32));
 
106
}