51
52
static sf_count_t gsm610_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len) ;
52
53
static sf_count_t gsm610_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len) ;
54
static sf_count_t gsm610_write_s (SF_PRIVATE *psf, short *ptr, sf_count_t len) ;
55
static sf_count_t gsm610_write_i (SF_PRIVATE *psf, int *ptr, sf_count_t len) ;
56
static sf_count_t gsm610_write_f (SF_PRIVATE *psf, float *ptr, sf_count_t len) ;
57
static sf_count_t gsm610_write_d (SF_PRIVATE *psf, double *ptr, sf_count_t len) ;
55
static sf_count_t gsm610_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len) ;
56
static sf_count_t gsm610_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len) ;
57
static sf_count_t gsm610_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len) ;
58
static sf_count_t gsm610_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len) ;
59
60
static int gsm610_read_block (SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610, short *ptr, int len) ;
60
static int gsm610_write_block (SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610, short *ptr, int len) ;
61
static int gsm610_write_block (SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610, const short *ptr, int len) ;
62
63
static int gsm610_decode_block (SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610) ;
63
64
static int gsm610_encode_block (SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610) ;
78
79
{ GSM610_PRIVATE *pgsm610 ;
79
80
int true_flag = 1 ;
82
if (psf->fdata != NULL)
83
{ psf_log_printf (psf, "*** psf->fdata is not NULL.\n") ;
81
87
if (psf->mode == SFM_RDWR)
82
88
return SFE_BAD_MODE_RW ;
84
90
psf->sf.seekable = SF_FALSE ;
86
if (! (pgsm610 = malloc (sizeof (GSM610_PRIVATE))))
92
if ((pgsm610 = calloc (1, sizeof (GSM610_PRIVATE))) == NULL)
87
93
return SFE_MALLOC_FAILED ;
89
95
psf->fdata = (void*) pgsm610 ;
97
103
============================================================*/
99
if (! (pgsm610->gsm_data = gsm_create ()))
105
if ((pgsm610->gsm_data = gsm_create ()) == NULL)
100
106
return SFE_MALLOC_FAILED ;
102
if ((psf->sf.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV ||
103
(psf->sf.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_W64)
104
{ gsm_option (pgsm610->gsm_data, GSM_OPT_WAV49, &true_flag) ;
106
pgsm610->encode_block = gsm610_wav_encode_block ;
107
pgsm610->decode_block = gsm610_wav_decode_block ;
109
pgsm610->samplesperblock = WAV_W64_GSM610_SAMPLES ;
110
pgsm610->blocksize = WAV_W64_GSM610_BLOCKSIZE ;
113
{ pgsm610->encode_block = gsm610_encode_block ;
114
pgsm610->decode_block = gsm610_decode_block ;
116
pgsm610->samplesperblock = GSM610_SAMPLES ;
117
pgsm610->blocksize = GSM610_BLOCKSIZE ;
108
switch (psf->sf.format & SF_FORMAT_TYPEMASK)
109
{ case SF_FORMAT_WAV :
110
case SF_FORMAT_WAVEX :
112
gsm_option (pgsm610->gsm_data, GSM_OPT_WAV49, &true_flag) ;
114
pgsm610->encode_block = gsm610_wav_encode_block ;
115
pgsm610->decode_block = gsm610_wav_decode_block ;
117
pgsm610->samplesperblock = WAV_W64_GSM610_SAMPLES ;
118
pgsm610->blocksize = WAV_W64_GSM610_BLOCKSIZE ;
121
case SF_FORMAT_AIFF :
123
pgsm610->encode_block = gsm610_encode_block ;
124
pgsm610->decode_block = gsm610_decode_block ;
126
pgsm610->samplesperblock = GSM610_SAMPLES ;
127
pgsm610->blocksize = GSM610_BLOCKSIZE ;
131
return SFE_INTERNAL ;
120
135
if (psf->mode == SFM_READ)
121
{ if (psf->datalength % pgsm610->blocksize)
136
{ if (psf->datalength % pgsm610->blocksize == 0)
137
pgsm610->blocks = psf->datalength / pgsm610->blocksize ;
138
else if (psf->datalength % pgsm610->blocksize == 1 && pgsm610->blocksize == GSM610_BLOCKSIZE)
140
** Weird AIFF specific case.
141
** AIFF chunks must be at an odd offset from the start of file and
142
** GSM610_BLOCKSIZE is odd which can result in an odd length SSND
143
** chunk. The SSND chunk then gets padded on write which means that
144
** when it is read the datalength is too big by 1.
146
pgsm610->blocks = psf->datalength / pgsm610->blocksize ;
122
149
{ psf_log_printf (psf, "*** Warning : data chunk seems to be truncated.\n") ;
123
150
pgsm610->blocks = psf->datalength / pgsm610->blocksize + 1 ;
126
pgsm610->blocks = psf->datalength / pgsm610->blocksize ;
128
153
psf->sf.frames = pgsm610->samplesperblock * pgsm610->blocks ;
442
468
} /* gsm610_wav_encode_block */
445
gsm610_write_block (SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610, short *ptr, int len)
471
gsm610_write_block (SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610, const short *ptr, int len)
446
472
{ int count, total = 0, indx = 0 ;
448
474
while (indx < len)
464
490
} /* gsm610_write_block */
466
492
static sf_count_t
467
gsm610_write_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
493
gsm610_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
468
494
{ GSM610_PRIVATE *pgsm610 ;
469
495
int writecount, count ;
470
496
sf_count_t total = 0 ;
498
if (psf->fdata == NULL)
474
500
pgsm610 = (GSM610_PRIVATE*) psf->fdata ;
489
515
} /* gsm610_write_s */
491
517
static sf_count_t
492
gsm610_write_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
518
gsm610_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
493
519
{ GSM610_PRIVATE *pgsm610 ;
495
521
int k, bufferlen, writecount = 0, count ;
496
522
sf_count_t total = 0 ;
524
if (psf->fdata == NULL)
500
526
pgsm610 = (GSM610_PRIVATE*) psf->fdata ;
514
540
} /* gsm610_write_i */
516
542
static sf_count_t
517
gsm610_write_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
543
gsm610_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
518
544
{ GSM610_PRIVATE *pgsm610 ;
520
546
int k, bufferlen, writecount = 0, count ;
521
547
sf_count_t total = 0 ;
550
if (psf->fdata == NULL)
526
552
pgsm610 = (GSM610_PRIVATE*) psf->fdata ;
542
568
} /* gsm610_write_f */
544
570
static sf_count_t
545
gsm610_write_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
571
gsm610_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
546
572
{ GSM610_PRIVATE *pgsm610 ;
548
574
int k, bufferlen, writecount = 0, count ;
549
575
sf_count_t total = 0 ;
550
576
double normfact ;
578
if (psf->fdata == NULL)
554
580
pgsm610 = (GSM610_PRIVATE*) psf->fdata ;